\DeclareDocumentCommand{}{omv}{}를 사용하여 명령을 생성할 수 없습니다.

\DeclareDocumentCommand{}{omv}{}를 사용하여 명령을 생성할 수 없습니다.

코드의 기능을 설명하는데 사용되는 설명을 기반으로 목록 환경을 만들어야 합니다.

프로토타입은 다음과 같습니다.

% !TeX program = lualatex

\documentclass[11pt]{report}
\usepackage{enumitem}
\usepackage{minted}
\usepackage{xparse}

\newlist{funcDescription}{description}{1}
\setlist[funcDescription, 1]{itemsep=2mm, style=nextline, font=\mdseries\ttfamily, align=left}
\NewDocumentCommand{\funcitem}{O{}mv}{\item[\mintinline[#1]{#2}|#3|]}

\begin{document}

    \begin{funcDescription}
        \funcitem{c}{int printf(const char * format, ...)}
            Writes the \code{C} string pointed by format to the standard output
            (stdout). If format includes format specifiers (subsequences
            beginning with \code{\%}), the additional arguments following
            format are formatted and inserted in the resulting string replacing
            their respective specifiers.
    \end{funcDescription}
    
\end{document}

그것은 생산한다

document.tex|32 error| Argument of \\RobustMintInline has an extra }.
document.tex|| Runaway argument?
document.tex|32 error| Paragraph ended before \\RobustMintInline was complete.

대신에

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

O{}옵션 을 제거하면 \funcitem모든 것이 의도한 대로 작동합니다.

% !TeX program = lualatex

\documentclass[11pt]{report}
\usepackage{enumitem}
\usepackage{minted}
\usepackage{xparse}

\newlist{funcDescription}{description}{1}
\setlist[funcDescription, 1]{itemsep=2mm, style=nextline, font=\mdseries\ttfamily, align=left}
\NewDocumentCommand{\funcitem}{mv}{\item[\mintinline{#1}|#2|]}

\begin{document}

    \begin{funcDescription}
        \funcitem{c}|int printf(const char * format, ...)|
            Writes the \code{C} string pointed by format to the standard output
            (stdout). If format includes format specifiers (subsequences
            beginning with \code{\%}), the additional arguments following
            format are formatted and inserted in the resulting string replacing
            their respective specifiers.
    \end{funcDescription}
    
\end{document}

무슨 일이 일어나고 있나요? 선택적 인수 \funcitem[]{}||로 작업 하는 방법은 무엇입니까 ?O{}

( texdoc에 대한 연구는 xparse도움이 되지 않았습니다. v키가 불안정할 수 있다고만 말하고, minted문서에서는 키의 환경이 거의 모든 상황에서 작동하도록 세심하게 제작되었다고 말합니다.)

업데이트 1

나는 실현을 가지고 놀았고 \funcitem다음 구현을 사용할 때 발견했습니다.

\NewDocumentCommand{\funcitem}{mv}{\item[{\mintinline[tabsize=4]{#1}|#2|}]}

동일한 오류가 발생합니다. 따라서 문제는 O{}or 가 아니라 o의 선택적 인수에 있습니다 \mintinline. 또한 \item에서 제거 \funcitem하고 환경 외부에서 사용해도 fundDescription오류가 발생하지 않습니다. 무슨 일이 일어나고 있나요?

답변1

주석에서 언급했듯이 축어와 유사한 명령을 다른 명령의 인수에 넣는 것은 지원되지 않으며 기껏해야 '우연히' 작동합니다. 즉, 여기서 특정 문제는 문자 그대로와는 관련이 없는 다른 원인을 가지고 있습니다.

LaTeX에서 '고전적인' 선택적 인수 잡기는~ 아니다레벨과 일치하므로 선택적 인수로 읽 \item[\mintinline[#1]{#2}|#3|]히게 됩니다 . 그런 다음 명령은 선택적 인수를 읽으려고 시도하지만 끝을 찾지 못하여 낮은 수준의 오류가 발생합니다. (일치 수행)을 사용하여 정의했다면 이런 일은 발생하지 않습니다.\item\mintinline[#1\mintinline]\itemltcmd

선택적 인수를 중첩하는 방법은 중괄호를 사용하여 '내부' 인수를 숨기는 것입니다.

\item[{\mintinline[#1]{#2}|#3|}]

그렇게 하면 당면한 문제가 해결될 것이지만, 말 그대로의 부분은 여전히 ​​걱정거리로 남을 것입니다.

관련 정보