0

I am trying to write a template for my homework using the package standalone for every exercise, since they can get really long and I want them to compile fast (since I use overleaf with my colleagues), otherwise I would have to always compile the whole file, which can take some time. I wrote a template and it works but sometimes, when I copy it into a new projekt, I get errors. I managed to find out, that they happen because of [subpreambles=true] in the main tex document, if I leave that, the errors disappear and everything works fine, but I could get a problem if I need to include some older files someday, so I need to use subpreambles. The strange thing is, that this error only happens sometimes. If I delete the project and start a new one with exactly the same code, it works sometimes completely without problems (and if it works once, then it works all the time). Does anyone know, what causes this problem, or could this be a problem of overleaf?

Here comes all my code and the errors. If have a main.tex, this is the code:

\documentclass[a4paper,11pt]{article}

\usepackage[subpreambles=true]{standalone}
\usepackage{import}
\usepackage{fullpage}
\usepackage[utf8]{inputenc}
\usepackage[ngerman]{babel}
\usepackage{ifthen}
\usepackage{amsmath}
\usepackage{amssymb}

\newcounter{aufgabe}
\renewcommand{\theaufgabe}{\arabic{aufgabe}}

\newcommand{\diff}[2]{\frac{d#1}{d#2}}

\newenvironment{aufgabe}[1]
{\smallskip\refstepcounter{aufgabe}\textbf{Lösung zu Aufgabe~\theaufgabe:}\newline\vspace{#1}}
{\par \hspace*{\fill}$\square$\medskip}

\begin{document}
    \allowdisplaybreaks
    \setlength{\parindent}{0pt}
    \setlength{\baselineskip}{1\baselineskip}
    
    1.12.2020 \hfill Namen einfügen\smallskip
    
    \setcounter{aufgabe}{24}
    
    \begin{center}
        {\large\underline{Beliebiges Fach - Übungsblatt 7}}
    \end{center}\medskip
    
    \begin{aufgabe}{-0.5cm}
        \import{aufgaben/}{aufgabe25}
    \end{aufgabe}
    
    \clearpage
    
    \begin{aufgabe}{-0.5cm}
        \import{aufgaben/}{aufgabe26}
    \end{aufgabe}
    
    \clearpage
    
    \begin{aufgabe}{-0.5cm}
        \import{aufgaben/}{aufgabe27}
    \end{aufgabe}
    
    \clearpage
    
    \begin{aufgabe}{-0.5cm}
        \import{aufgaben/}{aufgabe28}
    \end{aufgabe}

\end{document}

Then I also have a folder called aufgaben, which holds the files aufgabe25.tex,..., aufgabe28.tex. They all have the same code, that is

\documentclass[class=article, crop=false]{standalone}
\usepackage[subpreambles=true]{standalone}
\usepackage{import}

\usepackage{fullpage}
\usepackage[utf8]{inputenc}
\usepackage[ngerman]{babel}
\usepackage{latexsym}
\usepackage{amssymb}
\usepackage{enumerate}
\usepackage{ifthen}
\usepackage{amsmath}
\usepackage[hidelinks]{hyperref}
\usepackage{listings}
\usepackage[dvipsnames]{xcolor}
\usepackage[framemethod=tikz]{mdframed}
\usepackage{bbm}
\usepackage[most]{tcolorbox}
\usepackage{needspace}

\usepackage{silence}% Filter out unwanted warnings and error messages
% Remove all warnings issued by LaTeX that starts with
\WarningFilter[todo]{latex}
  {Reference }                      % 'Reference ' and
\WarningFilter[todo]{latex}
  {There were undefined references} % 'There were undefined references'

\ActivateWarningFilters[todo]% Activate the 'todo' warnings filter

\begin{document}

    \newcommand{\R}{\ensuremath{\mathbb{R}}}
    \newcommand{\cunderline}[2]{\textcolor{#1}{\underline{\textcolor{black}{#2}}}}
    \newcommand{\bunderbrace}[2]{\ensuremath{\begin{array}[t]{@{}c@{}} \underbrace{#1}\\ #2\end{array}}}
    \newcommand{\uproman}[1]{\uppercase\expandafter{\romannumeral#1}}
    \newcommand*{\mybox}[1]{\framebox{\strut #1}}

    \allowdisplaybreaks
    \setlength{\parindent}{0pt}
    \setlength{\baselineskip}{1\baselineskip}

    Start here...

\end{document}

Maybe it looks a bit messy, but I need all the packages. Note that I use the silence package to be able to reference math from other exercises since I do not want to deal with all the warnings when compiling the exercise files.

I cannot post the log file since it has to many characters and I looks like spam for this forum, but all errors come from the standalone package.

2
  • You didn't tell which error you get, but subpreambles combines the preambles of all the files. This is not an option that you should use together with "a bit messy" preambles. You should have a clear idea how the various preambles work together. Dec 2 '20 at 14:04
  • I just want to have one main file where I can drop in all other files and compile them together such that numbering and so on still works, but I still want to be able to compile all other files separately and import futher files in them, for example tikz pictures or older exercises. How can one achieve this? I read that I would need subpreambles=true so that I can still import files into the individual files.
    – question
    Dec 2 '20 at 16:30
1

Since all of your aufgabeXX.tex have the same preamble, I would suggest using the subfiles package instead of standalone.

With subfiles, you only have to declare the preamble once, in the main file. Then, all the "subfiles" will pull the preamble from the main file. And you still get to compile either the individual files or the main complete file, as you wish.

Have a look at this page for a comparison between subfiles and standalone packages, as well as further instructions on how to implement. Check the remarks on how to define paths for the packages (the page gives an example for \graphicspath), since you have subfolders and want to import from them.

2
  • Does this solve your problem? If not, I kindly ask you to comment so I can improve. If it solves, please select my answer. Thanks!
    – viking
    Jan 23 at 22:28
  • I know the subfiles package already, but I would lose the option to include nested subfiles in the subfiles themselves, that is one thing I want to have. I found out what the problem was by myself, newer versions of overleaf create this error, I can simply compile in an older version, if I get the error, and then go back to the newest one.
    – question
    Jan 27 at 15:46

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.