4

This is my first post on this amazing website, so hi to everybody!!

I'd like to know if there is a way to pass some parametrs (macros or lengths) to a standalone file.

Here is my MWE:

Consider the following main.tex file:

\documentclass{report}

\usepackage{standalone}
\standaloneconfig{mode=buildnew}

\newlength{\mylen}
\setlength{\mylen}{50pt}
\newcommand{\myl}{50pt}

\begin{document}    

    \ \\
    main: \the\mylen, \myl \\ 
    \includestandalone{safile}\\ 

\end{document}

And this is the standalone file safile.tex:

\documentclass[varwidth]{standalone}

\begin{document}

    standalone: \the\mylen, \myl\\ 

\end{document}

And the result that I get is the following:

main: 50.0pt, 50pt
standalone: 0

But I was expecting to see:

main: 50.0pt, 50pt
standalone: 50.0pt, 50pt

Is there a way to make this work?

Thanks in advance for your replies.

9
  • I get what you expect when i compile main.tex.
    – jon
    Commented Jul 11, 2015 at 15:52
  • This is strange... I don't... I am using TeXShop on Mac. Do you think it can be some program-related preference?
    – Alessandro
    Commented Jul 11, 2015 at 15:54
  • Welcome! No: not a programme preference. TeXShop doesn't do the compiling. It is just an editor. There is certainly no general problem with standalone files picking up all kinds of definitions and settings from the main file. (Though I tend to use \input{} rather than \includestandalone{}.)
    – cfr
    Commented Jul 11, 2015 at 15:55
  • Thanks for the fast reply! Ok, with \input{} macros and lengths are correctly interpreted now. The reason why I was using \includestandalone{} is because there should be a tikz picture in the standalone file which is very heavy and I don't want it to be compiled every time. With \includestandalone{} is not recompiled every time (but macros and lengths are lost), with \input{} instead is always recompiled.
    – Alessandro
    Commented Jul 11, 2015 at 16:07
  • Well, I'm on TeX Live 2014, still; if I add \listfiles, I see at the end of main.log: standalone.sty 2012/09/15 v1.1b Package to include TeX sub-files with preambles among other things.
    – jon
    Commented Jul 11, 2015 at 16:29

1 Answer 1

1

The reason you get standalone: 0 here is because of the \standaloneconfig{mode=buildnew}. You are telling standalone to compile the subfile on its own. This calls LaTeX internally again on the subfile, then include the resulting PDF as an image. The image is kept and not built again as long the subfile does not change.

This way the macro definitions in the main file are never seen by the subfile code as they are compiled separately. The 0 is a fallback of \the, I guess, as \mylen isn't defined in this case. Actually the subfile compilation is stopped there because of that error.

However, if you compile it with the main document (e.g. by changing the mode or by not enabling -shell-escape which is needed to start the second compilation) then the subfile sees the definition.

As a solution to this I would suggest that you

  1. either place the definition in an third small file \inputed by both other files, or
  2. avoid the buildnew and other build... options for this document, but include the subfile as TeX code, not as an image.

You must log in to answer this question.

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