summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/doc/latex/nameauth/examples.tex
blob: f7de75f8800eb68df630506c31bd22ac3b99ccb9 (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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
\documentclass{article}
\usepackage{verbatim}
\begin{document}
%% This is an example file used with the nameauth package.
%% See README and nameauth.pdf for copyright info.
%%

\section{Test for Latex Engine}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%     Test which LaTeX engine you are using
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{verbatim}
\ifdefined\Umathchar
  \usepackage{fontspec}
  \usepackage{polyglossia}
\else
  \usepackage[utf8]{inputenc}
  \usepackage[TS1,T1]{fontenc}
  \usepackage{babel}
\fi
% Below is optional; use only if your dvi viewer|\\
% crashes or becomes unresponsive with tikz.|\\
\usepackage{ifxetex}
\usepackage{ifluatex}
\usepackage{ifpdf}
\ifxetex
  \usepackage{tikz}
\else
  \ifpdf
    \usepackage{tikz}
  \fi
\fi
\end{verbatim}

\section{Use Different Latex Engines}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%     Allow for multiple LaTeX engines
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Requires \textsf{ifxetex}, \textsf{ifluatex}, and \textsf{ifpdf}.
\begin{verbatim}
\ifxetex
  xelatex %
\else
  \ifluatex
    \ifpdf
      lualatex in pdf mode %
    \else
      lualatex in dvi mode %
    \fi
  \else
    \ifpdf
      pdflatex %
    \else
      latex %
    \fi
  \fi
\fi
\end{verbatim}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%     Print the first use of a name in text and margin
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%
%% Below we print the argument both in the text and in a margin paragraph
%% unless we are in internal vertical mode.
%%
%% This macro is suitable to replace \NamesFormat and \FrontNamesFormat.
%%
\section{First Use in Margin: $\epsilon$-\TeX}
\begin{verbatim}
\renewcommand*\NamesFormat[1]%
{%
  #1%
  \unless\ifinner
    \marginpar{\raggedleft\scriptsize #1}%
  \fi
}
\end{verbatim}

\section{First Use in Margin: Historic \TeX}
\begin{verbatim}
\renewcommand*\NamesFormat[1]%
{%
  #1%
  \ifinner\else
    \marginpar{\raggedleft\scriptsize #1}%
  \fi
}
\end{verbatim}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%     Print a text tag after first name use
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%
%% Below we print the argument in the text and then we query the text tag
%% database to see if we can print a text tag after the argument.
%%
%% This macro is suitable to replace \NamesFormat and \FrontNamesFormat.
%%
\section{Text Tag With First Use: $\epsilon$-\TeX}
\begin{verbatim}
\newif\ifNoTag
\makeatletter
\renewcommand*\NamesFormat[1]{\begingroup%
  \protected@edef\temp{\endgroup\textbf{#1}%
  \unless\ifNoTag
    \if@nameauth@InName
      {\bfseries\noexpand\NameQueryInfo
      [\unexpanded\expandafter{\the\@nameauth@toksa}]
      {\unexpanded\expandafter{\the\@nameauth@toksb}}
      [\unexpanded\expandafter{\the\@nameauth@toksc}]}\fi
    \if@nameauth@InAKA
      \noexpand\NameQueryInfo
      [\unexpanded\expandafter{\the\@nameauth@toksa}]
      {\unexpanded\expandafter{\the\@nameauth@toksb}}
      [\unexpanded\expandafter{\the\@nameauth@toksc}]\fi
  \fi}\temp\global\NoTagfalse}
\makeatother
\end{verbatim}
\clearpage

\section{Text Tag With First Use: Historic \TeX}
\begin{verbatim}
\newif\ifNoTag
\makeatletter
\renewcommand*\NamesFormat[1]{%
  \let\ex\expandafter%
  #1%
  \if@nameauth@InName
    \ifNoTag
    \else
      \ex\ex\ex\ex\ex\ex\ex\NameQueryInfo\ex\ex\ex\ex\ex\ex\ex[%
        \ex\ex\ex\the\ex\ex\ex\@nameauth@toksa\ex\ex\ex]%
        \ex\ex\ex{\ex\the\ex\@nameauth@toksb\ex}\ex[\the\@nameauth@toksc]%
    \fi\fi
  \if@nameauth@InAKA
    \ifNoTag
    \else
      \ex\ex\ex\ex\ex\ex\ex\NameQueryInfo\ex\ex\ex\ex\ex\ex\ex[%
        \ex\ex\ex\the\ex\ex\ex\@nameauth@toksa\ex\ex\ex]%
        \ex\ex\ex{\ex\the\ex\@nameauth@toksb\ex}\ex[\the\@nameauth@toksc]%
    \fi\fi
  \global\NoTagfalse}
\makeatother
\end{verbatim}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%     Surname index entries in an fbox
%%     First surname instances in text are in an fbox
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%
%% We create a macro \Fbox that prints its argument in a framed
%% box when \@nameauth@DoAlt is true, or it just prints its argument.
%%
%%
\section{Formatting and Capping: New Style}
\begin{verbatim}
\makeatletter
\newcommand*\Fbox[1]{%
  \if@nameauth@DoAlt
    \fbox{#1}\else#1\fi
}
\makeatother

\renewcommand*\MainNameHook[1]{\NameOnly\NameParser}

\let\FrontNameHook\MainNameHook
\end{verbatim}
\clearpage

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%     Use both the arguments passed to the hooks
%%     and \NameParser under different conditions
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%
%% We redefine the hooks to print a name in the text and in
%% a margin paragraph. We change some of the internal flags
%% to make \NameParser print the name differently.
%%
%%
\section{Putting \texttt{\textbackslash NameParser} on Display}
\begin{verbatim}
\makeatletter
\renewcommand*\NamesFormat[1]{%
  #1\unless\ifinner
    \marginpar{\small\raggedleft%
               \@nameauth@FullNametrue%
               \@nameauth@FirstNamefalse%
               \@nameauth@EastFNfalse%
               \NameParser}%
  \fi}
\renewcommand*\MainNameHook[1]{%
  \AltOff#1\unless\ifinner
    \marginpar{\small\raggedleft%
               \@nameauth@FullNamefalse%
               \@nameauth@FirstNamefalse%
               \@nameauth@EastFNfalse%
               \NameParser}%
  \fi}
\makeatother
\end{verbatim}
\clearpage

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%     Surname index entries in an fbox
%%     First surname instances in text are in an fbox
%%     We can capitalize name within that formatting
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%
%% Below we create a Boolean value \ifFbox and set it true.
%% This will trigger an fbox
%%
%% We then create a macro \Fbox that prints its argument in 
%% an fbox when \ifFbox is true, or makes no change otherwise.
%%
%% The \AltCaps macro only capitalizies its argument inside the
%% formatting hook \NamesFormat below.
%%
%% \Namesformat ignores its argument, sets \InHooktrue, then
%% calls the name parser used specifically in formatting hooks.
%% \MainNameHook toggles \Fboxfalse to suppress formatting.
%%
%%
\section{Formatting and Capping: Old Style}
\begin{verbatim}
\newif\ifFbox
\newif\ifFirstCap
\newif\ifInHook
\Fboxtrue

\renewcommand*\Fbox[1]{%
  \ifFbox\fbox{#1}\else#1\fi
}

\renewcommand*\AltCaps[1]{%
  \ifInHook
    \ifFirstCap\MakeUppercase{#1}\else#1\fi
  \else
    #1%
  \fi
}

\renewcommand\CapThis{\FirstCaptrue}

\renewcommand*\NamesFormat[1]
{%
  \InHooktrue\NameParser\InHookfalse%
  \global\FirstCapfalse%
}

\renewcommand*\MainNameHook[1]
{%
  \Fboxfalse\InHooktrue\NameParser\InHookfalse%
  \global\FirstCapfalse\Fboxtrue%
}

\let\FrontNamesFormat\Namesformat
\let\FrontNameHook\MainNameHook
\end{verbatim}
\clearpage

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%     Migrate new style to old style
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%
%% This is the full example abbreviated in the manual.
%% Below we create a Boolean value \ifCaps and set it true.
%% This will trigger small caps.
%%
%% We then redefine \textSC to use our flag instead of package internals.
%% We redefine \AltCaps, \CapThis, and \NamesFormat in the same manner
%% as above. We change \MainNameHook to use our Caps flag.
%%
%%
\section{Migrating New Style to Old Style}
\begin{verbatim}
\newif\ifCaps
\newif\ifFirstCap
\newif\ifInHook
\Capstrue

\renewcommand*\textSC[1]{%
  \ifCaps\textsc{#1}\else#1\fi
}

\renewcommand*\AltCaps[1]{%
  \ifInHook
    \ifFirstCap\MakeUppercase{#1}\else#1\fi
  \else
    #1%
  \fi
}

\renewcommand\CapThis{\FirstCaptrue}

\renewcommand*\NamesFormat[1]
{%
  \InHooktrue\NameParser\InHookfalse%
  \global\FirstCapfalse%
}

\renewcommand*\MainNameHook[1]
{%
  \Capsfalse\InHooktrue\NameParser\InHookfalse%
  \global\FirstCapfalse\Capstrue%
}

\let\FrontNamesFormat\Namesformat
\let\FrontNameHook\MainNameHook
\end{verbatim}
\end{document}