매크로 비교 실패

매크로 비교 실패

저는 LaTex를 처음 접했는데 동료들로부터 문제를 받았습니다. TeX 파일에서 문서 유형을 정의합니다(예: 'svvr', 'srs', ...). 이 외부 정의는 예제 코드(MWE 2)의 4행과 5행에 해당합니다.

이제 TeX 파일에서 이 외부 정의를 사용하여 어떤 문서 종속 처리가 이루어져야 하는지 결정해야 합니다. 이를 위해 선택을 테스트하기 위해 MWE를 작성했습니다.

내 테스트 코드는 원래 인터넷에서 가져온 것이며 작업 이름을 주어진 문자열(예: "{\detokenize{svvr}")과 비교합니다. \jobname과 비교할 수 있도록 TeX 파일 이름을 "svvr.tex"로 지정했습니다.

이제 내 문제는 \jobname(MWE 1)과 비교할 때 선택이 올바르게 작동한다는 것입니다.

\documentclass{article}

% Own TeX file:
\begin{document}
    \edef\docTypeExt{\jobname}
    % Specify which document type is to be handled: 'svvr', 'srs', ...
    \edef\docTypeSvvr{\detokenize{svvr}} 
    \edef\docTypeSrs{\detokenize{srs}}

    \textbf{\jobname} 
    \textbf{\docShortcut}
    \textbf{\docTypeSvvr}
    \textbf{\docTypeSrs}
    \newline
    
    \ifx\docTypeExt\docTypeSvvr
        true
    \else
        false: \\
        \jobname \\
        \docShortcut \\
        \docTypeSvvr
    \fi
\newline

    \ifx\docTypeExt\docTypeSrs
        true
    \else
        false: \\
        \jobname \\
        \docShortcut \\
        \docTypeSrs
    \fi

\end{document}

그러나 동료의 외부 정의(MWE 2)와 비교하면 비교가 실패합니다.

\documentclass{article}

% Given code, defined in included TeX file: 'svvr', 'srs', ...
\newcommand { \docpropPTdocShortcut } {svvr}    % Define document type here!
\gdef\docShortcut{\docpropPTdocShortcut}

% Own TeX file:
\begin{document}
    \edef\docTypeExt{\docShortcut}
    % Specify which document type is to be handled: 'svvr', 'srs', ...
    \edef\docTypeSvvr{\detokenize{svvr}} 
    \edef\docTypeSrs{\detokenize{srs}}

    \textbf{\jobname} 
    \textbf{\docShortcut}
    \textbf{\docTypeSvvr}
    \textbf{\docTypeSrs}
    \newline
    
    \ifx\docTypeExt\docTypeSvvr
        true
    \else
        false: \\
        \jobname \\
        \docShortcut \\
        \docTypeSvvr
    \fi
\newline

    \ifx\docTypeExt\docTypeSrs
        true
    \else
        false: \\
        \jobname \\
        \docShortcut \\
        \docTypeSrs
    \fi

\end{document}

외부 정의와도 작동하려면 선택을 어떻게 구성해야 합니까?

정의를 수정했지만 지금까지의 시도는 모두 실패했습니다.

답변1

에서 전달하는 모든 캐릭터 토큰은 \jobname카테고리 12(기타)에 속합니다. 예외: 공백(ASCII 및 유니코드 모두에서 코드 포인트 번호 32)은 범주 10(공백)에 속합니다. 에서 전달한 캐릭터 토큰과 동일합니다 \detokenize.

그러나 두 번째 예에서 대체 텍스트로 들어가는 문자 ​​토큰은 TeX가 .tex-input 파일에서 내용을 읽고 토큰화하여 \docpropPTdocShortcut전달되지 않거나 생성됩니다 \jobname. \detokenize이로써 또 다른 카테고리 코드 제도가 적용되어 이러한 방식으로 생성되는 많은 문자 토큰이 12(기타)와 다른 카테고리를 갖게 됩니다. 예를 들어, 이런 식으로 생성되는 알파벳 문자를 나타내는 문자 토큰은 일반적으로 카테고리 11(문자)을 갖습니다.

