| 1 |
%% pig.dtx |
| 2 |
%% Copyright 2022 Jason Siefken |
| 3 |
% |
| 4 |
% This work may be distributed and/or modified under the |
| 5 |
% conditions of the LaTeX Project Public License, either version 1.3 |
| 6 |
% of this license or (at your option) any later version. |
| 7 |
% The latest version of this license is in |
| 8 |
% http://www.latex-project.org/lppl.txt |
| 9 |
% and version 1.3 or later is part of all distributions of LaTeX |
| 10 |
% version 2005/12/01 or later. |
| 11 |
% |
| 12 |
% This work has the LPPL maintenance status `maintained'. |
| 13 |
% |
| 14 |
% The Current Maintainer of this work is Jason Siefken |
| 15 |
% |
| 16 |
% This work consists of the files jobname-suffix.sty and docs/jobname-suffix.tex |
| 17 |
\documentclass{l3doc} |
| 18 |
\usepackage{listings,xcolor} |
| 19 |
|
| 20 |
\lstdefinestyle{mystyle}{ |
| 21 |
language=[LaTeX]{TeX}, |
| 22 |
texcsstyle=*\color{blue}, |
| 23 |
commentstyle={\color{green!50!black}\itshape}, |
| 24 |
basicstyle=\ttfamily, |
| 25 |
moretexcs={IfSuffixT,IfSuffixF,IfSuffixTF,OverrideSuffix,JobnameSuffix,solution}, % user command highlight |
| 26 |
frame=single, |
| 27 |
} |
| 28 |
\lstset{style=mystyle} |
| 29 |
|
| 30 |
\title{% |
| 31 |
\pkg{jobname-suffix}\\ |
| 32 |
Compile different content based on the file name% |
| 33 |
} |
| 34 |
|
| 35 |
\author{% |
| 36 |
Jason Siefken% |
| 37 |
\thanks{% |
| 38 |
Please file an issues/comments to \url{https://github.com/siefkenj/jobname-suffix/issues} |
| 39 |
} |
| 40 |
} |
| 41 |
|
| 42 |
\date{Released \today} |
| 43 |
|
| 44 |
\NewDocumentCommand{\fileshow}{m}{% |
| 45 |
\par |
| 46 |
\noindent\begin{minipage}{\linewidth} |
| 47 |
\noindent\texttt{\itshape #1:} |
| 48 |
\vspace{-1cm} |
| 49 |
\end{minipage} |
| 50 |
} |
| 51 |
|
| 52 |
\begin{document} |
| 53 |
\maketitle |
| 54 |
|
| 55 |
\tableofcontents |
| 56 |
|
| 57 |
\begin{abstract} |
| 58 |
\pkg{jobname-suffix} allows one to compile a document differently depending |
| 59 |
on the document's file name (internally called the \texttt{jobname} in \TeX). |
| 60 |
This allows one to have one source file and multiple links to this source file (either |
| 61 |
as symbolic links, or as different files referencing the original via an \cs{input} |
| 62 |
command) that are each compile differently. For example, an exam might have an |
| 63 |
\file{exam-student.tex} and an \file{exam-instructor.tex} which both reference the |
| 64 |
same source code but where the instructor version includes solutions and the student |
| 65 |
version does not. |
| 66 |
\end{abstract} |
| 67 |
|
| 68 |
\begin{documentation} |
| 69 |
|
| 70 |
\section{Introduction} |
| 71 |
\pkg{jobname-suffix} by default allows you to reference the part of a file name (technically the \cs{jobname}) |
| 72 |
that comes after the first ``\texttt{-}'' character and use that information to control what \LaTeX{} produces. |
| 73 |
|
| 74 |
Consider the following example: you have three files \file{exam.tex}, \file{exam-student.tex}, and \file{exam-instructor.tex}. |
| 75 |
The files \file{exam-student.tex} and \file{exam-instructor.tex} are either symbolic links to \file{exam.tex} (if your operating |
| 76 |
system supports symbolic links) or use \cs{input}\Arg{exam.tex file path} to include the contents of \file{exam.tex}. |
| 77 |
|
| 78 |
\fileshow{exam-student.tex \textnormal{and} exam-instructor.tex} |
| 79 |
\begin{lstlisting} |
| 80 |
\input{exam.tex} |
| 81 |
\end{lstlisting} |
| 82 |
|
| 83 |
\fileshow{exam.tex} |
| 84 |
\begin{lstlisting} |
| 85 |
\documentclass{article} |
| 86 |
\usepackage{jobname-suffix} |
| 87 |
|
| 88 |
\newcommand{\solution}[1]{#1} |
| 89 |
\IfSuffixT[instructor]{ |
| 90 |
% Instructors get solutions emboldened |
| 91 |
\renewcommand{\solution}[1]{\textbf{#1}} |
| 92 |
} |
| 93 |
\IfSuffixT[student]{ |
| 94 |
% Students don't see solutions at all |
| 95 |
\renewcommand{\solution}[1]{} |
| 96 |
} |
| 97 |
|
| 98 |
\begin{document} |
| 99 |
\begin{enumerate} |
| 100 |
\item First question |
| 101 |
\solution{First answer} |
| 102 |
|
| 103 |
\item Second question |
| 104 |
\solution{Second answer} |
| 105 |
\end{enumerate} |
| 106 |
\end{document} |
| 107 |
\end{lstlisting} |
| 108 |
|
| 109 |
\noindent Then, compiling via |
| 110 |
|
| 111 |
\noindent\texttt{> lualatex exam-instructor.tex} |
| 112 |
|
| 113 |
\noindent\texttt{> lualatex exam-student.tex} |
| 114 |
|
| 115 |
\noindent will produce two pdfs: one with solutions and one without. |
| 116 |
|
| 117 |
\section{Usage} |
| 118 |
\subsection{Variables} |
| 119 |
|
| 120 |
\begin{variable}{\JobnameSuffix} |
| 121 |
The computed suffix of the filename (\cs{jobname}). This is normally the part of the file name after the first ``\texttt{-}'' |
| 122 |
character and before the file extension. For example, |
| 123 |
\file{file-a.tex} has a \cs{JobnameSuffix} of ``\texttt{a}'', |
| 124 |
\file{file-a-b.tex} has a \cs{JobnameSuffix} of ``\texttt{a-b}'', |
| 125 |
and \file{file.tex} has a \cs{JobnameSuffix} of consisting of the empty string. |
| 126 |
\end{variable} |
| 127 |
|
| 128 |
\subsection{Commands} |
| 129 |
\begin{function}{\IfSuffixTF, \IfSuffixT, \IfSuffixF} |
| 130 |
\begin{syntax} |
| 131 |
\cs{IfSuffixTF}\oarg{suffixes}\marg{true condition}\marg{false condition} |
| 132 |
\cs{IfSuffixT}\oarg{suffixes}\marg{true condition} |
| 133 |
\cs{IfSuffixF}\oarg{suffixes}\marg{false condition} |
| 134 |
\end{syntax} |
| 135 |
The argument \meta{suffixes} is a comma-separated list of all suffixes you wish to test against. |
| 136 |
\end{function} |
| 137 |
|
| 138 |
\begin{function}{\OverrideSuffix} |
| 139 |
\begin{syntax} |
| 140 |
\cs{OverrideSuffix}\marg{suffix} |
| 141 |
\end{syntax} |
| 142 |
Override \cs{JobnameSuffix} to be the suffix specified by \meta{suffix} instead. |
| 143 |
\end{function} |
| 144 |
|
| 145 |
\subsection{Environments} |
| 146 |
|
| 147 |
\DescribeEnv{IfSuffix} |
| 148 |
The \env{IfSuffix} environment accepts an optional argument \oarg{suffixes} and will display its contents (unmodified) |
| 149 |
if \cs{JobnameSuffix} is among the comma-separated list \meta{suffixes}. Unfortunately this environment cannot contain |
| 150 |
\env{verbatim} contents. |
| 151 |
|
| 152 |
\section{Compiling} |
| 153 |
|
| 154 |
\pkg{jobname-suffix} works by reading the \cs{jobname} macro that is part of standard \TeX. By default, this is |
| 155 |
set to the file name without the file extension. You can affect the jobname in one of two ways: |
| 156 |
\begin{enumerate} |
| 157 |
\item The name of your file. |
| 158 |
\item By supplying the \texttt{-jobname} option during compilation. For example, the following two |
| 159 |
commands would both result in compiling with a \cs{jobname} of \texttt{exam-student}. |
| 160 |
|
| 161 |
\noindent\texttt{> lualatex -jobname exam-instructor exam.tex} |
| 162 |
|
| 163 |
\noindent\texttt{> lualatex exam-instructor.tex} |
| 164 |
\end{enumerate} |
| 165 |
|
| 166 |
\section{Tips} |
| 167 |
|
| 168 |
\begin{itemize} |
| 169 |
\item |
| 170 |
For performance reasons, it is best to \cs{IfSuffixTF} to define/redefine commands in your document preamble |
| 171 |
rather than to use them in your document body/macro bodies. For example, do |
| 172 |
|
| 173 |
\begin{lstlisting} |
| 174 |
\documentclass{article} |
| 175 |
\usepackage{jobname-suffix} |
| 176 |
|
| 177 |
\newcommand{\solution}[1]{#1} |
| 178 |
\IfSuffixT[instructor]{ |
| 179 |
% Instructors get solutions emboldened |
| 180 |
\renewcommand{\solution}[1]{\textbf{#1}} |
| 181 |
} |
| 182 |
|
| 183 |
\begin{document} |
| 184 |
\solution{Some Text} |
| 185 |
\end{document} |
| 186 |
\end{lstlisting} |
| 187 |
|
| 188 |
instead of |
| 189 |
|
| 190 |
\begin{lstlisting} |
| 191 |
\documentclass{article} |
| 192 |
\usepackage{jobname-suffix} |
| 193 |
|
| 194 |
\newcommand{\solution}[1]{% |
| 195 |
\IfSuffixTF[instructor]{% |
| 196 |
% Instructors get solutions emboldened |
| 197 |
\textbf{#1}% |
| 198 |
}{% |
| 199 |
#1% |
| 200 |
} |
| 201 |
} |
| 202 |
|
| 203 |
\begin{document} |
| 204 |
\solution{Some Text} |
| 205 |
\end{document} |
| 206 |
\end{lstlisting} |
| 207 |
|
| 208 |
\item |
| 209 |
To match the case when you have ``no suffix'' (i.e., when the suffix is the empty string because ``\texttt{-}'' did not appear in |
| 210 |
the filename), use \cs{IfSuffix[]} with an empty argument list\footnote{ |
| 211 |
If you omit the optional argument, \cs{IfSuffixT} will never be true (not even if \cs{JobnameSuffix} is the empty string). |
| 212 |
}. |
| 213 |
\end{itemize} |
| 214 |
|
| 215 |
|
| 216 |
\section{Installation} |
| 217 |
|
| 218 |
For manual installation, the package is available from |
| 219 |
\href{http://ctan.org/pkg/jobname-suffix}{{CTAN}}. |
| 220 |
|
| 221 |
The package requires \LaTeX3 support as provided in the \pkg{l3kernel} and |
| 222 |
\pkg{l3packages} bundles. Both of these are included in \TeX{} Live and |
| 223 |
MiK\TeX{}, or are again available in ready-to-install form from {CTAN}. |
| 224 |
|
| 225 |
\end{documentation} |
| 226 |
|
| 227 |
|
| 228 |
\PrintIndex |
| 229 |
\end{document} |