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 列があります。

関連情報