从同一个tex文件中创建多个pdf文件

问题描述 投票:0回答:2

我有多个数据文件(result_a.csv, result_b.csv, ...),我想为每个数据文件(result_a.pdf, result_b.pdf--或类似的文件)创建绘图。绘图是一样的,但输入文件和输出文件是不同的。有没有一种方法可以让我运行一个循环,从外面传递参数名,然后用一个独特的名字保存输出?

假设我的创建情节的代码--------。

\documentclass[tikz]{standalone}

\usepackage{pgfplots}
\pgfplotsset{ytick style={draw=none}, xtick style={draw=none}}
\usetikzlibrary{patterns}

\newcommand\param{a}

\begin{document}
\begin{tikzpicture}
\footnotesize
    \begin{semilogxaxis}
\addplot[color=red,mark=triangle] table [x=x,y=y,col sep=comma, mark=*] {result_\param.csv}; 
\end{semilogxaxis}
\end{tikzpicture}




\end{document}
latex pdflatex
2个回答
2
投票

假设你的文件叫 document.tex你可以通过编译以下命令将csv文件的名称传递给文档

pdflatex -jobname="document-b" "\\newcommand*\\version{b}\\input{document}"

和文档。

\documentclass[tikz]{standalone}

% setting a default value in case it is compiled without the newcommand
\unless\ifdefined\version
\def\version{a}
\fi


\usepackage{pgfplots}
\pgfplotsset{ytick style={draw=none}, xtick style={draw=none}}
\usetikzlibrary{patterns}

\newcommand\param{a}

\begin{document}
\begin{tikzpicture}
\footnotesize
    \begin{semilogxaxis}
\addplot[color=red,mark=triangle] table [x=x,y=y,col sep=comma, mark=*] {result_\version.csv}; 
\end{semilogxaxis}
\end{tikzpicture}

\end{document}

1
投票

如果你是在Linux Distro或Mac OS下工作 你可以使用一个shell脚本。让 init.tex 为tex文件,其中有

\documentclass[tikz]{standalone}

\usepackage{pgfplots}
\pgfplotsset{ytick style={draw=none}, xtick style={draw=none}}
\usetikzlibrary{patterns}

\newcommand\param{a}

\begin{document}
\begin{tikzpicture}
\footnotesize
    \begin{semilogxaxis}
\addplot[color=red,mark=triangle] table [x=x,y=y,col sep=comma, mark=*] {

且让 ends.tex 是含有

}; 
\end{semilogxaxis}
\end{tikzpicture}

下面的脚本读取每个.csv文件,并将其内容放到一个tex文件中,组织如下。

  • init.tex
  • result_x.csv
  • ends.tex

产生tex文件 result_xx.tex 并编译它,提供文件 result_xx.pdf

#!/bin/bash

for i in $(ls *.csv)
do
    a=$(basename -s .csv $i)
    cp init.tex $a.tex
    echo $i >> $a.tex
    cat ends.tex >> $a.tex
    pdflatex $a.tex

done

这是个天真的解决方案,SO这里有比我更有经验的bash--写脚本的人,但应该能用。

PS. 记得要把脚本做成可执行的才行。

chmod 755 myscript.sh

比如说... 此处.

© www.soinside.com 2019 - 2024. All rights reserved.