我正在尝试使用建议的答案将参数传递给 LaTeX 文档,发布这里作为解决方案#Three。
我在 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 列。