5

The following MWE code is working perfectly in TexLive2018 but is not working in "www.overleaf.com" (an online Latex platform).

\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}

The raw log from "www.overleaf.com" is as follows:

This is pdfTeX, Version 3.14159265-2.6-1.40.19 (TeX Live 2018) (preloaded format=pdflatex 2019.8.28) 28 NOV 2019 12:59 entering extended mode \write18 enabled. %&-line parsing enabled. **main.tex (/compile/main.tex LaTeX2e <2018-12-01> (/usr/local/texlive/2018/texmf-dist/tex/latex/base/article.cls Document Class: article 2018/09/03 v1.4i Standard LaTeX document class (/usr/local/texlive/2018/texmf-dist/tex/latex/base/size10.clo File: size10.clo 2018/09/03 v1.4i Standard LaTeX file (size option) ) \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).. .executed.

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

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

) Here is how much of TeX's memory you used: 198 strings out of 492616 2143 string characters out of 6128979 59595 words of memory out of 5000000 4200 multiletter control sequences out of 15000+600000 3640 words of font info for 14 fonts, out of 8000000 for 9000 1141 hyphenation exceptions out of 8191 23i,1n,17p,112b,36s stack positions out of 5000i,500n,10000p,200000b,80000s

No pages of output. PDF statistics: 0 PDF objects out of 1000 (max. 8388607) 0 named destinations out of 1000 (max. 500000) 1 words of extra memory for PDF output out of 10000 (max. 10000000)

CAN SOMEBODY PLEASE HELP ME??

  • 4
    The code needs --shell-escape and imho overleaf doesn't allow this. – Ulrike Fischer Nov 28 '19 at 13:22
  • 5
    Hello! This is Tom from the Overleaf Support Team. Note that what Ulrike mentions is basically right; we have to apply security restrictions, and --shell-escape conveys some security threats. I'll though double-check what exactly is going on here, and then eventually answer you in more detail. – yo' Nov 28 '19 at 13:27
  • 2
    So I found out the process it yet more complicated; the issue is not in shell-escape restriction, but in \jobname changes. See the answer. – yo' Nov 28 '19 at 13:57
12

(Tom from the Overleaf Support Team writing.)

Please note that due to the Overleaf setup, while you can run pdflatex within \immediate\write18 or \ShellEsc, you have to be careful about file names. Namely the \jobname is set to output, but the main file keeps it original name (main.tex in the example below).

So relying on \input\jobname is really impossible, and I'd avoid any usage of \jobname. Also note that pdflatex should be all lowercase on *nix machines. Last but not least, the only way to access the files generated by the shell-escape runs is via Logs and output files (right of Recompile) > Other logs & files. There you have all the test?.pdf, test?.aux and test?.log files.

Minimal example (to be called main.tex in Overleaf to make this work):

\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}
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.