If you to separate your preambles from the 'body' of their document, you might think this is a good idea: create a preamble (say, preamble.tex
) and their main file (say, main.tex
). For example,
% preamble.tex
\documentclass{article}
\usepackage{enumitem}
\newcommand\myname{XXXX YYYYY}
and then use it in:
% main.tex
\input{preamble}
\begin{document}
My name is \myname.
\end{document}
My advice is: do not do this. I understand the temptation to separate out the two 'parts', especially if it is a long document, etc. However, if you want to separate the parts, there is a better way to do it:
% main.tex
\documentclass{article}
\usepackage{enumitem}
\newcommand*{\myname}{XXXX YYYY}
% ... other preamble stuff
\begin{document}
\input{content}
% or \include{content}, though there are differences between the two;
% see: https://tex.stackexchange.com/q/246/8528
\end{document}
And then you do your 'writing' in content.tex
% content.tex
My name is \myname.
Note that you might have to 'flag' this as a subsidiary file and point it to the 'master'. Every editor probably does this differently. In Emacs it is easy. At the bottom of your file, you put:
%%% Local Variables:
%%% mode: latex
%%% TeX-master: "main"
%%% End:
(Really, only the %%% TeX-master: "main"
is doing the relevant work here.)
Although I cannot speak about ShareLaTeX, which I have never used, it is entirely possible that if it cannot see the line \documentclass
it will assume that it is not actually a file that can be processed by LaTeX. (This would be another reason to avoid the first method I described above and which I strongly encourage people to avoid.) Presumably the website allows you to mark 'main' and 'subsidiary' files in the way (e.g.) Emacs does, but I do not know how it does....
This method also allows you to rely on a common preamble. If you are going to do this, then it is best to name it with the .sty
extension and load it via \usepackage
. For more information on how to do this, see:
\input
-ed or the main file that has the\input
command in it? And I have to wonder whether Share LaTeX has a help section because I would imagine that many sophisticated editors -- even Emacs! -- wants you to set the 'main' document if you are going to compile from an included/subsidiary file.\input
command is in the document that the preamble will be imported. I don't know if I understood correct what you re saying so feel free to ask me to clarify further. This question is more about why in the first case I don't have to set a main document yet in the second I have.\input
command would have to be: but from which document are you compiling? I also suggest not using\input
in this way, but\usepackage
. The structure is\documentclass{article} \usepackage{mypreamble} \begin{document} text \end{document}
. If you are doing\input{mypreamble} \begin{document} text \end{document}
, then the best advice is: don't. If you are trying to compile from 'within'mypreamble
, then I'd assume you'd need to inform any reasonable editor that you are not in the 'main' document.\documentclass{article} \usepackage{mypreamble} \begin{document} \input{content} \end{document}
wherecontent.tex
is the file that contains the text that will be typeself. Again, however, I thinkcontent.tex
will (and should) have a flag marking which file is the 'master'.