Debian Codegraph @

texmf-dist/source/lualatex/lualatex-truncate/lualatex-truncate.dtx

raw
1 %\iffalse
2 %<*package>
3 %% \CharacterTable
4 %% {Upper-case \A\B\C\D\E\F\G\H\I\J\K\L\M\N\O\P\Q\R\S\T\U\V\W\X\Y\Z
5 %% Lower-case \a\b\c\d\e\f\g\h\i\j\k\l\m\n\o\p\q\r\s\t\u\v\w\x\y\z
6 %% Digits \0\1\2\3\4\5\6\7\8\9
7 %% Exclamation \! Double quote \" Hash (number) \#
8 %% Dollar \$ Percent \% Ampersand \&
9 %% Acute accent \' Left paren \( Right paren \)
10 %% Asterisk \* Plus \+ Comma \,
11 %% Minus \- Point \. Solidus \/
12 %% Colon \: Semicolon \; Less than \<
13 %% Equals \= Greater than \> Question mark \?
14 %% Commercial at \@ Left bracket \[ Backslash \\
15 %% Right bracket \] Circumflex \^ Underscore \_
16 %% Grave accent \` Left brace \{ Vertical bar \|
17 %% Right brace \} Tilde \~}
18 %</package>
19 %\fi
20 %\iffalse
21 % Doc-Source file to use with LaTeX2e
22 % Copyright (C) 2018 Sebastian Friedl
23 %
24 % This work is subject to the LaTeX Project Public License, Version 1.3c or -- at
25 % your option -- any later version of this license.
26 % The work consists of the files lualatex-truncate.dtx, lualatex-truncate.ins,
27 % lualatex-truncate-doc.dtx and the derived file lualatex-truncate.sty
28 %
29 % This work has the LPPL maintenance status 'maintained'.
30 % Current maintainer of the work is Sebastian Friedl.
31 %\fi
32 %
33 %
34 %
35 % \changes{1.0}{2018/06/03}{Initial release}
36 % \changes{1.1}{2018/08/22}{\textsc{\bfseries Bugfix:} visible hyphen char with \texttt{breakall} option and non-english language}
37 %
38 % \subsubsection*{Initialization}
39 % Identify the package and require \LaTeXe:
40 % \begin{macrocode}
41 \ProvidesPackage{lualatex-truncate}%
42 [2018/08/22 v1.1 LuaLaTeX wrapper for the truncate package]
43 \NeedsTeXFormat{LaTeX2e}
44 % \end{macrocode}
45 %
46 %
47 %
48 % \subsubsection*{Internal variables}
49 % This variable is used to remember whether messing with the hyphen char is required:
50 % \begin{macrocode}
51 \newif\if@lualtxtruncate@hackhyphen
52 \@lualtxtruncate@hackhyphenfalse
53 % \end{macrocode}
54 %
55 % Also, enable remembering whether the \opt{breakall} option has been used:
56 % \begin{macrocode}
57 \newif\if@lualtxtruncate@breakall
58 \@lualtxtruncate@breakallfalse
59 % \end{macrocode}
60 %
61 %
62 %
63 %
64 % \subsubsection*{Package options}
65 % The \opt{breakwords} and \opt{breakall} options require the hyphanation character to be hidden.
66 % Therefore, we remember to \enquote{hack} the hyphen character before passing these options
67 % to the \enquote{original} \sty{truncate} package:
68 % \begin{macrocode}
69 \DeclareOption{breakwords}{%
70 \@lualtxtruncate@hackhyphentrue%
71 \PassOptionsToPackage{breakwords}{truncate}}
72 % \end{macrocode}
73 %
74 % In case of the \opt{breakall} option, we also need to remember the option's usage:
75 % \begin{macrocode}
76 \DeclareOption{breakall}{%
77 \@lualtxtruncate@breakalltrue%
78 \@lualtxtruncate@hackhyphentrue%
79 \PassOptionsToPackage{breakall}{truncate}}
80 % \end{macrocode}
81 %
82 % \smallskip
83 % Pass all other options (i.e. \opt{hyphenate} and \opt{fit}) directly to the \sty{truncate} package:
84 % \begin{macrocode}
85 \DeclareOption*{\PassOptionsToPackage{\CurrentOption}{truncate}}
86 % \end{macrocode}
87 %
88 % \smallskip
89 % Process all options passed to \sty{lualatex-truncate}:
90 % \begin{macrocode}
91 \ProcessOptions
92 % \end{macrocode}
93 %
94 %
95 %
96 % \subsubsection*{Load the \sty{truncate} package}
97 % Require the \sty{truncate} package. All package options have already been passed on. \\
98 % If \sty{truncate} has been loaded already, a error message is printed to the log.
99 % \begin{macrocode}
100 \@ifpackageloaded{truncate}{%
101 \PackageError{lualatex-truncate}%
102 {Don't load the truncate package when using lualatex-truncate!}%
103 {Don't load the truncate package and pass all package options
104 to lualatex-truncate! Otherwise, the wrapper mechanism won't
105 be able to understand what you want.}%
106 }{\RequirePackage{truncate}}
107 % \end{macrocode}
108 %
109 %
110 %
111 % \subsubsection*{If the document is not compiled via \hologo{LuaLaTeX}\dots}
112 % Don't wrap anything if the document isn't compiled by \hologo{LuaLaTeX}:
113 % \begin{macrocode}
114 \RequirePackage{iftex}
115 \ifLuaTeX\else%
116 \PackageWarningNoLine{lualatex-truncate}%
117 {Whoops! You don't want to use LuaLaTeX?}%
118 \endinput%
119 \fi%
120 % \end{macrocode}
121 %
122 %
123 %
124 % \subsubsection*{Constructing the wrapper}
125 % \begin{macro}{\lualtxtruncate@truncate}
126 % Remember the original "\truncate" command's definition.
127 % Since "\truncate" provides an optional argument, "\LetLtxMacro" has to be used
128 % instead of the primitive "\let" command:
129 % \begin{macrocode}
130 \RequirePackage{letltxmacro}
131 \LetLtxMacro\lualtxtruncate@truncate\truncate
132 % \end{macrocode}
133 % \end{macro}
134 %
135 % \begin{macro}{\truncate}
136 % \changes{1.1}{2018/08/22}{Remember previous hyphenation character}
137 % Construct the wrapper by redefining the "\truncate" command
138 % and -- if necessary -- modifying "\prehyphenchar". \\
139 % "\prehyphenchar"'s value is stored inside the counter
140 % "\lualtxtruncate@tmp". Also, the current language must be set to US english,
141 % if the \opt{breakall} option has been used.
142 % \begin{macrocode}
143 \renewcommand{\truncate}[3][\TruncateMarker]{{% two braces -> scope changes
144 \if@lualtxtruncate@breakall%
145 \language\z@% force US english
146 \fi%
147 \newcount\lualtxtruncate@tmp%
148 \lualtxtruncate@tmp=\the\prehyphenchar% remember current hyphen char
149 \if@lualtxtruncate@hackhyphen%
150 \prehyphenchar=0% invisible hyphen
151 \fi%
152 \lualtxtruncate@truncate[#1]{#2}{#3}% run the original \truncate macro
153 \if@lualtxtruncate@hackhyphen%
154 \prehyphenchar=\the\lualtxtruncate@tmp% restore hyphen
155 \fi%
156 }}
157 % \end{macrocode}
158 % \end{macro}
159 %
160 %
161 %
162 % \subsubsection*{Famous last words}
163 % Enough code for this package. "\endinput".
164 % \begin{macrocode}
165 \endinput
166 % \end{macrocode}