
나는 X
비슷한 매크로를 사용하고 있습니다
\newcommand{\X}[1]{{\ttfamily{\detokenize{#1}}}}
로 이스케이프할 필요 없이 밑줄이 포함될 수 있는 특정 단어의 형식을 지정합니다 \_
. 이것은 내가 \caption
. 이로 인해 pdflatex와 lualatex 모두에 오류가 발생합니다( ! Missing $ inserted.
). 다음 MWE를 고려하십시오.
\documentclass{article}
\newcommand{\X}[1]{{\ttfamily{\detokenize{#1}}}}
\begin{document}
\listoffigures
\begin{figure}
\centering
\caption{One \X{a_b} Two}
\end{figure}
\end{document}
다른/더 정교한 솔루션을 사용해야 합니까, X
아니면 일반적으로 밑줄을 피해야 합니까? 나는 매우 영리한 해킹보다는 모범 사례에 더 관심이 있습니다.
답변1
강력한 명령이 필요합니다. 그렇지 않으면 파일의 주석 .lof
이
\contentsline {figure}{\numberline {1}{\ignorespaces One \texttt {a_b} Two}}{1}%
{\ttfamily...}
(구문 을 에서 으로 변경했는데 \texttt{...}
, 이것이 더 좋습니다). 보시다시피 이 \detokenize
적용되고 사라졌습니다.
반면에 그렇게 한다면
\newcommand{\X}{}% for safety
\DeclareRobustCommand{\X}[1]{\texttt{\detokenize{#1}}}
주석은
\contentsline {figure}{\numberline {1}{\ignorespaces One \X {a_b} Two}}{1}%
문제는 표시되지 않습니다.
또는 \protect\X
움직이는 논쟁이 있을 때 사용하세요.