LaTex 파일에 인수 전달 문제

LaTex 파일에 인수 전달 문제

LaTeX 문서에 인수를 전달하는 데 제안된 답변을 사용하려고 합니다.여기솔루션#3.

Windows 명령 프롬프트에서 다음과 같이 인수를 전달합니다.

C:\Users\afp\projects>pdflatex "\def\InputFilename{sample}\input{myLaTeXDoc.tex}"

인수가 제공되지 않은 경우 처리할 기본 파일을 갖고 싶습니다. 그러나 컴파일러는 여전히 Undefined control sequence. \begin{filecontents*}{\FILENAME.csv}. 나는 둘 다 할 수 없다

  • 명령 프롬프트에서 인수를 전달하거나
  • 기본 csv 파일을 생성합니다.

누군가 저를 도와주실 수 있나요?

\documentclass[tikz, border=0mm]{standalone}

\usepackage{array}
\usepackage{readarray}
\readarraysepchar{,}

\usepackage{filecontents}

% If the argument is provided at the Windows command prompt, define \FILENAME as the input argument 
% otherwise define \FILENAME as a default comma-separated file to process.
\ifdefined\InputFilename
    \def\FILENAME{\InputFilename} 
\else
    \begin{filecontents*}{\FILENAME.csv}
        1,2,3
        4,5,6
        7,8,9
        10,11,12
    \end{filecontents*}
\fi

\begin{document}
    \wlog{filename is \FILENAME.csv}
    \readdef{\FILENAME.csv}\namedata
    \readarray\namedata\mydata[-,\ncols]
    \wlog{\FILENAME.csv has \nrows rows and \ncols columns.}
\end{document}

답변1

\FILENAME당신은 사용되는 경우를 정의하지 않습니다 filecontents*. 아마도 당신은 그것을 정의하는 것과 같은 것을 원할 것입니다.\jobname

\documentclass[tikz, border=0mm]{standalone}

\usepackage{array}
\usepackage{readarray}
\readarraysepchar{,}

\usepackage{filecontents}

% If the argument is provided at the Windows command prompt use it 
% otherwise create a default comma-separated file to process.
\ifdefined\InputFilename
    \def\FILENAME{\InputFilename} 
\else
    \def\FILENAME{\jobname} 
    \begin{filecontents*}{\FILENAME.csv}
        1,2,3
        4,5,6
        7,8,9
        10,11,12
    \end{filecontents*}
\fi

\begin{document}
    \wlog{filename is \FILENAME.csv}
    \readdef{\FILENAME.csv}\namedata
    \readarray\namedata\mydata[-,\ncols]
    \wlog{\FILENAME.csv has \nrows rows and \ncols columns.}
\end{document}

답변2

대답이 나에게 도움이 되지 않았습니다. 뭔가를 바꿔야 했습니다.

\documentclass[tikz, border=0mm]{standalone}

\usepackage{array}
\usepackage{readarray}
\readarraysepchar{,}


% If the argument is provided at the Windows command prompt, define \FILENAME as the input argument
% otherwise define \FILENAME as a default comma-separated file to process.
\ifdefined\InputFilename
    \def\FILENAME{\InputFilename}
\else
    \def\FILENAME{\jobname.csv}
    \begin{filecontents*}{\FILENAME}
        1,2,3
        4,5,6
        7,8,9
        10,11,12
    \end{filecontents*}
\fi

\begin{document}
    Filename is \FILENAME
    \readdef{\FILENAME}\namedata
    \readarray\namedata\mydata[-,\ncols]
    \FILENAME has \nrows rows and \ncols columns.
\end{document}

PDF가 생성되었습니다.

파일 이름은 Tabela.csv입니다. Tabela.csv에는 301행과 4열이 있습니다.

관련 정보