solved: latex with multiple source files

502 views
Skip to first unread message

Harald Schilly

unread,
Nov 4, 2013, 4:07:09 PM11/4/13
to sage-...@googlegroups.com
SMC's LaTeX editor doesn't work with multiple files. I searched a bit
around and found a package I've never heard of: "subfiles". It seems
to be pretty new, too.

What it does is the following: you create a master document, which
references sub-documents, and the sub-documents reference the master
document for the overall style. That's all. Then you can render
everything or just a part of it at the same time.
I hope this is helpful for some of you!
http://ctan.org/tex-archive/macros/latex/contrib/subfiles

In example below pay attention, how the scrartcl class is propagated
to both child documents!

@William: what's missing is the obvious: trigger a recompile of the
master document, if one of the child documents change - and vice
versa, recompile a child, if the master document changes (which might
have an impact on the styling of the child).

Example:

main.tex

\documentclass[a4paper]{scrartcl}
\usepackage{subfiles}
\begin{document}
This is the main part
\subfile{chapter1}
\subfile{chapter2}
\end{document}

chapter1.tex

\documentclass[main.tex]{subfiles}
\begin{document}
\section{Section 1}
This is section 1 speaking!
\end{document}

chapter2.tex

\documentclass[main.tex]{subfiles}
\begin{document}
\section{Section 2}
... and this is section 2.
\end{document}

Christian Stump

unread,
Nov 6, 2013, 7:13:34 AM11/6/13
to sage-...@googlegroups.com
> SMC's LaTeX editor doesn't work with multiple files. I searched a bit  around and found a package I've never heard of: "subfiles". It seems to be pretty new, too.

I was also looking for a solution to this problem this morning, thanks for sharing!


@William
> what's missing is the obvious: trigger a recompile of the master document, if one of the child documents change - and vice versa, recompile a child, if the master document changes (which might have an impact on the styling of the child).

The main advantage of this package is that you can compile sections individually. This is nice sometimes, especially when working on large documents. On the other hand, the average user might prefer to use a simpler solution, that she is maybe even used to use. I would suggest the following:

* I would vote for a "standard solution" that uses the preamble " %!TEX root=Master.tex " and on saving/compiling the master file gets compiled and shown on the right split screen.

* Using Harald's package idea, there could be a switch, maybe that's what he meant anyway, that you can either view only the section (as it is currently), or you can switch view the complete document. The later raises the question: what about forward and inverse search?

Cheers, Christian

Harald Schilly

unread,
Nov 6, 2013, 7:25:17 AM11/6/13
to sage-...@googlegroups.com
On Wed, Nov 6, 2013 at 1:13 PM, Christian Stump
<christi...@gmail.com> wrote:
> I was also looking for a solution to this problem this morning, thanks for
> sharing!

Glad someone found it useful ;-)

I think it's quite hard to add enough magic to all this to get
multiple documents working in whatever way you want. I am happy with a
simpler solution, that works consistently and is not maintained by SMC
only - i.e. the mentioned package would fit this.
About your second point: yes, I could envision a dropdown, where you
can select the whole view or just a part. I don't know if syncing back
and forward searches would work at all, though.

Harald

Christian Stump

unread,
Nov 6, 2013, 7:45:25 AM11/6/13
to sage-...@googlegroups.com
I think it's quite hard to add enough magic to all this to get
multiple documents working in whatever way you want. I am happy with a
simpler solution, that works consistently and is not maintained by SMC
only - i.e. the mentioned package would fit this.

what is wrong with the more elementary solution using " % !TEX root = " at the beginning of the document ? See e.g. http://tex.stackexchange.com/questions/39207/how-can-i-compile-different-tex-file-on-click-on-typeset-in-texshop-mactex-20 for people proposing this solution that is quite common among latex users. I mainly like this better (though it is less powerful) because it has been used a lot. Also "kile" is using a master document solution in which the child files do not have a document class or a begin/end document.

For me personally, the other solution would be okay as well. But

* it is less intuitive for newbies, and
* it appears that the subfiles package does not interact with bibtex. This way, my document is full of ??? when working

Finally, I think that there should be a way of forward and inverse search jumping into the right file in both solutions.

Cheers, Christian

David Perkinson

unread,
Jun 10, 2014, 2:11:36 PM6/10/14
to sage-...@googlegroups.com
With vim-latex, you can add 

let g:Tex_MultipleCompileFormats = 'dvi, pdf'

to your .vimrc, then, if your main file is main.tex, add an empty file called main.tex.latexmain in the same directory.  You can then just compile a subfile, and everything works, including possible multiple compiles for new labels and citations:

Reply all
Reply to author
Forward
0 new messages