Can we store a latex preamble into another file to avoid writing all same stuff in another file.If we can then can we change the title in another Tex file?
-
Yes, it is possible but this is generally a bad idea. Such a shared preamble tends to grow in complexity over time such that older documents don't compile with the newer version anymore. Also loading a huge bunch of unnecessary packages will make document compilation horribly slow.– Henri MenkeJul 6, 2020 at 4:18
-
Does this answer your question? Is it possible to create a LaTeX preamble "header"?– AndréCJul 6, 2020 at 4:56
-
Yes but Partially sir. Suppose I have define title in that file and I want to change title in every Tex document so can I do this– sachin rawatJul 6, 2020 at 5:32
-
I mean the title work as a function– sachin rawatJul 6, 2020 at 5:35
-
Just remove that title from the shared preamble file and place it into each individual file's preamble.– leandriisJul 6, 2020 at 6:06
1 Answer
Yes. Write your preamble in a tex file, lets say, preamble.tex
In the main file, where you want to add the preamble, just use
\input{preamble.tex}
This is in general, a bad idea though. I hope you have a good justification of using it in this way though.
-
2why is it a bad idea? also it is more idiomatic latex to save it as
something.sty
and then use\usepackage
rather than\input
to input it. Jul 6, 2020 at 8:52 -
"Can we store a latex preamble into another file to avoid writing all same stuff in another file.If we can then can we change the title in another Tex file" From the question, it felt like Sachin wants to use the same preamble including information like Title in multiple files. If not maintained correctly, it might be changed to accommodate something in one document, but the same changes might behave differently in another document. It's very easy to mess up when using the same preamble with document-specific information in multiple documents. Jul 6, 2020 at 18:43