Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

You can use \standalonefalse to specify the parent document for which all sub-documents should be considered sub-documents, I think.

Is it possible to re-enable standalone with something like \standalonetrue after a \standalonefalse call?

I would like this capability because I have a paper that uses standalone for its subsections that is being included in a thesis, which also uses standalone. I'd like to be able to compile the chapter, the paper, and the thesis each independently (since each document has different dependencies / build times).

EDIT: MWE below and here: https://gist.github.com/keflavich/5224790 (because there are multiple file interdependencies, I figured it was best to have a complete example in one place).

My understanding of both latex conditionals and standalone must be pretty weak. I've constructed a MWE (sub2.tex):

\documentclass{article}
\usepackage{standalone}
%\standalonetrue
\usepackage{import}
\usepackage{natbib}
\begin{document}
\section{Section}
Nothing here (but I want to compile this document on its own sometimes)
\citet{Aguirre2010}
\ifstandalone
\bibliographystyle{apj_w_etal}  
\bibliography{mwe}      
\fi
\end{document}

with mwe.bib:

@article{Aguirre2010,
    title={Title},
    author = {Aguirre},
    journal = {In Prep},
    year={2010}
}

If I compile this code with pdflatex sub2.tex && bibtex sub2, it gives me bibtex problems:

I found no \bibdata command---while reading file sub2.aux
I found no \bibstyle command---while reading file sub2.aux

If I uncomment \standalonetrue, it works.

The problem comes in if I have another document that imports this document. In order to compile this document, I need \standalonetrue in it. But the parent document (below), won't accept an imported document with \standalonetrue in it, as far as I can tell:

Illegal, another \bibstyle command---line 8 of file sub1.aux
 : \bibstyle
 :          {apj_w_etal}
I'm skipping whatever remains of this command
Illegal, another \bibdata command---line 9 of file sub1.aux
 : \bibdata
 :         {mwe}
I'm skipping whatever remains of this command

Here's the "parent" document (called sub1.tex)

\documentclass{aastex}
\usepackage{standalone}
\standalonetrue
\usepackage{import}
\usepackage{natbib}
\begin{document}
\chapter{Chapter of an Article}
This is an article that includes many subsections
\subimport{./}{sub2}
\ifstandalone
\bibliographystyle{apj_w_etal}
\bibliography{mwe}      
\fi
\end{document}
share|improve this question
    
Please don't use \input{preface} in MWEs. It defeats the purpose of a MWE because your preamble isn't shown. Note that I'm not 100% sure what you exactly mean with "uses standalone". You mean the class or the package? –  Martin Scharrer Mar 22 '13 at 20:29
    
I'm using the package, not the class. And I intentionally did not try to include a complete MWE - it would take too long at this point. –  keflavich Mar 22 '13 at 20:34
    
I still can't understand your exact use-case. There is nothing in your example for which you need standalone. –  Martin Scharrer Mar 22 '13 at 20:37
    
I've updated the example to create a genuine MWE now; I can't include a standalone inside another standalone because of 1-bibdata-per-file restrictions. –  keflavich Mar 25 '13 at 21:16
add comment

1 Answer

I'm the author of standalone. The \ifstandalone switch is defined automatically by both the package and the class, in different form, to indicate if a subfile is compiled stand-alone or as part of a main document. The switch is not designed to be modified by the user and I acutally have to look at the source code again to be able to tell which impact doing so would have. It's definitifly not a supported feature and so I wouldn't recommend it.

Note that you can include standlone documents inside another standalone documents, i.e. use the standalone package in a standalone class document. That is a supported feature. You don't need to change any switches for this. If you want to compile the subfiles by themselves simply use them as main documents.

The main document is not selected by any switches, but simply by you, i.e. with document you feed to your LaTeX compiler. It seems to me that you are using some graphical LaTeX develop environment/editor and don't specify there which document it should compile. This is a setting of this specific program and has nothing to do with the LaTeX code itself. If you tell us which program you are using people should be able to help you with it. I personally use the command line a lot.

share|improve this answer
    
I'm using the command line only... I think there must be some strange behavior going on, then. I'll try to construct a MWE. –  keflavich Mar 22 '13 at 20:37
    
I still don't really understand this answer. If I compile my –  keflavich Apr 18 '13 at 23:07
    
@keflavich: I had issues understanding your question as well. It looks to me that you misunderstood the function of the if-switch. Users are not supposed to use \standalonetrue by themselves. It is set by both the standalone class and package - to different settings - and is intended to be able to exclude or include code inside a subfile depending on whether it is compiled by itself or as part of a main document. –  Martin Scharrer Apr 19 '13 at 13:20
    
Thanks for that clarification, and sorry... I meant not to send that comment. My issue is, I can't get my bibliographies to include with \ifstandalone unless specifying it explicitly. I think the problem is having doubly-nested standalone files. –  keflavich Apr 19 '13 at 15:45
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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