是否有可能获得编译文档中使用的所有命令? 我的意思是,如果我在各种.tex
-documents 命令中使用诸如\emph
、、、、、、和之\section
类\cite
的\begin
命令,我\documentclass
可以生成类似以下的列表吗?\footnote
\MyCommandX
\begin
\cite
\documentclass
\emph
\footnote
\MyCommandX
\section
答案1
拿一个文件,xyz.tex
我只是用它来回答另一个问题
\documentclass[12pt]{report}
\usepackage{array}
\usepackage{amsmath}
\begin{document}
\begin{tabular}{| >{$}c<{$} | c | c | c | c | c | c |c |}
\cline{2-8}
\multicolumn{1}{c|}{}&\multicolumn{7}{c|}{\rule{0mm}{0.4cm}{figure1 put here}}\\ \hline
\rule[-.5cm]{0mm}{1.2cm} x & -0.01 & -0.001 & -0.0001 & 0 & 0.0001 & 0.001 & 0.01 \\\hline
\rule[-.5cm]{0mm}{1.2cm} f(x) & 1.99499 & 1.9995 & 1.99995 & ? & 2.00005 & 2.0005 & 2.00499\\\hline
\multicolumn{1}{c|}{}&\multicolumn{7}{c|}{\rule{0mm}{0.4cm}\text{figure2 put here}}\\\cline{2-8}
\end{tabular}
addsomething with \emph{\$ and \^{a}}
\end{document}
然后一个简单的命令行,例如
egrep -o '\\[a-zA-Z]+|\\[^a-zA-Z]' xyz.tex | sort | uniq
生产
\$
\\
\^
\begin
\cline
\documentclass
\emph
\end
\hline
\multicolumn
\rule
\text
\usepackage
那是使用 unix-ish 工具(虽然我在 Windows 上)但任何编辑器都应该能够做同样的事情。
答案2
我偶然发现了这个问题,并认为列出控制序列会很有趣之内文档本身。当然,逐字输入 DC 的答案所生成的列表就足够了,但是假设我们想在一次运行中完成所有操作;这可以通过以下方式完成:
\documentclass[10pt,a4paper]{article}
\usepackage[T1]{fontenc}
\newcommand*{\meta}[1]{\(\langle\textit{#1}\rangle\)}
\title{The \TeX\ control sequences\\
used in this document}
\author{A.~U.~Thor}
\begin{document}
\maketitle
What follows is an alphabetized list of the names of all the \TeX\ control
sequences used in this same document:
\begin{flushleft}
\ttfamily
\catcode`\^ = 12
\catcode`$ = 0
\catcode`\\ = 12
$obeylines
$input{|"egrep -o '\\[a-zA-Z]+|\\[^a-zA-Z]' $jobname.tex | sort | uniq"}
$end{flushleft}
Note that \verb*|\ | is handled correctly, but \verb|\|\meta{CR} is not.
(We have included a \verb|\|\meta{CR} right here:~$\to$\
!)
Note also that the alfabetical ordering used by \texttt{sort} is somewhat
questionable, and that, of course, control sequences beginning with non-standard
escape characters, like \verb|$obeylines| or \verb|$input|, are not recognized.
\end{document}
当然,这个例子必须在启用shell-escape特性的情况下进行编译。
添加
以下是承诺的完善版本(请参阅下面的“对自己的评论”):
\documentclass[10pt,a4paper]{article}
\usepackage[T1]{fontenc}
\title{The \TeX\ control sequences\\
used in this document}
\author{A.~U.~Thor}
\newcommand*{\meta}[1]{\(\langle\textit{#1}\rangle\)}
\newcommand*{\CR}{\meta{CR}}
\newcommand*{\ListMyOwnCSNames}{%
\begin{flushleft}%
\ttfamily
\def\do##1{\catcode`##1=12\relax}%
\dospecials
\obeylines
\input{|"\CommandLine\jobname"}%
\end{flushleft}%
}
\newcommand*{\CommandLine}{} % let's behave well and declare the name
\begingroup
\catcode`\^ = 12
\catcode`\$ = 0
\catcode`\\ = 12
$gdef $CommandLine #1{%
egrep -o '\\[a-zA-Z]+|\\[^a-zA-Z]' #1.tex | sort | uniq%
}
$endgroup
\begin{document}
\maketitle
What follows is an alphabetized list of the names of all the \TeX\ control
sequences used in this same document:
\ListMyOwnCSNames
Note that \verb*|\ | is handled correctly, but \verb|\|\CR\ is not.
(We have included a \verb|\|\CR\ right here:~$\to$\
!)
Note also that the alfabetical ordering used by \texttt{sort} is somewhat
questionable, and that, of course, control sequences beginning with non-standard
escape characters, like \verb|$gdef| or \verb|$endgroup|, are not recognized.
Let's try a few special characters. It costs 100\$. Procter \& Gamble. You
are the~\#1!. De~l'H\^{o}pital. A variable named \textit{total\_cost}.
A~10\%~discount. \emph{Muchas gracias, se\~{n}orita!} (I~hope the Spanish is
correct!)
Moreover: let \( P = \{\,x\mid\mbox{$x$ is prime}\,\} \), and\\a line break.
\end{document}
请注意,如果这个问题还没有被归类为“有趣”标签的话,我可不敢写这样的答案。