极端 TeX 新手,抱歉这个例子太长了,我不确定哪些包对于复制问题很重要。我试图创建一个简单的命令,可以用来将带标签的注释注入现有文档。我的注释将以蓝色文本显示,并以首字母开头(本例中为“[XXX]”)
\documentclass[12pt]{article}
\usepackage{cprotect}
\usepackage{amssymb, amsmath, bm, bbm}
\usepackage{adjustbox}
\usepackage{amsmath, amsfonts}
\usepackage{bm, bbm}
\usepackage{graphics, graphicx, color, epsf}
\usepackage{natbib}
\usepackage{xr, zref, hyperref}
\usepackage{etoolbox, siunitx}
%
\usepackage{xcolor}
%
\usepackage{scrextend}
%
\newcommand\xxx[1] {\newline\textcolor{blue}{[XXX] #1}}
\begin{document}
\title{A title}
\author{A person}
\maketitle
\section{A section}
Some section stuff
\xxx{a comment}
\begin{verbatim}
This is
text that
presented 'as-is'
\end{verbatim}
Some more text
\xxx{
abc
\begin{verbatim}
verbatim
\end{verbatim}
}
\end{document}
生成:
line 37: Argument of \@xverbatim has an extra }. }
line 37: Paragraph ended before \@xverbatim was complete. }
line 37: Extra }, or forgotten \endgroup. }
: Emergency stop.
: Command \@footnotemark has changed.
我试图定义命令使用的新的环境(未显示),认为也许“命令”无法处理嵌套内容,但这没有帮助。
我想了解我做错了什么以及将来如何解决这些问题。
找到 TeX 语法的简洁摘要(不是 LaTeX,只是基本的 TeX)。
了解如何消除脚注警告。是否有某个包重新定义了该命令?
答案1
您可能可以使用 xparse 的+v
-type-argument 让 LaTeX 读取并标记逐字分类代码体系中的所有内容,然后将内容传递给\scantokens
重新标记,但如果您这样做,则\xxx
不能在宏参数/宏定义/等中使用:
\documentclass[12pt]{article}
\usepackage{xparse}
%
\usepackage{xcolor}
%
\begingroup
\newcommand\xxx[1]{%
\endgroup
\newcommand\xxx{%
\begingroup
\catcode`\^^I=12 %
\innerxxx
}%
\NewDocumentCommand{\innerxxx}{+v}{%
\endgroup
\textcolor{blue}{[XXX] %
\begingroup
\newlinechar=\endlinechar
\scantokens{\endgroup##1#1}}%
}%
}%
\catcode`\%=12\relax
\xxx{%}%
\begin{document}
\title{A title}
\author{A person}
\maketitle
\section{A section}
Some section stuff
\xxx{a comment}bla
\begin{verbatim}
This is
text that
presented 'as-is'
\end{verbatim}
Some more text
\xxx{%
abc
\begin{verbatim*}
verbatim
\end{verbatim*}
}%
Indenting is funny when nesting verbatim-environment in verbatim-argument:
\xxx{%
abc
\begin{verbatim*}
verbatim
\end{verbatim*}
}%
Indenting is funny when nesting verbatim-environment in verbatim-argument:
\xxx{%
abc
\begin{verbatim*}
verbatim
verbatim
\end{verbatim*}
}%
\end{document}