summaryrefslogtreecommitdiff
path: root/info/examples/LaTeX-Referenz/06-05-23.ltx
blob: 42cd3848e2113e34f8fa5cac63be58c5ded3b564 (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
%% 
%%  Die DANTE-Edition
%%  Ein Beispiel der LaTeX Referenz
%%  3. Auflage
%% 
%% 
%%  Copyright (C) 2013 Herbert Voss
%% 
%%  It may be distributed and/or modified under the conditions
%%  of the LaTeX Project Public License, either version 1.3
%%  of this license or (at your option) any later version.
%% 
%%  See http://www.latex-project.org/lppl.txt for details.
%% 
%% 
%% ==== 
% Show page(s) 1
%% 
%% 
\documentclass[]{exaarticle}
\pagestyle{empty}
\setlength\textwidth{193.16928pt}
\setlength\parindent{0pt}
\usepackage{xtemplate,xparse}
\ExplSyntaxOn
\DeclareObjectType { names } { 2 }

% das Interface für das Template `fullname':
\DeclareTemplateInterface { names } { fullname } { 2 }
  {
    reversed           : boolean   = false ,
    use-last-name      : boolean   = true  ,
    use-first-name     : boolean   = true  ,
    last-name-format   : tokenlist         ,
    first-name-format  : tokenlist         ,
  }
% das Interface für das Template `initial':
\DeclareTemplateInterface { names } { initial } { 2 }
  {
    reversed           : boolean   = false ,
    use-last-name      : boolean   = true  ,
    use-first-name     : boolean   = true  ,
    last-name-format   : tokenlist         ,
    first-name-format  : tokenlist         ,
    last-name-initial  : boolean   = false ,
    first-name-initial : boolean   = true  ,
  }

% erst einmal die Variablen:
\bool_new:N \l_names_reversed_bool
\bool_new:N \l_names_use_last_bool
\bool_new:N \l_names_use_first_bool
\tl_new:N   \l_names_last_format_tl
\tl_new:N   \l_names_first_format_tl

% und dann der Template-Code:
\DeclareTemplateCode { names } { fullname } { 2 }
  {
    reversed           = \l_names_reversed_bool   ,
    use-last-name      = \l_names_use_last_bool   ,
    use-first-name     = \l_names_use_first_bool  ,
    last-name-format   = \l_names_last_format_tl  ,
    first-name-format  = \l_names_first_format_tl ,
  }
  {
    \AssignTemplateKeys
    \bool_if:NTF \l_names_reversed_bool
      {
        \bool_if:NT \l_names_use_last_bool
          { { \tl_use:N \l_names_last_format_tl #2 } }
        \bool_if:nT { \l_names_use_first_bool && \l_names_use_last_bool }
          { , ~ }
        \bool_if:NT \l_names_use_first_bool
          { { \tl_use:N \l_names_first_format_tl #1 } }
      }
      {
        \bool_if:NT \l_names_use_first_bool
          { { \tl_use:N \l_names_first_format_tl #1 } }
        \bool_if:nT { \l_names_use_first_bool && \l_names_use_last_bool }
          { \tl_use:N \c_space_tl }
        \bool_if:NT \l_names_use_last_bool
          { { \tl_use:N \l_names_last_format_tl #2 } }
      }
  }

% zwei weitere Variablen:
\bool_new:N \l_names_last_initial_bool
\bool_new:N \l_names_first_initial_bool

% Hilfsfunktion:
\cs_new:Npn \names_get_initial:w #1#2 \q_stop { #1 . }

% der Template-Code:
\DeclareTemplateCode { names } { initial } { 2 }
  {
    reversed           = \l_names_reversed_bool      ,
    use-last-name      = \l_names_use_last_bool      ,
    use-first-name     = \l_names_use_first_bool     ,
    last-name-format   = \l_names_last_format_tl     ,
    first-name-format  = \l_names_first_format_tl    ,
    last-name-initial  = \l_names_last_initial_bool  ,
    first-name-initial = \l_names_first_initial_bool ,
  }
  {
    \AssignTemplateKeys
    \bool_if:NTF \l_names_reversed_bool
      {
        \bool_if:NT \l_names_use_last_bool
          {
            \group_begin:
              \tl_use:N \l_names_last_format_tl
              \bool_if:NTF \l_names_last_initial_bool
                { \names_get_initial:w #2 \q_stop }
                { #2 }
            \group_end:
          }
        \bool_if:nT { \l_names_use_first_bool && \l_names_use_last_bool }
          { , ~ }
        \bool_if:NT \l_names_use_first_bool
          {
            \group_begin:
              \tl_use:N \l_names_first_format_tl
              \bool_if:NTF \l_names_first_initial_bool
                { \names_get_initial:w #1 \q_stop }
                { #1 }
            \group_end:
          }
      }
      {
        \bool_if:NT \l_names_use_first_bool
          {
            \group_begin:
              \tl_use:N \l_names_first_format_tl
              \bool_if:NTF \l_names_first_initial_bool
                { \names_get_initial:w #1 \q_stop }
                { #1 }
            \group_end:
          }
        \bool_if:nT { \l_names_use_first_bool && \l_names_use_last_bool }
          { \tl_use:N \c_space_tl }
        \bool_if:NT \l_names_use_last_bool
          {
            \group_begin:
              \tl_use:N \l_names_last_format_tl
              \bool_if:NTF \l_names_last_initial_bool
                { \names_get_initial:w #2 \q_stop }
                { #2 }
            \group_end:
          }
      }
  }

% ein paar Instanzen, erst mal mit dem Template `fullname':
\DeclareInstance { names } { standard } { fullname } {}
\DeclareInstance { names } { it-rev } { fullname }
  {
    first-name-format = \itshape ,
    reversed          = true
  }
\DeclareInstance { names } { first-only } { fullname }
  { use-last-name = false }
% und dann mit `initial':
\DeclareInstance { names } { init-first } { initial } {}
\DeclareInstance { names } { init-it-rev } { initial }
  {
    first-name-format = \itshape ,
    reversed          = true
  }
\DeclareInstance { names } { init-all } { initial }
  { last-name-initial = true }

% eine weitere Hilfsvariable:
\tl_new:N  \l_names_instance_tl
\tl_set:Nn \l_names_instance_tl { standard }

% der interne Befehl:
\cs_new:Npn \names_typeset_name:nnn #1#2#3
  {
    \IfInstanceExistTF { names } { #1 }
      { \UseInstance { names } { #1 } }
      { \UseInstance { names } { standard } }
    { #2 } { #3 }
  }
\cs_generate_variant:Nn \names_typeset_name:nnn { V }

% der Benutzerbefehl:
\DeclareDocumentCommand \name { o > { \SplitArgument { 1 } { ~ } } m }
  {
    \group_begin:
      \IfNoValueF { #1 } { \tl_set:Nn \l_names_instance_tl { #1 } }
      \names_typeset_name:Vnn \l_names_instance_tl #2
    \group_end:
  }
\ExplSyntaxOff
%StartShownPreambleCommands
\usepackage{xtemplate,xparse}
\usepackage[T1]{fontenc}
\usepackage{libertine}
\usepackage[utf8]{inputenc}
%StopShownPreambleCommands
\begin{document}
\name{Herbert Voß} \\
\name[it-rev]{Herbert Voß} \\
\name[first-only]{Herbert Voß} \\
\name[init-first]{Herbert Voß} \\
\name[init-it-rev]{Herbert Voß} \\
\name[init-all]{Herbert Voß}
\end{document}