1

I am working on a specifications file which should be used for multiple projects. Ideally what I would like to have is a generic latex file where I can enable project specific additions, but these additions would be different for each project. At the moment I am using \if statements, but this leads to very unreadable tex code. Ideally I would like to externalised these things into separate files. How would I achieve this?

Example:

%TEX program = xelatex
\documentclass[10pt,oneside,article]{memoir}
\title{Specs for Project}
\newif\ifprojectA
\projectAfalse
\newif\ifprojectB
\projectBfalse
\begin{document}
\chapter{The Chapter}
The font in this project used should be \ifprojectA Times New Roman
\else \ifprojectB Palatino \else
Helvetica \fi
\end{document}

So if none of the projects are defined, I get a default, but if I set one of the projects to true I get a specific project result. Instead of all of these \if and putting the specific text inside the \if I would like to be able to refer to an external page where I can insert the relevant text. Is this possible?

2 Answers2

2

You could use files with name projectAfile1.tex and projectBfile1.tex and then use

\projectinput{file1}

with the definition

\newcommand*\projectinput[1]{\input{project\ifprojectA A\else B\fi#1}}

Or, may be easier, have two folders projectA and projectB with files file1.tex inside both folders and then in the preamble

\makeatletter
\edef\input@path{{project\ifprojectA A\else B\fi/}}
\makeatother

and then use in the document

\input{file1} % or \include{file1}

which would be chosen depending on \ifprojectA. (I simplified the \if … fi but I think it's easy enough to get the idea.)

Manuel
  • 27,118
0

I think I have almost found a solution, based on the linked related section on this page: \input only part of a file. What I am doing now is to use the catchfilebetweentags package which allows me to include LaTex based on tags. This together with a short \newcommand lets me choose the text snippets I want to include. To optimise this, I only would like to get rid of having to need a default file, so that the text remains more readable.

So the solution looks for like this:

%TEX program = xelatex
\documentclass[10pt,oneside,article]{memoir}
\usepackage{catchfilebetweentags}
\title{Specs for Project}
\newif\ifprojectA
\projectAfalse
\newif\ifprojectB
\projectBfalse
\newcommand{\loadText}[1]{% define command
    \ifprojectA\ExecuteMetaData[ProjectA.tex]{#1}%
    \else\ifprojectB\ExecuteMetaData[ProjectB.tex]{#1}%
    \else\ExecuteMetaData[Default.tex]{#1}%
    \fi
}
\begin{document}
\chapter{The Chapter}
The default font for this project should be \loadText{font}.

\end{document}

I now have 3 tex files called ProjectA.tex, ProjectB.tex and Default.tex which will be used depending which project is active.

So Default.tex would look like:

%<*font>%
Helvetica%
%</font>

ProjectA.tex would be:

%<*font>
Palatino
%</font>

and so on.