Problem beim Übergeben von Argumenten an eine LaTex-Datei

Problem beim Übergeben von Argumenten an eine LaTex-Datei

Ich versuche, die vorgeschlagene Antwort zum Übergeben von Argumenten an ein LaTeX-Dokument zu verwenden, gepostetHierals Lösung Nr. Drei.

Ich übergebe das Argument wie folgt in meiner Windows-Eingabeaufforderung:

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

Falls das Argument nicht angegeben wird, hätte ich gerne eine Standarddatei zum Verarbeiten. Der Compiler beschwert sich jedoch immer noch über Undefined control sequence. \begin{filecontents*}{\FILENAME.csv}. Ich kann weder

  • das Argument an der Eingabeaufforderung übergeben noch
  • Erstellen Sie eine Standard-CSV-Datei.

Kann mir dabei bitte jemand helfen?

\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}

Antwort1

Sie definieren nicht \FILENAMEin dem Fall, dass filecontents*verwendet wird, vermutlich möchten Sie so etwas wie dies, das definiert, dass es\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}

Antwort2

Die Antwort hat bei mir nicht funktioniert, ich musste etwas ändern:

\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}

Ich habe das PDF erstellt:

Der Dateiname lautet Tabela.csv. Tabela.csv hat 301 Zeilen und 4 Spalten.

verwandte Informationen