latex中插入latex代码

导言区插入:
\usepackage{listings}
%插入代码要引入的宏包
\lstset{
    columns = fixed,       
    basicstyle = \linespread{1.2} \ttfamily,             % 设置行距,字体
    numbers = left,                                      % 在左侧显示行号
    numberstyle = \tiny \color{gray},                    % 设定行号格式
    keywordstyle = \bfseries \color[RGB]{240,40,255},     % 设定关键字颜色
    numberstyle = \footnotesize \color{darkgray},           
    commentstyle = \color[RGB]{0,96,96},                 % 设置代码注释的格式
    stringstyle = \color[RGB]{128,128,0},                  % 设置字符串格式
    frame = single,                                      % 不显示背景边框
    backgroundcolor = \color[RGB]{205,245,244},          % 设定背景颜色
    showstringspaces = false,                            % 不显示字符串中的空格
    language=Tex                                           % 设置语言
}

latex中代码:

\begin{lstlisting}[language=tex]    
    \documentclass{article}
    \usepackage{ctex} 
    \begin{document}
         坚持使用\\LaTeX  ,你会爱不释手!                                
    \end{document}
\end{lstlisting}

效果:

这样就可以在latex插入latex代码就不在解释了,省却了不少麻烦。也可以支持c,python和java的。

posted @ 2024-01-18 17:53  叕叒双又  阅读(305)  评论(0编辑  收藏  举报