來自一個 .tex 檔案的多個 pdf 輸出

來自一個 .tex 檔案的多個 pdf 輸出

以下 MWE 程式碼在 TexLive2018 中完美運行,但在「www.overleaf.com」(線上 Latex 平台)中無法運作。

\documentclass{article}

\ifx\conditionmacro\undefined
\immediate\write18{%
    pdfLaTeX --jobname="\jobname1"
    \gdef\string\conditionmacro{1}\string\input\space\jobname
}%
\immediate\write18{%
    pdfLaTeX --jobname="\jobname2"
    \gdef\string\conditionmacro{2}\string\input\space\jobname
}%
\immediate\write18{%
    pdfLaTeX --jobname="\jobname3"
    \gdef\string\conditionmacro{3}\string\input\space\jobname
}%
\expandafter\stop
\fi

\begin{document}
    \ifnum\conditionmacro=1 
    Condition is 1
    \fi
    \ifnum\conditionmacro=2 
    Condition is 2
    \fi
    \ifnum\conditionmacro=3 
    Condition is 3
    \fi
    \verb|\conditionmacro| is \texttt{\meaning\conditionmacro}.
\end{document}

來自“www.overleaf.com”的原始日誌如下:

這是 pdfTeX,版本 3.14159265-2.6-1.40.19 (TeX Live 2018)(預先載入格式=pdflatex 2019.8.28)2019 年 11 月 28 日 12:59 進入擴充模式 \write18 已啟用。 %&-行解析已啟用。 **main.tex (/compile/main.tex LaTeX2e <2018-12-01> (/usr/local/texlive/2018/texmf-dist/tex/latex/base/article.cls 文件類別:文章 2018/09 /03 v1.4i 標準LaTeX 文件類別(/usr/local/texlive/2018/texmf-dist/tex/latex/base/size10.clo 檔案:size10.clo 2018/09/03 v1.4i 標準LaTeX 檔案(大小選項) ) \c@part=\count80 \c@section=\count81 \c@subsection=\count82 \c@subsubsection=\count83 \c@paragraph=\count84 \c@subparagraph=\count85 \c@figure= \count86 \c@table=\count87 \abovecaptionskip=\skip41 \belowcaptionskip=\skip42 \bibindent=\dimen102 ) runsystem(pdfLaTeX --jobname="output1" \gdef \conditionmacro{1}\input 輸出).. 執行執行。

runsystem(pdfLaTeX --jobname="output2" \gdef \conditionmacro{2}\input output).. .執行。

runsystem(pdfLaTeX --jobname="output3" \gdef \conditionmacro{3}\input output).. .執行。

) 這裡是你使用了多少TeX 記憶體: 492616 中的198 個字串6128979 中的2143 個字串字元5000000 中的59595 個記憶體字15000+600000 中的4200 個多字母控制序列80000 字型3640 個字體資訊字對於 9000 1141 連字例外 8191 23i,1n,17p,112b,36s 堆疊位置 5000i,500n,10000p,200000b,80000s

沒有輸出頁面。 PDF 統計資料: 1000 個中的 0 個 PDF 物件(最多 8388607) 1000 個中的 0 個指定目標(最多 500000) 10000 個中的 1 個用於 PDF 輸出的額外記憶體(最多 10000000)

有人能幫幫我嗎?

答案1

(來自 Overleaf 支援團隊的 Tom 撰寫。)

請注意,由於 Overleaf 設置,雖然您可以在或pdflatex內運行,但您必須小心檔案名稱。即設定為,但主文件保留其原始名稱(在下面的範例中)。\immediate\write18\ShellEsc\jobnameoutputmain.tex

所以依賴\input\jobname確實是不可能的,我會避免使用\jobname.另請注意,pdflatex在 *nix 機器上應全部小寫。最後但並非最不重要的一點是,訪問運行生成的文件的唯一方法shell-escape是透過日誌和輸出文件(權重新編譯) >其他日誌和文件。那裡有所有test?.pdf,test?.auxtest?.log文件。

最小範例(在 Overleaf 中呼叫main.tex以使其工作):

\documentclass{article}

\usepackage[margin=5pt]{geometry}

\ifx\conditionmacro\undefined
\gdef\conditionmacro{0}
\immediate\write18{
    pdflatex --jobname="test1" "\gdef\string\conditionmacro{1}\string\input\space main"
}
\immediate\write18{
    pdflatex --jobname="test2" "\gdef\string\conditionmacro{2}\string\input\space main"
}
\immediate\write18{
    pdflatex --jobname="test3" "\gdef\string\conditionmacro{3}\string\input\space main"
}
\fi

\usepackage{pdfpages}

\begin{document}
    \centering\fontsize{40}{45}\bfseries
    JOBNAME = \jobname\par
    \ifcase\conditionmacro\relax
        % = 0
        \fbox{\includegraphics[width=9cm]{test1.pdf}}
        \fbox{\includegraphics[width=9cm]{test2.pdf}}
        \fbox{\includegraphics[width=9cm]{test3.pdf}}
    \or
        % = 1
        Condition is 1
    \or
        % = 2
        Condition is 2
    \or
        % = 3
        Condition is 3
    \fi
%    \verb|\conditionmacro| is \texttt{\meaning\conditionmacro}.
\end{document}

相關內容