4

On my computer, in the same folder, I create the main document main.tex and a figure disc.tex - a standalone TikZ/Asymptote code. First run disc.tex to get disc.pdf, then run main.tex (there is \includegraphics{disc.pdf} in it). It works as usual. This way helps increasing compilation time, especially when there are a lot of figures in the main document.

enter image description here

The content of main.tex:

\documentclass{article}
\usepackage{graphics,lipsum}
\begin{document}
\lipsum[1]

\begin{figure}
\centering
\includegraphics{disc.pdf}
\caption{This is my disc}
\label{fig:mydisc}
\end{figure}

\lipsum[2]
\end{document}

The content of disc.tex:

\documentclass[tikz]{standalone}
\begin{document}
\begin{tikzpicture}
\fill[cyan!50] circle(1) node[red]{unit disc};
\end{tikzpicture}
\end{document}

How can I do a similar thing on Overleaf? In my example project Overleaf did not recognize where the disc.pdf is.

enter image description here

I think this situation is quite common for TeX users on Overleaf, but I have not found suitable answers on texSE yet. This answer suggested making 2 or more projects, one is for the main document and each others are for each figure, then importing output.pdfs (with name changing if necessary) to the main project. This is not so convenient: think each time we repair code of a figure, we need to import again. We write a book of 100 figures, we need one project, not 101 projects, right?

4
  • You are aware that you consistently mispelled disc as dics in your question, yes?
    – Markus G.
    Sep 27, 2021 at 18:00
  • @MarkusG. Yes, I have just correct it. However the problem still exists: Overleaf did not recognize pdf output of another tex file in the same project
    – Black Mild
    Sep 27, 2021 at 18:10
  • Looks like you can set folders in one of the Overleaf menues, see here: tex.stackexchange.com/questions/536146/…
    – MS-SPO
    Sep 27, 2021 at 18:32
  • @MS-SPO I have cited that link in my question. It is not what I ask.
    – Black Mild
    Sep 28, 2021 at 3:05

2 Answers 2

5

You could also try using the standalone package and \includestandalone in main.tex:

\documentclass{article}
\usepackage{graphicx,lipsum}
\usepackage[mode=buildnew]{standalone}
\begin{document}
\lipsum[1]

\begin{figure}
\centering
\includestandalone{disc}
\caption{This is my disc}
\label{fig:mydisc}
\end{figure}

\lipsum[2]
\end{document}

Compiling main.tex will then trigger compiling disc.tex, produce disc.pdf, and use it in main.tex.

enter image description here

You can also download disc.pdf from the generated files list.

3

overleaf copies the main document to /compile and uses -jobname=output so everything's called output.pdf and the file is not there when you need it. You can do

enter image description here

adding

\immediate\write18{pdflatex disc}

to main.tex so it compiles disc.pdf in the directory generated for main but note that it does this every time so you don't save any time.

You could wrap that in a test to see if disc.pdf exists


\IfFileExists{disc.pdf}{}{%
\immediate\write18{pdflatex disc}
}

Then if you edit disc.pdf you would need to comment out the test temporarily to force a disc.pdf rebuild

1
  • Thanks for your information! it is a bit pity that it can not be done on Overleaf as the way we do on computers
    – Black Mild
    Sep 28, 2021 at 7:50

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .