首页 > 其他分享 >解决latex在使用lstlisting环境时的Undefined control sequence.错误

解决latex在使用lstlisting环境时的Undefined control sequence.错误

时间:2024-01-20 21:55:12浏览次数:24  
标签:control latex begin end Undefined color RGB lstlisting document

  错误描述,如题,Undefined control sequence. \begin{lstlisting},查了不少的资料,起始就是一句话,缺了宏包的导入。先看代码:

\documentclass[11pt,a4paper]{ctexart}
\usepackage{listings}
%插入代码要引入的宏包
\author{gsc}
\title{sample}
\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                                         % 设置语言
}

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

编译时就会出现各种问题,后来就添加了一行导入宏包\usepackage{xcolor},就解决了问题,记录下来。

正确代码:

\documentclass[11pt,a4paper]{ctexart}
\usepackage{xcolor}
\usepackage{listings}
%插入代码要引入的宏包
\author{gsc}
\title{sample}
\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                                         % 设置语言
}

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

搞定了在latex中展示latex代码

标签:control,latex,begin,end,Undefined,color,RGB,lstlisting,document
From: https://www.cnblogs.com/guochaoxxl/p/17977196

相关文章

  • 常用 $ \LaTeX $ 数学公式(持续更新)
    Updateon2022.11.12:修正了一处小错误希望这份东西能尽量帮助大家,节省在\(\LaTeX\)公式大全中寻找的时间,欢迎在评论区提出建议。如果您有需求,例如添加某一部分的公式,可私信号主。插入公式$你要插入的公式$这是普通插入(即紧跟随文字插入)$$你要插入的公式(最好是比较大的)$$......
  • 解决controller拿不到前端的参数
    如果在你的控制器(Controller)中无法获取前端传递的值,有几个常见的原因和解决方法:参数绑定错误:确保你的Controller方法的参数列表与前端传递的参数一致。使用@RequestParam、@PathVariable等注解来映射前端参数到方法的参数。@RestControllerpublicclassYourController{......
  • Avalonia TemplatedControl (模板控件)
    在ava中的模板控件相当于wpf中的自定义控件在下面示例中,将绘制一个文本框和一个按钮,用来组合一个搜索控件在app.axaml中加入样式<Application.Styles><FluentTheme/><StyleIncludeSource="/TemplatedControl1.axaml"/></Application.Styles>引入并使用xmlns......
  • Avalonia UserControl
    ava中的用户控件和wpf中的作用一致一般用来制作页面新建一个页面<UserControl...><StackPanelHorizontalAlignment="Center"VerticalAlignment="Center"><TextBlockText="这是一个用户控件"/><ButtonName="btn1&qu......
  • @RestControllerAdvice定义返回格式
    原文链接:如何优雅的写Controller层代码?一、拦截异常,封装返回值@RestControllerAdvicepublicclassControllerExceptionAdvice{@ExceptionHandler({BindException.class})publicResultVoMethodArgumentNotValidExceptionHandler(BindExceptione){/......
  • javascript中的undefined可以被重写
    众所周知,当声明一个变量,并且没有给赋值的情况下,它的初始值是 undefined。但是在javascript中,怎么检查一个值是否为 undefined 呢?在现代浏览器中,你可以安全的直接比较将变量是与 undefined 进行比较if(name===undefined){//...}一些人反对直接使用 undefined......
  • SpringMVC中@pathVariable 为spring的注解,都可以用在Controller 层接受前段传递的数据
    @PathVariable主要接收http://host:port/path{参数值}数据 @pathVariable作为借口是,url是http"//ww.yoodb.com/user/getUserById/2 @RequestParam主要用于接受http://host:port/path?参数名=值数据值 @ResquesrParam请求接口时,url是http://www.yoodb.com/user/getUsrBy......
  • latex中插入latex代码
    导言区插入:\usepackage{listings}%插入代码要引入的宏包\lstset{columns=fixed,basicstyle=\linespread{1.2}\ttfamily,%设置行距,字体numbers=left,%在左侧显示行号numberstyle=\t......
  • 使用ChatGPT解决在Spring AOP中@Pointcut中的execution如何指定Controller的所有方法
    背景使用ChatGPT解决工作中遇到的问题,https://xinghuo.xfyun.cn/desk切指定类在SpringAOP中,@Pointcut注解用于定义切点表达式,而execution属性用于指定切点表达式的具体匹配规则。要指定Controller的所有方法,可以使用以下方法:使用类名和方法名进行精确匹配。例如,如果要匹配名......
  • subline text 的package control 下载插件不全的解决办法
    起初我打算在sublinetext安装几个好用的插件方便刷题使用,可是在packagecontrol上找不到该插件,但是在https://packagecontrol.io/packages/这个插件是存在的,无奈之下重装packagecontrol问题依旧存在,于是只能从本地下载导入,但是效率很低,后来我发现,是由于我的packagecontrol使用......