\newcommand 내의 #(해시태그) 무시

\newcommand 내의 #(해시태그) 무시

LilyPond를 LaTeX에 통합하기 위해 패키지를 사용하고 있습니다 lyluatex. 텍스트 내에서 올바른 크기의 Figured Bass를 편리하게 출력하기 위해 다음 명령을 만들었습니다.

\newcommand{\fig}[1]{%
    \raisebox{-2pt}{%
        \lilypond{%
        #(set-global-staff-size 18)%
        \figures {#1}
        }%
    }%
}

문제는 #(set-global-staff-size 18)실제로 인수가 아닌 LilyPond 명령입니다. 코드는 컴파일되지만 매번 잘못된 인수를 건너뛰도록 지시해야 합니다.

\detokenize효과가 없는 것으로 \string판명되었습니다.

LaTeX가 해시태그를 무시하도록 하면서 해시태그를 LilyPond에 전달하는 방법에 대한 제안이 있으십니까?

답변1

#에 들어가는 catcode 12일 수 있는 경우 \lilypad다음과 같습니다.

\documentclass{article}
\begin{document}
\newcommand{\fig}[1]{%
    \raisebox{-2pt}{%
        \prelilypond{%
        ##(set-global-staff-size 18)%
        figures {#1}% I removed the backslash for this non-working example.
        }%
    }%
}

\newcommand\prelilypond[1]{\expandafter\lilypond\expandafter{\string#1}}

\def\lilypond#1{#1}

\fig{1}
\end{document}

여기에 이미지 설명을 입력하세요

#catcode 6이어야 하는 경우 다음과 같습니다.

\documentclass{article}
\begin{document}
\newcommand{\fig}[1]{%
    \raisebox{-2pt}{%
        \lilypond{%
        ##(set-global-staff-size 18)%
        figures {#1}% I removed the backslash for this non-working example.
        }%
    }%
}

\def\lilypond#1{\string#1}

\fig{1}
\end{document}

분명히 이 예에서는 \lilypad장황한 내용으로 재정의했기 때문에 실제 음악적 예를 연주할 필요가 없었습니다.

답변2

\edef몇 가지 제어 시퀀스 이름을 확장할 수 없게 만들어야 하는 를 사용할 수 있습니다 . \fig새로운 명령인지 확인하려면 하위 수준 인터페이스가 필요합니다 .

\makeatletter
\@ifdefinable{\fig}{%
  \edef\fig#1{%
    \noexpand\raisebox{-2pt}{%
      \noexpand\lilypond{%
        \string#(set-global-staff-size 18)%
        \noexpand\figures {#1}%
      }%
    }%
  }%
}
\makeatother

관련 정보