
次の 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 文書クラス: article 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 output).. .実行されました。
runsystem(pdfLaTeX --jobname="output2" \gdef \conditionmacro{2}\input output).. .実行されました。
runsystem(pdfLaTeX --jobname="output3" \gdef \conditionmacro{3}\input output).. .実行されました。
) TeX のメモリ使用量は次のとおりです: 文字列 198 (492616 個中) 文字列文字 2143 (6128979 個中) メモリ 59595 ワード (5000000 個中) マルチレター制御シーケンス 4200 (15000+600000 個中) フォント情報 3640 ワード (14 フォント、9000 フォント、8000000 個中) ハイフネーション例外 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
\jobname
output
main.tex
したがって、 に頼るのは\input\jobname
不可能なので、 の使用は避けたほうがよいでしょう\jobname
。またpdflatex
、 *nix マシンでは はすべて小文字にする必要があることに注意してください。最後に、実行によって生成されたファイルにアクセスする唯一の方法shell-escape
は、ログと出力ファイル(右の再コンパイル) >その他のログとファイルtest?.pdf
、test?.aux
およびファイルがすべてそこにありますtest?.log
。
main.tex
最小限の例 (これを動作させるために Overleaf で呼び出されます):
\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}