따라서 대체 텍스트가 카테고리 12(기타)의 문자 토큰 또는 카테고리 10(공백)의 문자 토큰인 문자 토큰 으로만 구성된 제어 시퀀스 토큰 \docTypeSvvr또는 은 컨트롤의 의미와 다른 의미를 갖습니다. 동일한 문자가 카테고리 11(문자)로 토큰화된 시퀀스 입니다. 따라서 두 번째 예제와의 -비교는 -branch로 라우팅됩니다.\docTypeSrs\jobname\detokenize\docTypeExt
\ifx\else

두 번째 예에서는 /를 \detokenize정의할 때 생략 하거나 적용할 때 또는 를 정의할 때 생략할 수 있습니다 .\docTypeSvvr\docTypeSrs\detokenize\@onelevel@sanitize\docTypeExt

\newlineLaTeX가 단락을 계속 조판하게 하지만 단락의 다른 줄을 시작하고 뒤에 빈 줄이 추가되어 LaTeX가 현재 단락을 끝내게 하는 것은 나에게 다소 중복된 \baselineskip것처럼 보입니다 \newline. \parskip0이 아닙니다. 수직이 \parskip0이고 어떤 곳에서 단락 사이에 수직 건너뛰기를 원하는 경우 \newline이를 남용하지 말고 \vspace또는 또는 \addvspave또는 \vskip또는 \smallskip또는 \medskip을 사용하십시오 \bigskip.

\newcommand { \docpropPTdocShortcut } {svvr}, \docpropPTdocShortcut토큰화 뒤에 공간 토큰이 오는 것은 좋은 습관이 아닙니다. 토큰화할 때 공백이 이미 무시되는 ExplSyntax가 아닌 경우 다음을 수행하십시오
\newcommand{\docpropPTdocShortcut}{svvr}.

아래 예에서는 -route가 사용되므로 원하는 경우 \detokenize확장으로 대체 텍스트가 구성되는 매크로와 안전하게 비교할 수 있습니다 .\jobname

\documentclass{article}


% Given code, defined in included TeX file: 'svvr', 'srs', ...
%% (In case the TeX file in question does not produce text/a chapter of the document, 
%%  \input might be a better choice than \include ...)

\newcommand{\docpropPTdocShortcut}{svvr}% Define document type here!
\gdef\docShortcut{\docpropPTdocShortcut}

% Own TeX file:
\begin{document}
  \edef\docTypeExt{\docShortcut}%%
  \edef\docTypeExt{\detokenize\expandafter{\docTypeExt}}%%
  %\csname @onelevel@sanitize\endcsname\docTypeExt
  %-----------------------------------------------------------------  
  % Specify which document type is to be handled: 'svvr', 'srs', ...
  \edef\docTypeSvvr{\detokenize{svvr}}%%
  \edef\docTypeSrs{\detokenize{srs}}%%

  \noindent
  \verb|\jobname|: \texttt{\jobname}\\
  \verb|\docShortcut|: \texttt{\meaning\docShortcut}\\
  \verb|\docTypeExt|: \texttt{\meaning\docTypeExt}\\
  \verb|\docTypeSvvr|: \texttt{\meaning\docTypeSvvr}\\
  \verb|\docTypeSrs|: \texttt{\meaning\docTypeSrs}

  \vskip\baselineskip

  \noindent
  \ifx\docTypeExt\docTypeSvvr
      true
  \else
      false:\\
      \jobname\\
      \docShortcut\\
      \docTypeSvvr
  \fi

  \vskip\baselineskip

  \noindent
  \ifx\docTypeExt\docTypeSrs
      true
  \else
      false:\\
      \jobname\\
      \docShortcut\\
      \docTypeSrs
  \fi
\end{document}

관련 정보