如何打印所有环境变量?

如何打印所有环境变量?

许多语言都有printenvliststr()命令,允许您查看所分配变量的运行时环境... 我说的“环境变量”是指指定值时包含的值。如果值随时间变化,是否有某种跟踪功能?

我可以用来typeout打印“已知变量及其值”,例如:

\typeout{The footnote: \thefootnote}
\typeout{The footnote (arabic): \arabic{\thefootnote}}
\typeout{The footnote (value): \value{\thefootnote}}

如果我想抽象地了解变量及其值,而不想逐一表达,该怎么办?

答案1

\newcounterLaTeX 维护所有由(我假设这就是您所说的“变量”)声明的计数器的列表,因此您可以执行该列表来打印值。

\documentclass{article}

\begin{document}

\section{aaa}
\subsection{bbb}
x

\makeatletter
\def\@elt#1{\typeout{counter: #1, value: \the\value{#1}, representation: \csname the#1\endcsname}}
\cl@@ckpt

\end{document}

生产

counter: page, value: 1, representation: 1
counter: equation, value: 0, representation: 0
counter: enumi, value: 0, representation: 0
counter: enumii, value: 0, representation: 
counter: enumiii, value: 0, representation: 
counter: enumiv, value: 0, representation: 
counter: footnote, value: 0, representation: 0
counter: mpfootnote, value: 0, representation: {\itshape }
counter: part, value: 0, representation: 
counter: section, value: 1, representation: 1
counter: subsection, value: 1, representation: 1.1
counter: subsubsection, value: 0, representation: 1.1.0
counter: paragraph, value: 0, representation: 1.1.0.0
counter: subparagraph, value: 0, representation: 1.1.0.0.0
counter: figure, value: 0, representation: 0
counter: table, value: 0, representation: 0

相关内容