summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/latex/dlfltxb/dlfltxbmarkup.sty
blob: a94d4e30118fb20ed499038e6b108c3617e9dd8b (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
\ProvidesPackage{dlfltxbmarkup}[2008/08/05 v0.70 by daleif]

% This package 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.
%% The latest version of this license is in
%%   http://www.latex-project.org/lppl.txt
%% and version 1.3 or later is part of all distributions of LaTeX
%% version 2003/12/01 or later.
%% 
%% This work has the LPPL maintenance status "maintained".
%% 
%% The Current Maintainer of this work is Lars Madsen (daleif@imf.au.dk).
%%



\@ifclassloaded{memoir}{}{%
  \PackageError{felinemarkup}{This package depends on several internal
    components of the memoir class and therefore need the memoir
    class}{Use the memoir class}
}



\RequirePackage{keyval}
\RequirePackage{ragged2e}


\DeclareOption{loadsampleconfig}{\AtEndOfPackage{
    %\InputIfFileExists{dlfltxbmarkup-sample.cfg}{}{}
    \IfFileExists{dlfltxbmarkupbookkeys.sty}{
      \RequirePackage{dlfltxbmarkupbookkeys}
    }{
      \PackageError{dlfltxbmarkup}{Sample configuration package
        'dlfltxbmarkupbookkeys' not found, option 'loadsampleconfig'
        is useless.}{}
    }
}}

\ProcessOptions\relax



% HISTORY
% <2007      this package dates back to at least 2004
% 2007/03/20 added \color{black} to the margin writing devices, since
%            color at a line boundary may extend out into the margin
% 2007/03/21 added inputenc keyword
% 2007/03/21 added counter keyword
% 2007/03/21 added length keyword
% 2007/03/22 added gauss keyword
% 2007/03/23 added tabs keyword
% 2007/03/23 added nbop keyword
% 2007/03/24 fixed a bug in tabs
% 2007/03/24 fixed loads more index errors
% 2007/04/27 added \hspace{0pt} to \MarkWMargin to activate automatic hyphenation
% 2007/04/30 added \feline@MWM@inner to get better source re-use
% 2007/05/05 fixed a margin placement problem by adding \leavevmode
%            in front of \checkoddpage in \feline@MWM@inner, fix
%            supplied by Peter Wilson, after I submitted a bug report
%            about it.
% 2007/05/10 started adding support for key explanations, planning to
%            make it possible to print a generated overview of the
%            regisered keys
% 2007/05/14 all keys for my book project have now been moved to
%            felinemarkup.cfg, which wil be loaded at the end of the
%            package, if the 'loadfelinemarkupconfig' package option
%            is given
% 2007/05/15 \feline@index@cmd renamed to \felineIndexCmd
% 2007/05/16 package renamed to dlfltxbmarkup
% 2008/01/10 added a strut inside the macro that writes in the margin, 
% 2008/10/30 'sample configuration' has been renamed



% this boolean is meant to be used for example inside constructions
% that will not permit the use of \marginpar, for example the
% environments 'framed' and 'shaded', then \MarkWMargin will use
% \sidepar instead of \marginpar

\@ifundefined{ifNoMarginparAvail}{%
  \newif\ifNoMarginparAvail
  \NoMarginparAvailfalse
}{}


\newcommand\felineMarginAdjustment{%
  \ifoddpage\RaggedRight\else\RaggedLeft\fi}


% typesets the material in the margin
% we use \checkoddpage (assuming the use of \strictpagechecktrue) to
% perform a rigid test on whether or not we are on an odd page
% \RaggedRight \RaggedLeft is used to get the test 'mashed' up against
% the text, and to permit hyphenation. If the material in #1 is using
% typewriter font, then it is #1's responsability to ensure that
% hyphenation is possible in that font
\newcommand\feline@MWM@inner[1]{%
  \parbox[t]{\marginparwidth}{%
    \leavevmode\checkoddpage% needs \leavevmode since \checkoddpage
                            % leaves a whatsit
%    \ifoddpage\RaggedRight\else\RaggedLeft\fi%
    \felineMarginAdjustment%
    {\slshape\scriptsize\strut\hspace{0pt}\color{black} #1\strut\par}}}

% this might not belong here, but we will leave it for now
\strictpagechecktrue%
\reversesideparfalse%

% the main macro to write in the margin with
\newcommand\felineWriteInMargin[1]{%
  \ifNoMarginparAvail%
    \sidepar{\feline@MWM@inner{#1}}%
  \else%
    \if@feline@forcesidepar%
      \sidepar{\feline@MWM@inner{#1}}%
    \else%
      \marginpar{\feline@MWM@inner{#1}}%
    \fi%
  \fi%
}%


% because of a possible babel use, and its active charecters (in
% danish, " is an active character, it seems that we cannot directly
% add automatic english hyphenation to \cs and \css, in most cases it
% can be added by hand to the macros specified in \FelineKeyGenerator
% see felinemarkup.cfg
\DeclareRobustCommand\cs[1]{%
  \textnormal{\texttt{\symbol{'134}#1}}}

\@ifpackagewith{babel}{english}{
  \DeclareRobustCommand\css[1]{%
    \textnormal{\texttt{%
        \protect\makebox[0pt][r]{\symbol{'134}}%
        \foreignlanguage{english}{\cs{\hyphenchar\font=`\-#1}}}}}
}{
  \DeclareRobustCommand\css[1]{%
    \textnormal{\texttt{%
        \protect\makebox[0pt][r]{\symbol{'134}}%
        {#1}}}}
}

% indexing commands, first just two alias macros
\newcommand\textitindex[1]{\textit{#1}}
\newcommand\textbfindex[1]{\textbf{#1}}
% then two different indexing macros, one for italic index entries and
% one for bold. we use them like this to avoid expansion problems (or
% at least try to)
\newcommand\itindex[1]{\index{#1|textitindex}}
\newcommand\bfindex[1]{\index{#1|textbfindex}}
% default indexing command, we change this using the idxit, idxbf keys
\newcommand\felineIndexCmd{\index}


% ---------------------------------------------------------------------------



% just initial definitions
\newcommand*\feline@margin[1]{\par margin: #1\par}
\newcommand*\feline@index[1]{\par index: #1\par}
\newcommand*\feline@text[1]{\par text: #1\par}

% just a shortcut, amsmath makes the same one
\let\@xp\expandafter

\define@key{FelineIndex}{empty}[]{%
  \renewcommand*\feline@margin[1]{\par margin: ##1\par}%
  \renewcommand*\feline@index[1]{\par index: ##1\par}%
  \renewcommand*\feline@text[1]{\par text: ##1\par}%
}

% whether or not to write the text part
\newif\if@feline@txt  \@feline@txttrue
% whether or not to write in the margin
\newif\if@feline@mrgn \@feline@mrgntrue
% whether or not to add to the index
\newif\if@feline@idx  \@feline@idxtrue
% force the use of sidepar instead of the usual marginpar
\newif\if@feline@forcesidepar
% whether or not to let \markup add a \hspace{0pt} in the text
% don't know it this is still needed
\newif\if@feline@hsp

% basically stolen from another package
\newcommand*\dlf@M@setbool[2]{%
  \csname #2\ifx\relax#1\relax true \else #1\fi\endcsname}

% switch off keys
\define@key{FelineIndex}{notxt} []{\@feline@txtfalse}  % = nowr
\define@key{FelineIndex}{nowr}  []{\@feline@txtfalse}  % no writing in text
\define@key{FelineIndex}{nomk}  []{\@feline@mrgnfalse} % no mark in margin
\define@key{FelineIndex}{noidx} []{\@feline@idxfalse}  % no adding index

\define@key{FelineIndex}{hsp}   []{\@feline@hsptrue}

% locally use a different index command
\define@key{FelineIndex}{idxit} []{\renewcommand\felineIndexCmd{\itindex}}
\define@key{FelineIndex}{idxbf} []{\renewcommand\felineIndexCmd{\bfindex}}
\define@key{FelineIndex}{idxn}  []{\renewcommand\felineIndexCmd{\index}}

% \sidepar's are non-floating objects so they does not move by them
% self, we need to help if needed, the argument should be a number
% (the unit will be \onelineskip)
\newlength\feline@spvs@addto
\setlength\feline@spvs@addto{0pt}
\define@key{FelineIndex}{addtospvrt}{\addtolength{\feline@spvs@addto}{#1\onelineskip}}
\define@key{FelineIndex}{vaddtosp}  {\addtolength{\feline@spvs@addto}{#1\onelineskip}}

% force the use of \sidepar, don't think I've ever used this
\define@key{FelineIndex}{forcesidepar}[true]{\dlf@M@setbool{#1}{@feline@forcesidepar}}

% by default this macro does nothing, the idea behind it is to use
% this in an external document to generate a list of key names and
% descriptions (using the first two arguments)
\providecommand\felineMarkupDescription[5]{}

% key generator macro, has the following arguments
% #1: name of the key
% #2: description of what this key is for
% #3: code for margin command
% #4: code for index command
% #5: code for text command
% and does the following:
% * creates \feline@margin@<key>, \feline@index@<key> and
%   \feline@text@<key>
% * the \define@key part then performs three \let's:
%   \let\feline@margin\feline@margin@<key> etc.
% when using \FelineKeyGenerator, #1 refers to the main argument given
% to \markup
\newcommand\felineKeyGenerator[5]{%
  \felineMarkupDescription{#1}{#2}{#3}{#4}{#5}%
  \global\define@key{FelineIndex}{#1}[]{%
    \global\@xp\@xp\@xp\let\@xp\@xp\@xp\feline@margin\@xp\csname feline@margin@#1\endcsname%
    \global\@xp\@xp\@xp\let\@xp\@xp\@xp\feline@index\@xp\csname feline@index@#1\endcsname%
    \global\@xp\@xp\@xp\let\@xp\@xp\@xp\feline@text\@xp\csname feline@text@#1\endcsname%
  }%
  \@namedef{feline@margin@#1}##1{#3}%
  \@namedef{feline@index@#1}##1{#4}%
  \@namedef{feline@text@#1}##1{#5}%
}

% standard key er lavet ned i \setkeys, da \markup[notxt]{...} ellers ikke vil
% vaere det samme som \markup[macro,notxt]{...} 

% this is the main macro, take two arguments, a optional argument for
% key controls and the mandatory arguments for the think we want to
% markup 
% note the it starts by setting the \feline@std@key which will be the
% stadard key used if the optional argument is empty or the other keys
% does not alter the \feline@margin, \feline@text and \feline@index
\newcommand\markup[2][]{%
%  \@bsphack
  \begingroup%
  \setkeys{FelineIndex}{\felineStandardKey}%
  \setkeys{FelineIndex}{#1}%
  \ifdim\feline@spvs@addto>0pt%
  \addtolength\sideparvshift{\feline@spvs@addto}%
  \fi%
  \if@feline@txt\feline@text{#2}\fi%
  \if@feline@idx\phantomsection\feline@index{#2}\fi%
  \if@feline@mrgn\if@feline@hsp\hspace{0pt}\fi\feline@margin{#2}\fi%
  \@feline@txttrue%
  \@feline@mrgntrue%
  \@feline@idxtrue%
  \endgroup%
%  \@esphack
}

% default generated key used by \markup, in the example setup 'macro'
% is used
\def\felineStandardKey{test}

% test key
\felineKeyGenerator{test}
  {test key, does not do anything useful}%
  {\felineWriteInMargin{#1}}%
  {\felineIndexCmd{#1}}%
  {\emph{#1}}



\InputIfFileExists{dlfltxbmarkup.cfg}{}{}