summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/lualatex/novel/novel-TextMacros.sty
blob: 8346676bbb86a13a2717e60e0d8e1ce53c9b86a3 (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
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
%%
%% This is file `novel-TextMacros.sty', part of class `novel'.
%% Copyright 2017 Robert Allgeyer.
%%
%% 
%% This file may be distributed and/or modified under the
%% conditions of the LaTeX Project Public License, either version 1.3c
%% 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.3c or later is part of all distributions of LaTeX
%% version 2005/12/01 or later.
%% 
%%
\ProvidesFile{novel-TextMacros.sty}%
[2017/11/29 v1.46.1 LaTeX file (text macros usable within document body)]
%%


%% This file contains various commands that are usable within the document body,
%% for styling and otherwise manipulating text.
%% These are not commands used in Preamble for setup, although a few of them
%% can be used in Preamble for setup, then again in body for change.


%% The following commands are BANNED.
%% -----------------------------------------------------------------------------
% The `novel' class disallows these commands, or neutralizes them by simply
% repeating their arguments. In some cases, they request functionality that is
% not implemented in `novel'. In other cases, the functionality is part of core,
% but would interfere with the `novel' emphasis on constant line skip.
% You may re-define the commands using your own code in Preamble (discouraged).
%
%% Standard LaTeX font sizes are ineffective. Use novel's own methods.
% If you write one of these size commands, it will silently be ignored:
% \small, \footnotesize, \scriptsize, \tiny,
% \large, \Large, \LARGE, \huge, \Huge, \HUGE.
%
%% Internal subdivisions are ineffective.
% The command will merely echo its argument, without any functionality:
% \part{}, \chapter{}, \section{}, \subsection{}, \subsubsection{}, \paragraph{}, \subparagraph{}
%
%% Certain commands will generate an error, so that you know they cannot be used:
% \maketitle, \makeindex, \tableofcontents, \listoftables, \listoffigures, \textls
%
%% You cannot use \includepdf (package: pdfpages).
%
%% You cannot use \includegraphics. Instead use novel's own image commands.
%
%% Commands normally provided in other classes, pertaining to floats, figures, and tables,
%% are not defined in `novel' class. If you attempt to use them, an error will result.



%% AND NOW TO THE GOOD STUFF
%% -----------------------------------------------------------------------------
%
%% \memo{} does not print or save its argument.
% Useful when you wish to put a note to yourself in the *.tex document.
% Not the same as % comment, because anything after the braces will print.
\long\gdef\memo#1{}
%
\gdef\stake{\rule{0pt}{1pt}} % placeholder
%
% \forceindent and \backindent perform or remove indent, using \hspace{}.
% Rationale: Sometimes \indent and \noindent are neutralized by another command.
\newlength\forceparlength % holds default value, even when \parindent changed

% See novel.cls for accompanying AtBeginDocument routine.

%%
% \smcp{} and \textsc{} small caps (Open Type) and \allsmcp{}:
%
\ExplSyntaxOn
%
\DeclareDocumentCommand \smcp { +m }
 {%
  {\addfontfeature{Letters=SmallCaps}#1}%
 }
%
\DeclareDocumentCommand \allsmcp { +m }
 {%
  \fontspec_if_feature:nTF {c2sc}{%
   {\addfontfeatures{Letters=UppercaseSmallCaps, Letters=SmallCaps}#1}%
  }{%
   {\addfontfeature{Letters=SmallCaps}\MakeLowercase{#1}}%
  }%
 }
%
\ExplSyntaxOff
%
\let\textsc\smcp\relax % unified
\let\oldscshape\scshape\relax % in case needed later
\let\scshape\smcp\relax % unified
%
\providecommand\FirstLineFont{\smcp} % package `magaz'
\renewcommand\FirstLineFont{\smcp}
%%

%% The `novel' class normally allows only black text on white paper.
%% In draft mode, option `shademargins` provides light gray margins,
%%   but still black text on white paper.
%% However, with option `graytext' (in any mode) then grayscale text
%%   is allowed. Images are always allowed grayscale.
%% Just in case `xcolor' re-defines its internals, to prevent code bomb:
\ProvideDocumentCommand\@declaredcolor { m } {}
\ProvideDocumentCommand\@undeclaredcolor { o m } {}
%%
\if@graytext % and the usual colors, including black and white.
  \definecolor[named]{gray1}{gray}{0.15} % ten percent gray, etc.
  \definecolor[named]{gray2}{gray}{0.25}
  \definecolor[named]{gray3}{gray}{0.33}
  \definecolor[named]{gray4}{gray}{0.4}
  \definecolor[named]{gray5}{gray}{0.5}
  \definecolor[named]{gray6}{gray}{0.6}
  \definecolor[named]{gray7}{gray}{0.68}
  \definecolor[named]{gray8}{gray}{0.75}
  \definecolor[named]{gray9}{gray}{0.87}
\else
  \let\my@color\color\relax
  \let\color\relax
  \DeclareDocumentCommand \color { o m }
   {%
   \ifthenelse{\equal{#1}{gray} \AND \equal{#2}{0.903215}}{\@undeclaredcolor[gray]{0.903215}}{}% shademargins
   \ifthenelse{\equal{#2}{hingledingle}}{\@declaredcolor{white}}{}% hingledingle is internal alias for white
   }
\fi
%%


% This code is slightly modified from package `etextools' by Florent Chervet.
% Its license: "This work 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."
% My rationale for not simply loading the package: Other parts of the package
% generate warning messages, but the warnings do not apply. Also, I might
% wish to hack the code at some point.
\newcount\nov@ettl@fter
\newrobustcmd\nov@AfterGroup{%
  \@ifstar{\nov@ettl@AfterGroup\@firstofone}{\nov@ettl@AfterGroup\unexpanded}%
}
\newrobustcmd\nov@ettl@AfterGroup[2]{%
 \csxdef{nov@ettl@fterGroup\number\numexpr\the\nov@ettl@fter+1}%
 {\global\csundef{nov@ettl@fterGroup\number\numexpr\the\nov@ettl@fter+1}#1{#2}}%
 \global\advance\nov@ettl@fter\@ne%
 \expandafter\aftergroup\csname nov@ettl@fterGroup\the\nov@ettl@fter\endcsname%
}
% End code from `etextools`.




%% \flexbox based on code by Werner at tex.stackexchange.com, CC-by-sa-3.0:
% Optional first argument is minimum width of box.
% Second argument is contents of box.
% Box width will be the greater of #1 or the width of #2.
\newlength\@mylen
\newcommand{\flexbox}[2][\parindent]{%
  \settowidth{\@mylen}{#2}%
  \ifdim\@mylen < #1%
    \makebox[#1][l]{#2}%
  \else%
    #2%
  \fi%
}
%% \bigemdash inspired by code by RTBarnard at stackoverflow.com, CC-by-sa-3.0:
% Allows a rule of variable length to fill available space at its right.
% There must be a "right-hand limit" imposed by something, such as by enclosing
%   the rule in a \makebox of known width, or by an immediate \par.
%   Without this limit, rule will be missing (zero width) or excessively long,
%   or an error will result (referring to \leaders).
% Takes a single optional argument: Comma-separated raise, line thickness.
%   If no argument or empty, defaults to [1,1].
%   Without comma, argument defaults to [argument,1].
%   First number: Scales the raise up or down. 1 = raise of emdash in typical fonts.
%   Second number: Scales the line thickness. 1 = thickness of emdash in typical fonts.
% NOTE: Built-in TeX PDF viewer might show the line at slightly incorrect
%   width and height. Best seen in a "real" PDF viewer.
\DeclareDocumentCommand \bigemdash { O{1,1} }
 {%
  \ifthenelse{\equal{#1}{}\OR\equal{#1}{\space}}{\def\@myargsi{1,1}}{\def\@myargsi{#1}}%
  \StrDel{\@myargsi}{\space}[\@myargs]%
  \StrCut{\@myargs}{,}{\@myraisei}{\@mythicki}%
  \ifthenelse{\equal{\@myraisei}{}\OR\equal{\@myraisei}{\space}}{\def\@myraise{1}}{\def\@myraise{\@myraisei}}%
  \ifthenelse{\equal{\@mythicki}{}\OR\equal{\@mythicki}{\space}}{\def\@mythick{1}}{\def\@mythick{\@mythicki}}%
  \FPmul{\@myraise}{\@myraise}{0.56}% ex, typical font emdash raise
  \FPmul{\@mythick}{\@mythick}{0.049}% em, typical font emdash thickness
  {\leaders\hbox{\rule[\@myraise ex]{1pt}{\@mythick em}}\hfill\stake}%
 }
%%

%%
% \charscale[scale,x,y]{text} and starred version
% This is an "in-line" means of adjusting font size
%   and position, without changing the baselineskip.
% If the optional argument is unused or empty, then the text is not scaled
%   or moved, but equivalent to \stake\smash{text}.
% Up to 3 arguments may be used in the single optional argument.
% They are separated by commas. Spaces ignored.
% First argument is scale. Number>=0.5. Default 1. Relative to what the size
%   would otherwise be. May multiply with an already-scaled font.
% Second and third arguments are x-offset and y-offset, respectively.
% Offsets are lengths, best measured in em or \nfs for x,
%   and em or \nfs or \nbs for y. Default 0pt. Can abbreviate as 0.
% Posiive offsets are x right, y up.
% Text is "smashed" and may go anywhere, even overlying other text or image.
% The unstarred command occupies width equal to the scaled text,
%   thus leaving a "hole" where the text would have been.
% The starred command occupies zero width, thus no hole. Consecutive starred
%   commands, without intervening space, displace from same origin.
% The text must be on a single line, without break or wrap.
% Do not use \\ or \par inside \charscale, but you sometimes need \par after it.
% If the text is in a font other than usual, place the font command
%   outside \charscale, not inside.
\ExplSyntaxOn
\DeclareDocumentCommand \charscale { s O{1} m }
 {
  % Allows empty or blank to be used, and still provide default values:
  \ifthenelse{\equal{#2}{}\OR\equal{#2}{\space}}{\def\@myargs{1}}{\def\@myargs{#2}}
  \StrDel{\@myargs}{\space}[\@myargsns] % needs {\space} not { }
  \StrCut{\@myargsns}{,}{\@myscalet}{\@mycoord}
  \ifthenelse{\equal{\@myscalet}{}}{\def\@myscale{1}}{\def\@myscale{\@myscalet}}
  \FPmax{\@myscale}{\@myscale}{0.5}% not permitted below this scale
  \StrCut{\@mycoord}{,}{\@myxt}{\@myyt}
  \ifthenelse{\equal{\@myxt}{}\OR\equal{\@myxt}{0}}{\def\@myx{0pt}}{\def\@myx{\@myxt}}
  \ifthenelse{\equal{\@myyt}{}\OR\equal{\@myyt}{0}}{\def\@myy{0pt}}{\def\@myy{\@myyt}}
  \IfBooleanTF{#1}
  {% starred
    \ifvmode\else\unskip\fi%
    \stake\makebox[0pt][l]{\smash{\hspace{\@myx}\raisebox{\@myy}{\scalebox{\@myscale}{#3}}}}%
  }{% unstarred
    \stake\makebox[0pt][l]{\smash{\hspace{\@myx}\raisebox{\@myy}{\scalebox{\@myscale}{#3}}}}%
    \smash{\phantom{\scalebox{\@myscale}{#3}}}%
  }
 }
\ExplSyntaxOff
%%



%%
% If you really must change the font size and baselineskip on a paragraph basis,
%   then use an environment. For example, the text on your Copyright page might
%   be smaller (and less baselineskip) than normal.
% The following environment takes an optional argument, which is the scale
%   of font size and baselineskip, relative to normal. Note that both size
%   and skip are scaled together. The default is 1, meaning no change.
% To get the rough equivalent of traditional \footnotesize, use 0.83 scale.
% Example:
%    \begin{parascale}[0.83]
%    This text is like old footnotesize. It can go on for many lines.\par
%    Be sure to end with the paragraph ending.\par
%    You may need to manipulate whether anything indents.\par
%    \end{parascale}
% Normally you should NOT use this environment within the main text,
%   as it will upset the baselineskip there. If you have to do that for
%   a special effect, then use \vspace{} before and after the environment,
%   so that the following normalsize text is re-aligned. You'll have to
%   do the calculations yourself.
\newenvironment{parascale}[1][1]
{\begingroup%
\FPmax{\my@tempDetailsNum}{#1}{0.5}% must be at least half normal.
\FPmul{\my@tempDetailsFontNum}{\my@tempDetailsNum}{\Current@FontSizeNum}%
\FPround{\my@tempDetailsFontNum}{\my@tempDetailsFontNum}{2}%
\FPmul{\my@tempDetailsSkipNum}{\my@tempDetailsNum}{\Current@BaselineSkipNum}%
\FPround{\my@tempDetailsSkipNum}{\my@tempDetailsSkipNum}{2}%
\fontsize{\my@tempDetailsFontNum pt}{\my@tempDetailsSkipNum pt}\selectfont}%
{\endgroup}
%
%%
% Environment toc (alternative table of contents):
% optional argument: additional vspace (\nbs) after each \tocitem entry.
% required: LR margin increase, to narrow the table (0pt = full textwidth).
\newlength\@tocnumwid
\newlength\@tocskip
\newenvironment{toc}[2][0]%
{%
  \begin{adjustwidth}{#2}{#2}%
  \begingroup% lengths not global
  \setlength\parindent{0pt}%
  \setlength\@tocnumwid{\widthof{00.~}}%
  \setlength\@tocskip{#1\nbs}%
}{%
  \endgroup\end{adjustwidth}\par%
}%
%% \tocitem[number]{description}{page} provides a one-line table entry in toc.
% optional number might be chapter number. Can use ~ to offset.
% unstarred: distance between description and page is not decorated.
% starred (better): distance between description and page has dotted line.
\newcommand\tocitem{\@ifstar\@tocitemst\@tocitemns}
\newcommand\@tocitemst[3][]{%
  \ifthenelse{\equal{#1}{}}{}{%
    \ifthenelse{\equal{#1}{~}}{%
      \makebox[\@tocnumwid][l]{~}%
    }{%
      \makebox[\@tocnumwid][l]{#1.}%
    }%
  }%
  #2\,%
  \dotfill%
  \,#3\par\vspace{\@tocskip}%
}%
%
\newcommand\@tocitemns[3][]{%
  \ifthenelse{\equal{#1}{}}{}{%
    \ifthenelse{\equal{#1}{~}}{%
      \makebox[\@tocnumwid][l]{~}%
    }{%
      \makebox[\@tocnumwid][l]{#1.}%
    }%
  }%
  #2%
  \hfill%
  #3\par\vspace{\@tocskip}%
}%
%% end toc and \tocitem.
%%
%% legalese environment. Certain info, such as Copyright page, customarily is
% neither justified nor hyphenated. Can be used wherever desired, of course.
\newenvironment{legalese}
{\raggedright\hyphenpenalty=10000\exhyphenpenalty=10000}
{}
%
\gdef\hangleft#1{% places content to left of usual position.
  \newlength\@temphangl%
  \setlength\@temphangl{\widthof{#1}}%
  \stake\hspace{-\@temphangl}#1%
}
%%
% \showlength[decimal places]{length}{units}
% Returns the length as a string with the units, but does not change the length.
% length is any existing length
% units may be pt, bp, mm, cm, in
% decimal places for rounding (0=integer, 1=one decimal point, etc.)
% Example: \showlength[3]{17bp}{in}  returns  0.236in
\newlength{\temp@showlength}
\newcommand\showlength[3][]{%
  \setlength\temp@showlength{#2}%
  \def\temp@lengthnum{\strip@pt\temp@showlength}%
  \ifthenelse{\equal{#3}{bp}}{%
    \FPmul{\temp@lengthnum}{\temp@lengthnum}{0.99626401}%
  }{}%
  \ifthenelse{\equal{#3}{mm}}{%
    \FPmul{\temp@lengthnum}{\temp@lengthnum}{0.351459804}%
  }{}%
  \ifthenelse{\equal{#3}{cm}}{%
    \FPmul{\temp@lengthnum}{\temp@lengthnum}{0.0351459804}%
  }{}%
  \ifthenelse{\equal{#3}{in}}{%
    \FPmul{\temp@lengthnum}{\temp@lengthnum}{0.013837}%
  }{}%
  \ifthenelse{\equal{#1}{}}{}{\FPround{\temp@lengthnum}{\temp@lengthnum}{#1}}%
  \temp@lengthnum#3%
}
%% end \showlength


%% \squeeze{} and \crush{} slightly shrink the horizonal dimension of the
% enclosed text. May span paragraphs. Emergency only! No compounding.
\long\gdef\squeeze#1{{\addfontfeature{FakeStretch=0.99}#1}}
\long\gdef\crush#1{{\addfontfeature{FakeStretch=0.98}#1}}
%%


%% \lnum for lining numbers.
\gdef\lnum#1{{\addfontfeature{Numbers=Lining}#1}}
%%


%% superscripts and subscripts
\let\subs\relax
\let\sups\relax
\let\textsuperscript\relax
\let\textsubscript\relax
\newlength\@hoAhl % measured when needed.
% Perhaps superscripts and subscripts (scientific) are in the font, or not.
% Problem: The best fonts have these characters at size/weight designed
%   to mingle with normal size. But many fonts merely scaled characters,
%   which will be too light at the small size.
% The unstarred version of these commands use the Open Type features when
%   they are present, then faking (auto scale/raise) if features not present. 
% The starred version just fakes, without regard for features.
% 

% Note that the effect of these commands continues, not just one-shot:
\gdef\realmarker{\toggletrue{@realmarker}} % anywhere in text
\gdef\fakemarker{\togglefalse{@realmarker}} % anywhere in text
%%
\ExplSyntaxOn
%
\DeclareDocumentCommand \sups { m }
 {%
  \iftoggle{@realmarker}{%
    \fontspec_if_feature:nTF {sups}{%
      \ifvmode\else\unskip\fi{\addfontfeature{VerticalPosition=Superior}\smash{#1}}%
    }{%
      \setlength\@hoAhl{\heightof{Ahl}}%
      \ifvmode\else\unskip\fi\charscale[0.7,0pt,0.5\@hoAhl]{#1}%
    }%
  }{%
    \setlength\@hoAhl{\heightof{Ahl}}%
    \ifvmode\else\unskip\fi{\addfontfeature{Numbers=Lining}\charscale[0.7,0pt,0.5\@hoAhl]{#1}}%
  }%
 }% end \sups
%
\DeclareDocumentCommand \subs { m }
 {%
  \iftoggle{@realmarker}{%
    \fontspec_if_feature:nTF {sinf}{%
      \ifvmode\else\unskip\fi{\addfontfeature{VerticalPosition=ScientificInferior}\smash{#1}}%
    }{%
      \fontspec_if_feature:nTF {subs}{%
        \ifvmode\else\unskip\fi{\addfontfeature{VerticalPosition=Inferior}\smash{#1}}%
      }{%
        \setlength\@hoAhl{\heightof{Ahl}}%
        \ifvmode\else\unskip\fi\charscale[0.7,0pt,-0.2\@hoAhl]{#1}%
      }%
    }%
  }{%
    \setlength\@hoAhl{\heightof{Ahl}}%
    \ifvmode\else\unskip\fi{\addfontfeature{Numbers=Lining}\charscale[0.7,0pt,-0.2\@hoAhl]{#1}}%
  }%
 }% end \subs
%
\cs_new_eq:NN \textsuperscript \sups
\cs_new_eq:NN \textsubscript \subs
\ExplSyntaxOff
%%
\gdef\specialblankline{\null} % deprecated
%%


%% New in v. 1.46: Allows text to be placed (potentially) off-grid, with grid resuming after.
\newcounter{currentlinegap} % 0 when not within a linegap environment, >0 otherwise.
\ExplSyntaxOn
\DeclareDocumentEnvironment {linegap} { m } {%
  \FPifint{#1}\else%
    \ClassError{novel}{Non-integer~linegap~on~page~\thepage}%
     {Only~integer~>=~1~allowed~for~linegap.}%
  \fi%
  \FPiflt{#1}{1}%
    \ClassError{novel}{Insufficient~linegap~on~page~\thepage}%
     {Only~integer~>=~1~allowed~for~linegap.}%
  \fi%
  \par%
  \null%
  \vspace*{-\nbs}%
  \begin{textblock*}{\textwidth}[0,0](0pt,0pt)%
  \setcounter{currentlinegap}{#1}%
  \strut\par%
  \vspace*{-\nbs}%
}{% close the environment:
  \end{textblock*}%
  \par%
  \vspace*{#1\nbs}%
  \setcounter{currentlinegap}{0}%
}
\ExplSyntaxOff % end linegap environment
%%



%%
%% End of file `novel-TextMacros.sty'.