I want to make a template where I can modify one .tex file and have it pull various ''boilerplate'' (i.e., information that doesn't change) from a network. Firstly, I would have some .tex where the User will copy/paste into a new folder and then specify some stuff:

%% User Data
hello world!

%% Initialize document
\input{boilerplate/Preamble} %<----This folder would be located like C://User/etc,...

Then, I would have the Preamble pulled from within the Template folder, as well as, the remaining information:

%% Select class

%% Packages
colorlinks=true,% hyperlinks will be coloured
citecolor=blue, % hyperlink text will be blue  
linkcolor=blue,% hyperlink text will be blue
linkbordercolor=blue,% hyperlink border will be blue
breaklinks = true,

%% Begin Document
\input{boilerplate/Introduction} % Need path
\input{boilerplate/DetailedEquipmentInformationandRequirements} % Need path
\input{boilerplate/ProductInformation} % Need path
\input{boilerplate/SupplierScopeofWork} % Need path
\include{boilerplate/Appendices} % Need path

The folder structure I envision would be:

Project 1
-Compiler 1 .tex file
-Image Folder
Project 2
-Compiler 2 .tex file
-Image Folder

As you can see, I would need to call the Preamble and then call in various in data that are not in the same folder. Does anyone know an easy way to call in these information or perhaps a better management system?

  • TeX etc. is no CMS, unfortunately – user31729 Apr 14 '17 at 23:52
  • I don't really understand the question. How can it pull in files from boilerplate/ when boilerplate/ doesn't exist? – cfr Apr 15 '17 at 0:41
  • @cfr I modified the original post; boilerplate is a folder with the .tex files. – Bryan Manning Apr 15 '17 at 9:02
  • how is this going to be a good idea? – Moriambar Apr 15 '17 at 9:07

This sounds like a new local package or class, with auxiliary files.

First, create a directory, say mytemplate, either in your personal local texmf tree if you will be the only user, or in the site-wide local texmf tree, or distribute the final template as a zip-archive with instructions how people have to install it on their PC (in their personal or in the site-wide texmf-tree). In my case, under Linux, I'd create the mytemplate directory either as

$(kpsewhich -var TEXMFHOME)/texmf/tex/latex/mytemplate

or for site-wide access as

$(kpsewhich -var TEXMFLOCAL)/tex/latex/mytemplate

Whatever you put into these folders will then be found without requiring an explicit path. Note that the site-wide local directory is usually indexed, so you have to rebuild the index after adding files to the directory. Under Linux, I call texhash as root (admin).

The common preamble and document settings become a style file mytemplate.sty or, if you need control over the document class loaded, a class file mytemplate.cls. You then start the specific documents with \documentclass{mytemplate} (refers to mytemplate.cls) or with \documentclass{anyclass}\usepackage{mytemplate} (refers to mytemplate.sty).

Particular user data can be collected using commands that store it for later use or as parameters to commands that immediately process it. For the first approach, use LaTeX's \author command as a model:

\newcommand\@data{} % if it is ok that no data is provided
% or alternatively
\newcommand\@data{\@latex@warning@no@line{No \noexpand\data given}} % gives a warning if the data is needed but has not provided
\newcommand\data[1]{\renewcommand\@data{#1}} % Store the argument under the name `\@data`

If the document contains \data{42}, then you can later access the value in your style or class file as \@data.

In the second approach the document calls a macro \processdata{42} and the data is immediately processed.

Regarding the text fragments, you can provide them as direct TeX code to be included. The document then has a line


If myintroduction.tex is located in the texmf-tree, it will be found without having to give the full path. Alternatively, your mytemplate.cls or mytemplate.sty can provide a command \Introduction (maybe with some parameters) that does some specific things and either contains the intro text verbatim or uses an \input statement itself.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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