Skip to content

Commit 2b0d3f3

Browse files
doc: 修正快速使用手册中的\isGraduateTF
1. 之前的环境变量根本影响`\isGraduateTF`结果,始终用`#2`。这次将`if_eq`从 token list 的换成 string 的,并将`\GRADUATE`从`n`(token list)改为`V`(value of the command)。 > …we can choose between `\tl_if_eq:` (from token list library) and `\str_if_eq:` (from string library). Unless **it is absolutely necessary, it is recommended to use string library’s comparision functions**. That i1s because `\tl_if_eq:` not only checks if the characters are the same, but it also checks if the category code of each character is the same. As a result, two seemingly identical variables can result in `False` outcome when using `\tl_if_eq:`. > > —[LaTeX3: Programming in LaTeX with Ease | Alan Xiang’s Blog](https://www.alanshawn.com/tech/2020/10/04/latex3-tutorial.html) 2. 命令内部不能使用`lstlisting`环境。这里用`\lstinputlisting`绕开了。 这种情况只在`\isGraduateTF`的`#1`里有,之前测不到。
1 parent 648c5b8 commit 2b0d3f3

File tree

3 files changed

+15
-12
lines changed

3 files changed

+15
-12
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
@article{zhang2021,
2+
author = {张三 and 李四 and 王五},
3+
title = {论文标题},
4+
journal = {期刊名},
5+
year = {2021},
6+
volume = {1},
7+
pages = {1--10},
8+
author+an = {1:myself="\Author"},
9+
}

the-graduates-handbook/chapters/ch2-template-usage.tex

+1-11
Original file line numberDiff line numberDiff line change
@@ -177,17 +177,7 @@ \section{其他部分}
177177
根据 pub.bib 中的示例以及注释说明,为每个文献条目添加并设置
178178
\texttt{author+an} 字段。
179179
比如,如果作为张三的你的文献条目为:
180-
\begin{lstlisting}[language=TeX]
181-
@article{zhang2021,
182-
author = {张三 and 李四 and 王五},
183-
title = {论文标题},
184-
journal = {期刊名},
185-
year = {2021},
186-
volume = {1},
187-
pages = {1--10},
188-
author+an = {1:myself="\Author"},
189-
}
190-
\end{lstlisting}
180+
\lstinputlisting[language=TeX]{chapters/ch2-example-pub.bib}
191181
通过设置 \texttt{author+an} 字段,我们可以在盲审模式打开时,
192182
将自己的名字自动替换为「第一作者」。
193183
%

the-graduates-handbook/main.tex

+5-1
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,12 @@
9292
\tl_gset:Nn \GRADUATE {}
9393
\getenv[\GRADUATE]{GRADUATE}
9494

95+
% 若为研究生,显示第一个参数;若为本科生,显示第二个参数。
96+
% 命令内部不能使用 lstlisting 环境,原因如下。可用 \lstinputlisting 绕开。
97+
% Verbatim material can't be placed in a macro argument because then the material got already parsed by TeX and the switching to verbatim mode comes to late.
98+
% https://tex.stackexchange.com/a/122055
9599
\NewDocumentCommand{\isGraduateTF}{ m m } {
96-
\tl_if_eq:nnTF {\GRADUATE} { true } { #1 } { #2 }
100+
\str_if_eq:VnTF \GRADUATE { true } { #1 } { #2 }
97101
}
98102

99103
\ExplSyntaxOff

0 commit comments

Comments
 (0)