summaryrefslogtreecommitdiff
path: root/macros/latex/contrib/varsfromjobname/varsfromjobname.tex
blob: 55516a138ad17610d1f8c090cbfc46fd20163f3b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
\documentclass[12pt]{article}
\usepackage{listings}
\nofiles

\usepackage{varsfromjobname}
\usepackage[default]{sourcesanspro}
\setlength{\parskip}{1em}
\setlength{\parindent}{0em}
\usepackage[left=3cm, right=3cm, top=3cm, bottom=3cm]{geometry}


\date{May 1st 2016}
\author{Uwe Ziegenhagen, ziegenhagen@gmail.com}
\title{\texttt{varsfromjobname} Description}



\begin{document}
\maketitle

\noindent Using \texttt{varsfromjobname.sty} one can easily extract information from the filename, if it follows a certain form. The LaTeX command \verb|\|jobname returns the name of the LaTeX file. 

If the filename consists of tokens separated by hyphen we can easily extract certain tokens that can be used inside the document. 

The package expects the filename to be of the form 

\noindent\texttt{one-two-three-four-five-six-seven-eight-nine.tex} 

\noindent and offers the following commands:

\begin{itemize}
	\item \verb|\getfromjobname|\{\textit{param}\}, with \textit{param} in the
	 range of 1 to 9 (highlevel interface to the following commands)
	\item \verb|\getonefromjobname|
	\item \verb|\gettwofromjobname|
	\item \verb|\getthreefromjobname|
	\item \verb|\getfourfromjobname|
	\item \verb|\getfivefromjobname|
	\item \verb|\getsixfromjobname|
	\item \verb|\getsevenfromjobname|
	\item \verb|\geteightfromjobname|
	\item \verb|\getninefromjobname|	
\end{itemize}

For included documents the package uses the \texttt{currfile} package to provide the following commands: 

\begin{itemize}
	\item \verb|\getfromcurrfilename|\{\textit{param}\}, with \textit{param} in the
	 range of 1 to 9 (highlevel interface to the following commands)
	\item \verb|\getonefromcurrfilename|
	\item \verb|\gettwofromcurrfilename|
	\item \verb|\getthreefromcurrfilename|
	\item \verb|\getfourfromcurrfilename|
	\item \verb|\getfivefromcurrfilename|
	\item \verb|\getsixfromcurrfilename|
	\item \verb|\getsevenfromcurrfilename|
	\item \verb|\geteightfromcurrfilename|
	\item \verb|\getninefromcurrfilename|	
\end{itemize}

\section*{Example}

Place the code from Listing 1 in a file \textbf{a-b-c-d-e-f-g-h-i-j.tex} and the code from
 Listing~2 in a file named \textbf{z-y-x-w-v-u-t-s-r-q.tex}. Then compile the first file with pdflatex.

\begin{lstlisting}[caption={\textbf{a-b-c-d-e-f-g-h-i-j.tex}}]
% testfiles for varsfromjobname.sty
\documentclass{article}
\listfiles
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{varsfromjobname}
\begin{document}

a: \getonefromjobname % a

b: \gettwofromjobname % b

c: \getthreefromjobname % c

d: \getfourfromjobname % d

e: \getfivefromjobname % e

f: \getsixfromjobname % f 

g: \getsevenfromjobname % g

h: \geteightfromjobname %h 

i-j: \getninefromjobname % i-j

a: \getfromjobname{1} % a

b: \getfromjobname{2} % b 

c: \getfromjobname{3} % c

d: \getfromjobname{4} % d

e: \getfromjobname{5} % e

f: \getfromjobname{6} % f

g: \getfromjobname{7} % g 

h: \getfromjobname{8} % h

i-j: \getfromjobname{9} % i-j

\input{z-y-x-w-v-u-t-s-r-q}

\end{document}
\end{lstlisting}




\begin{lstlisting}[caption={\textbf{z-y-x-w-v-u-t-s-r-q.tex}}]
z: \getonefromcurrfilename

y: \gettwofromcurrfilename

x: \getthreefromcurrfilename

w: \getfourfromcurrfilename

v: \getfivefromcurrfilename

u: \getsixfromcurrfilename

t: \getsevenfromcurrfilename

s: \geteightfromcurrfilename

r-q: \getninefromcurrfilename
\end{lstlisting}


\section*{Change History}

\begin{description}
	\item [Version 0.5] as of January 11th 2009: Initial version published
	\item [Version 1.0] published May 2017:
        Added various commands which extract necessary information also from included documents
        Modified code as suggested by egreg
\end{description}

    
\vfill 2017-05-01, Uwe Ziegenhagen

\end{document}