
我正在嘗試使用建議的答案將參數傳遞給 LaTeX 文檔,已發布這裡作為解決方案#三。
我在 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 列。