Debian Codegraph @

texmf-dist/doc/lualatex/kkluaverb/kkluaverb-doc.tex

raw
1 \documentclass[luatex,fontsize=8pt,paper=b5,twoside]{jlreq}%
2 \usepackage{amsmath,amssymb}
3 \usepackage{booktabs,caption, tabularray}
4 \usepackage{luwa-ul}
5 \usepackage{KKsymbols}
6 \usepackage[most]{tcolorbox}
7 \usepackage{KKluaverb}
8
9 %%% fonts (This can be omitted.)
10 \makeatletter
11 \RequirePackage[no-math]{fontspec}
12 \RequirePackage[no-math,match,scale=1]{luatexja-fontspec}
13 \RequirePackage[hiragino-pro,deluxe,expert]{luatexja-preset}
14 \setmainfont{HiraMinPro-W3}[BoldFont=HiraMinPro-W6]
15 \setmainjfont{HiraMinPro-W3}[BoldFont=HiraMinPro-W6]
16 \newfontfamily{\sfhira@pre}{HiraKakuPro-W3}[BoldFont=HiraKakuPro-W6]
17 \newjfontfamily{\sfhiraj@pre}{HiraKakuPro-W3}[BoldFont=HiraKakuPro-W6]
18 \newfontfamily{\mchira@pre}{HiraMinPro-W3}[BoldFont=HiraMinPro-W6]
19 \newjfontfamily{\mchiraj@pre}{HiraMinPro-W3}[BoldFont=HiraMinPro-W6]
20 \newfontfamily{\gthira@pre}{HiraKakuPro-W3}[BoldFont=HiraKakuPro-W6,FontFace={eb}{\shapedefault}{HiraKakuStd-W8}]
21 \newjfontfamily{\gthiraj@pre}{HiraKakuPro-W3}[BoldFont=HiraKakuPro-W6,FontFace={eb}{\shapedefault}{HiraKakuStd-W8}]
22 \newfontfamily{\mghira@pre}{HiraMaruPro-W4}
23 \newjfontfamily{\mghiraj@pre}{HiraMaruPro-W4}
24 \renewcommand{\sffamily}{\sfhira@pre\sfhiraj@pre}
25 \renewcommand{\mcfamily}{\mchira@pre\mchiraj@pre}
26 \renewcommand{\gtfamily}{\gthira@pre\gthiraj@pre}
27 \renewcommand{\mgfamily}{\mghira@pre\mghiraj@pre}
28 \makeatother
29 %%%
30
31
32 %%% mapping
33 \begin{luacode*}
34 KKLuaVerb.presets["TeXStyle"] = {
35 map = {
36 DarkCyan = { "{", "}" },
37 OrangeRed = { "[", "]" },
38 DeepPink = { "(", ")" },
39 DarkGoldenrod = { "&", "$", "^", "_"},
40
41 CornflowerBlue = {
42 "\\documentclass", "\\usepackage", "\\begin", "\\end",
43 "\\section", "\\subsection", "\\chapter",
44 "\\makeatletter", "\\makeatother", "\\ExplSyntaxOn", "\\ExplSyntaxOff"
45 },
46
47 MediumPurple = {
48 "\\def", "\\edef", "\\gdef", "\\xdef",
49 "\\newcommand", "\\renewcommand", "\\providecommand",
50 "\\let", "\\setcopy", "\\long", "\\global"
51 },
52
53 Magenta = {
54 "\\if", "\\else", "\\fi", "\\ifx", "\\ifdefined",
55 "\\ifnum", "\\ifdim", "\\loop", "\\repeat", "\\noexpand"
56 },
57
58 IndianRed = {
59 "\\KKlvStart*", "\\KKlvEnd*"
60 }
61 },
62
63 options = {
64 word_boundary = true,
65 comment_char = "%",
66 comment_color = "ForestGreen",
67 escape_char = "\\",
68 delimiters = {
69 { start = "$", stop = "$", color = "SpringGreen3" },
70 { start = "\\[", stop = "\\]", color = "SpringGreen3" },
71 },
72 forced_tokens = {
73 ["{"] = "DarkCyan",
74 ["}"] = "DarkCyan",
75 },
76 }
77 }
78 \end{luacode*}
79
80 \begin{luacode*}
81 KKLuaVerb.presets["LuaStyle"] = {
82 map = {
83 Magenta = {
84 "if", "then", "else", "elseif", "end",
85 "for", "while", "repeat", "until", "in",
86 "do", "break", "return", "function"
87 },
88
89 ProcessBlue = { "local", "true", "false", "nil" },
90 DarkGoldenrod = {
91 "print", "require", "type", "tostring", "tonumber",
92 "table", "string", "math", "io", "os", "debug", "coroutine",
93 "self"
94 },
95
96 DarkCyan = { "{", "}", "[", "]", "(", ")", "=", "+", "-", "*", "/", "#", "..", "==" }
97 },
98 options = {
99 word_boundary = true,
100 comment_char = "--",
101 comment_color = "Cerulean",
102 escape_char = "%",
103 delimiters = {
104 { start = '"', stop = '"', color = "SkyBlue1" },
105 }
106 }
107 }
108 \end{luacode*}
109 %%%
110
111
112 %%% hyperref
113 \usepackage{hyperref}
114 \hypersetup{
115 luatex, pdfencoding=auto,
116 colorlinks=true,
117 linkcolor=black,
118 citecolor=black,
119 urlcolor=DeepSkyBlue3,
120 pdfborder={0 0 0},
121 }
122 %%%
123
124
125 %%% textboxes
126 \makeatletter
127 \newcommand{\ascb@parindent}[1]{%
128 \setlength{\parindent}{#1}\relax%
129 }
130 \def\ascb@gtfamily{\gtfamily}\def\ascb@zw#1#2{#1\zw}
131 \DeclareTColorBox{simple}{ o m O{.5} O{} }%
132 {empty, left=2mm, right=2mm, top=-1mm,
133 attach boxed title to top left={xshift=\ascb@zw{1.2}{11pt}},
134 boxed title style={empty,left=-2mm,right=-2mm}, colframe=black, coltitle=black, coltext=black, breakable,
135 before upper={\ascb@parindent{\zw}},%%%
136 underlay unbroken={\draw[black,line width=#3pt](title.east) -- (title.east-|frame.east) -- (frame.south east) -- (frame.south west) -- (title.west-|frame.west) -- (title.west); },
137 underlay first={\draw[black,line width=#3pt](title.east) -- (title.east-|frame.east) -- (frame.south east) ;
138 \draw[black,line width=#3pt] (frame.south west) -- (title.west-|frame.west) -- (title.west); },
139 underlay middle={\draw[black,line width=#3pt](frame.north east) -- (frame.south east) ;
140 \draw[black,line width=#3pt](frame.south west) -- (frame.north west) ;},
141 underlay last={\draw[black,line width=#3pt](frame.north east) -- (frame.south east) -- (frame.south west) -- (frame.north west) ;},
142 fonttitle=\ascb@gtfamily, IfValueTF={#1}{title=\hspace*{.1em}【#2】〈#1〉\hspace*{.1em}}{title=\hspace*{.1em}【#2】\hspace*{.1em}},#4}
143 \def\KKfbox@SourceCode@phantom{\vphantom{あ}\vphantom{j}}
144 \NewTCBListing{SourceCode}{ m m !o !O{DeepSkyBlue3} }{%
145 enhanced, colback=black!70, colframe=Snow4,
146 toptitle=-1mm, bottomtitle=-1mm,
147 righttitle=-1mm, lefttitle=-1mm,
148 arc=.5mm,
149 title={\tcbox[on line, arc=.5mm, boxsep=0pt, boxrule=0pt,
150 top=1mm, bottom=0.8mm, left=2mm, right=2.2mm,
151 colback=gray!80, coltext=white]{%
152 \raisebox{-.04\zw}{\KKfbox@SourceCode@phantom#1}}%
153 },
154 fonttitle=\gtfamily\footnotesize, boxrule=0.8pt,
155 breakable, before upper={\color{white}}, top=-0.5mm, bottom=-0.5mm,
156 after title=\IfNoValueTF{#3}{}{{\hfill%
157 \tcbox[on line, arc=.5mm, boxsep=0pt, boxrule=0pt,
158 top=1mm, bottom=0.8mm, left=2mm, right=2.2mm,
159 colback=white!80!black, coltext=#4]{\raisebox{-.04\zw}{\KKfbox@SourceCode@phantom#3}}}%
160 },
161 listing only,
162 listing options={
163 language={#2},
164 basicstyle=\ttfamily,
165 keywordstyle=\ttfamily\color{white},
166 stringstyle=\itshape\color{white},
167 commentstyle=\small\gtfamily\color{DeepSkyBlue2},
168 showspaces=false,showtabs=false,
169 breaklines=true,breakindent=0pt,
170 showstringspaces=false,
171 columns=fullflexible,
172 tabsize=2,
173 numbers=left,numbersep=1.5pt,
174 numberstyle=\scriptsize\gtfamily\color{gray},
175 }
176 }
177 \NewTColorBox{OutPut}{ m !o !O{DeepSkyBlue3} }{%
178 enhanced, colframe=Snow4,
179 toptitle=-1mm, bottomtitle=-1mm,
180 righttitle=-1mm, lefttitle=-1mm,
181 arc=.5mm, colback=white,
182 title={\tcbox[on line, arc=.5mm, boxsep=0pt, boxrule=0pt,
183 top=1mm, bottom=0.8mm, left=2mm, right=2.2mm,
184 colback=gray!40, coltext=DeepSkyBlue3]{\raisebox{-.04\zw}{\KKfbox@SourceCode@phantom#1}}%
185 },
186 fonttitle=\gtfamily\footnotesize, boxrule=0.8pt,
187 breakable, top=-0.5mm, bottom=-0.5mm,
188 after title=\IfNoValueTF{#2}{}{{\hfill%
189 \tcbox[on line, arc=.5mm, boxsep=0pt, boxrule=0pt,
190 top=1mm, bottom=0.8mm, left=2mm, right=2.2mm,
191 colback=white!80!black, coltext=#3]{\raisebox{-.04\zw}{\KKfbox@SourceCode@phantom#2}}}%
192 },
193 bottom=2mm, top=2mm,
194 }
195 \makeatother
196 %%%
197
198
199 %%% titlepage
200 \title{\texttt{KKluaverb} Package Documentation}
201 \author{Kosei Kawaguchi a.k.a. KKTeX}
202 \date{Version 2.1.2 (2026/01/27)}
203 %%%
204
205 \begin{document}
206 \KKvUsePreset{TeXStyle}
207
208 %%% title and toc
209 \begin{titlepage}
210 \maketitle
211 \end{titlepage}
212 \newpage
213 \tableofcontents
214 \newpage
215 %%%
216
217 \section{Outline}
218 The \KKverb|KKluaverb| is a LaTeX package which provides a Lua-enhanced \KKverb|\verb| command, \KKverb|\KKverb|. \thinHighLight{It can be used in the table of contents, index, underline commands (e.g., \KKverb|\underLineKK| provided by the luwa-ul package), \KKverb|tblr| environment and so on.}
219
220 \section{Acknowledgements / Credit}
221 In devoloping this package, I made use of an algorithm which is used in ``bxrawstr'' (by Takayuki YATO)\footnote{%
222 package: \url{https://gist.github.com/zr-tex8r/c7901658a866adfcd3cd66b6dfa86997}\par
223 article: \url{https://zrbabbler.hatenablog.com/entry/20181222/1545495849}}.
224
225 \section{Dependencies}
226 This package internally uses the following packages:
227
228 \begin{itemize}
229 \item luatexbase, luacode
230 \item pgfkeys
231 \item xcolor
232 \end{itemize}
233
234 \section{Basic Usage of Lua-enhanced \KKverb|\verb|}
235 \subsection{Fundamental Behavior}
236 As mentioned in the ``Outline'' section, this package mainly provides enhanced \KKverb|\verb| command. The usage is not much different from the normal one.
237
238 \KKvScanOff
239 \begin{SourceCode}{Input}{TeX}
240 \KKverb|\def\TEST{Test Text.}|
241 \end{SourceCode}
242 \KKvScanOn
243 \begin{OutPut}{Output}
244 \KKverb|\def\TEST{Test Text.}|
245 \end{OutPut}
246
247 In the argument of the command, any linebreaks and blank lines are ignored. However, every space are preserved and rendered exactly as it appears.
248
249 \subsection{In Verbatim Environments}
250 When this package is loaded, the Lua-scanning which enables \KKverb|\KKverb| to detokenize its argument is activated.
251 However, when \KKverb|\KKverb| used in verbatim environments such as ``lstlistings'' and ``tcblisting'', the argument cannot be decoded properly.
252 \namiKK{In such cases, you should use \KKverb|\KKvScanOff| which deactivates the scanning process used internally in \KKverb|KKverb.lua|.} Of course, \KKverb|\KKvScanOn| re-activates the process.
253
254 \subsection{Optional Usage}
255 In addition to the main function of \KKverb|\KKverb|, some optional funcions are provided.
256
257 \KKverb|\KKvOpChange| can change font and color of the output of \KKverb|\KKverb|. Also, it can activate or deactivate the scanner.
258 The usage is as follows:
259
260 \KKvScanOff
261 \begin{SourceCode}{Input}{TeX}
262 {\KKvOpChange{color=blue, font=\gtfamily, enabled=true}%
263 \KKverb|\def\TEST{Test Text.}|}
264 \end{SourceCode}
265 \KKvScanOn
266 \begin{OutPut}{Output}
267 {\KKvOpChange{color=blue, font=\gtfamily, enabled=true}%
268 \KKverb|\def\TEST{Test Text.}|}
269 \end{OutPut}
270
271 \bigskip\begin{center}
272 \captionof{table}{\KKverb|\KKvOpChange|}
273 \begin{tblr}{
274 colspec = {l l l},
275 hline{1,Z} = {0.8pt},
276 hline{2} = {.4pt},
277 column{1} = {font=\ttfamily},
278 row{1} = {font=\bfseries, bg=gray9},
279 }
280 Key & Default Value & Description \\
281 font & \KKverb|\ttfamily| & Sets the font for the verbatim text. \\
282 color & \KKverb|black| & Sets the text color. \\
283 enabled & \KKverb|true| & Activates or deactivates the scanning engine. \\
284 \end{tblr}
285 \end{center}\bigskip
286
287 Additionally, the \KKverb|enabled| option functions the same as \KKverb|\KKvScanOn| and \KKverb|\KKvScanOff|.
288
289 Also, you can change delimiters by using \KKverb|\KKvSetDelims| as follows in order to change the delimiters of the command:
290
291 \KKvScanOff
292 \begin{SourceCode}{Input}{TeX}
293 \KKvSetDelims{[<}{>]}
294
295 Changed the delimiters: \KKverb[<\def\foo\s>]
296 \end{SourceCode}
297
298 \KKvScanOn
299 \begin{OutPut}{Output}
300 \KKvSetDelims{[<}{>]}
301
302 Changed the delimiters: \KKverb[<\def\foo\s>]
303 \end{OutPut}
304
305 \KKvSetDelims{|}{|}
306
307 By default, the delimiters are set as "|". So you can reset them by this:
308
309 \KKvScanOff
310 \begin{SourceCode}{Input}{TeX}
311 \KKvSetDelims{|}{|}
312 \end{SourceCode}
313 \KKvScanOn
314
315 \subsection{Behavior in TOC, Index etc.}
316 One of the strong points of \KKverb|\KKverb| is that it can be used in table of contents, index, and footnotes and more.
317 While the traditional \KKverb|\verb| command always causes an error in such contexts, \KKverb|\KKverb| does not. This is achieved through the following logic, using the TOC as an example.
318
319 When the TeX system generates the TOC, it produces an auxiliary file with the extension \KKverb|.toc|. In this file, entry data is typically stored in an expanded state.
320
321 However, this package requires the raw text data to be passed unexpanded. This is because the text must be intercepted and processed by \KKverb|process_input_buffer| before TeX's tokenizer converts it into tokens. To resolve this, I implemented a mechanism that automatically prepends the \KKverb|\unexpanded| command to the starter flag when writing to auxiliary files:
322
323 \KKcodeS+
324 % In TOC
325 \noexpand\KKlvStart*<encoded tests>\noexpand\KKlvEnd*%
326 \KKcodeE
327
328 Then, the content of the \KKverb|.toc| file is processed by TeX in the usual way subsequently, because the \KKverb|\unexpanded| is no longer present.
329
330 \section{Basic Usage of Lua-enhanced \KKverb|lstlisting|}
331 \subsection{Fundamental Behavior}
332 \KKvScanOff
333 \verb|\KKcodeS| and \verb|\KKcodeE| provide an environment-like output which is very close to the \verb|lstlisting|.
334 The usage is very simple. The code between \verb|\KKcodeS| and \verb|\KKcodeE| is rendered as raw texts.
335
336 If you want to attach linenumbers to the left of the each line, \verb|\KKcodeS+| will meet the request. Please note that you do not need to type \verb|\KKcodeE+|. \verb|\KKcodeS+| and \verb|\KKcodeE| is the proper pair.
337
338 \begin{SourceCode}{Input}{TeX}
339 \KKcodeS+
340 % A sample command
341 \long\def\myprog#1{%
342 \ifx#1\empty
343 \relax
344 \else
345 \message{Processing...}%
346 #1
347 \fi
348 }
349 \KKcodeE
350 \end{SourceCode}
351 \KKvScanOn
352 \begin{OutPut}{Output}
353 \KKcodeS+
354 % A sample command
355 \long\def\myprog#1{%
356 \ifx#1\empty
357 \relax
358 \else
359 \message{Processing...}%
360 #1
361 \fi
362 }
363 \KKcodeE
364 \end{OutPut}
365
366 When you use this Lua-based environment, please keep the following points in mind:
367
368 \begin{itemize}
369 \item All indents and spaces are displayed.
370 \item Line breaks and blank lines are rendered exactly as they appear in the source.
371 \end{itemize}
372
373 \subsubsection{\KKverb|\KKvLNChange|}
374 This command can change the style of the linenumbers.
375
376 \bigskip\begin{center}
377 \captionof{table}{\KKverb|\KKvLNChange|}
378 \begin{tblr}{
379 colspec = {l l l},
380 hline{1,Z} = {0.8pt},
381 hline{2} = {.4pt},
382 column{1} = {font=\ttfamily},
383 row{1} = {font=\bfseries, bg=gray9},
384 }
385 Key & Default Value & Description \\
386 font & \KKverb|\ttfamily| & Sets the font for the linenumbers. \\
387 color & \KKverb|black!80| & Sets the color of the linenumbers. \\
388 size & \KKverb|\small| & Set the size of the linenumbers. \\
389 start & \KKverb|1| & Set the start number. \\
390 style & \KKverb|0| & Set the style. \\
391 \end{tblr}
392 \end{center}\bigskip
393
394 \KKvScanOff
395 Please note that you do not have to use style key when you use this package in a normal way.
396 This is because style1 and style2 are completely covered by \verb|\KKcodeS/E| or \verb|\KKcodeS+/E| environment.
397 The following example illustrates this point.
398
399 \begin{SourceCode}{Input}{TeX}
400 {\KKvLNChange{style=1}
401 \KKverb|
402 % contents
403 |}
404
405 \KKcodeS
406 % contents
407 \KKcodeE
408 \end{SourceCode}
409
410 \noindent The two above produce identical output. To summarize,
411
412 \begin{description}
413 \item[\texttt{style=0}] This is the normal usage of the \verb|\KKverb|.
414 \item[\texttt{style=1}] This style corresponds to \verb|\KKcodeS/E| environment.
415 \item[\texttt{style=2}] This style corresponds to \verb|\KKcodeS+/E| environment.
416 \end{description}
417
418 \subsection{Additional Description}
419 \KKvScanOff
420 Some corner cases should be payed attention.
421
422 \subsubsection{Note\#1}
423 You cannot use \verb|\KKcodeS| and \verb|\KKcodeE| in the argument of \verb|\KKverb| command. When the scanner is activated, \verb|\KKcodeS| forcibly starts the encoding system, even it is wrapped by \verb|\KKverb|.
424 If you need to display \verb|\KKcodeS| and \verb|\KKcodeE| as they are, deactivate the scanner by \verb|\KKvScanOff| and use \verb|\verb|.
425
426 \subsubsection{Note\#2}
427 Any text on the same line that falls "inside" the \verb|\KKcodeS| and \verb|\KKcodeE| boundaries is ignored, while text "outside" them is preserved. The following example will illustrate the behavior.
428
429 \begin{SourceCode}{Input}{TeX}
430 Not ignored. \KKcodeS+ Ignored.
431 % Contents
432 Ignored. \KKcodeE Not ignored.
433 \end{SourceCode}
434 \KKvScanOn
435 \begin{OutPut}{Output}
436 Not ignored. \KKcodeS+ Ignored.
437 % Contents
438 Ignored. \KKcodeE Not ignored.
439 \end{OutPut}
440
441 \section{Color Mapping}
442 \KKvScanOff
443 \subsection{Basic Behavior}
444 This package provides color-mapping option. You can specify the color of the keyword-color, comment-color, comment-token, etc.
445 In order to set a colormap, you should use \verb|luacode*| environment as follows:
446
447 \begin{SourceCode}{Input}{TeX}
448 \begin{luacode*}
449 KKLuaVerb.presets["<name-of-style>"] = {
450 map = {
451 <color1> = { "<token1>", "<token2>",... },
452 <color2> = { "<token1>", "<token2>",... },
453 ...
454 },
455
456 options = {
457 word_boundary = true or false,
458 word_components = "[<word-components>]",
459 comment_char = "<comment-token>",
460 comment_color = "<comment-color>",
461 escape_char = "<escape-token>",
462 delimiters = {
463 { start = '<starter1>', stop = '<ender1>', color = "<patial-color1>" },
464 { start = '<starter2>', stop = '<ender2>', color = "<patial-color2>" },
465 },
466 forced_tokens = {
467 ["<forced-token1>"] = "<color2>",
468 ["<forced-token2>"] = "<color2>",
469 }
470 }
471 }
472 \end{luacode*}
473 \end{SourceCode}
474
475 %%% オプション全部についてガッツリ説明書くこと!
476 %%% 今のままだとわかりづらい!
477
478 The ``color'' parameter here refers to those defined in the \verb|xcolor| package.
479
480 You can set multiple presets, and can change or activate by \verb|\KKvUsePreset{<name-of-style>}| command.
481
482 \KKvScanOn
483 \subsubsection{\KKverb|word_boundary, word_components| options}
484 \KKvScanOff
485 These two options are closely related to each other. In the argument of the \verb|\KKverb| command or inside of the \verb|\KKcodeS/E| environment,
486 \KKvScanOn\KKvUsePreset{TeXStyle}
487 the mapped keywords are colored as you specified. However, if the string is included in the other words, you need to prevent the system provided from wrongly color the string. For example, in the situation that \KKverb|\def| command is mapped as a keyword but \KKverb|\define| is not, the part of \KKverb|\def| in \KKverb|\define| should not be colored.
488
489 For this purpose, I made a ``\KKverb|word_boundary| detector''. In advance, set the components of the ``word'' like this:
490
491 \KKvUsePreset{LuaStyle}
492 \KKcodeS+
493 word_components = "[A-Za-z0-9_]",
494 \KKcodeE
495
496 Then, activate the \KKverb|word_boundary| detector:
497
498 \KKcodeS+
499 word_boundary = true,
500 \KKcodeE
501
502 By all this, any characters or tokens except for \KKverb|"[A-Za-z0-9_]"| works as a separater of the words or tokens, and each keywords are properly colored.
503
504 By default, \KKverb|word_boundary| are set as ``\KKverb|true|'', and \KKverb|word_components| are set as \KKverb|"[A-Za-z0-9_]"|.
505
506 \subsubsection{\KKverb|comment_char, comment_color, escape_char| options}
507 These options are provided in order to set comment character, comment color, and escape character respectively.
508
509 If you set \KKverb|comment_char|,
510 the following texts in the same lina are colored as \KKverb|comment_color|.
511 But, if you put the \KKverb|escape_char| before the \KKverb|comment_char|, the very token and the following texts are not colored as \KKverb|comment_color|.
512
513 \subsubsection{\KKverb|delimiters, forced_token| options}
514 These options are provided for the purpose of setting \KKverb|delimiter token| and the color of the texts between the tokens.
515 Additionally, you can set multiple \KKverb|forced_token|. These are forced to be colored as you specify, even they are between the delimiters.
516
517 \subsection{Example}
518 \KKvScanOff
519
520 \begin{SourceCode}{Input}{TeX}[Setting]
521 \begin{luacode*}
522 KKLuaVerb.presets["TeXStyle"] = {
523 map = {
524 DarkCyan = { "{", "}" },
525 OrangeRed = { "[", "]" },
526 DeepPink = { "(", ")" },
527 DarkGoldenrod = { "&", "$", "^", "_"},
528
529 CornflowerBlue = {
530 "\\documentclass", "\\usepackage", "\\begin", "\\end",
531 "\\section", "\\subsection", "\\chapter",
532 "\\makeatletter", "\\makeatother", "\\ExplSyntaxOn", "\\ExplSyntaxOff"
533 },
534
535 MediumPurple = {
536 "\\def", "\\edef", "\\gdef", "\\xdef",
537 "\\newcommand", "\\renewcommand", "\\providecommand",
538 "\\let", "\\setcopy", "\\long", "\\global"
539 },
540
541 Magenta = {
542 "\\if", "\\else", "\\fi", "\\ifx", "\\ifdefined",
543 "\\ifnum", "\\ifdim", "\\loop", "\\repeat", "\\noexpand"
544 },
545
546 IndianRed = {
547 "\\KKlvStart*", "\\KKlvEnd*"
548 }
549 },
550
551 options = {
552 word_boundary = true,
553 comment_char = "%",
554 comment_color = "ForestGreen",
555 escape_char = "\\",
556 delimiters = {
557 { start = "$", stop = "$", color = "SpringGreen3" },
558 { start = "\\[", stop = "\\]", color = "SpringGreen3" },
559 },
560 forced_tokens = {
561 ["{"] = "DarkCyan",
562 ["}"] = "DarkCyan",
563 },
564 }
565 }
566 \end{luacode*}
567 \end{SourceCode}
568
569 \begin{SourceCode}{Input}{TeX}[Actual Use]
570 \KKvUsePreset{TeXStyle}
571
572 \KKcodeS+
573 \usepackage{KKluaverb}
574
575 \begin{document}
576 Hello, KKTeX!
577 \end{document}
578 \KKcodeE
579
580 \KKcodeS
581 { [ \ ( \% \$ # & _ ^ ) / ] }
582 Inline mathmode: $a + b = \frac{x}{y}$
583 Display-style mathmode:
584 \[a + b = \frac{x}{y}\]
585 \KKcodeE
586 \end{SourceCode}
587
588 \KKvScanOn
589 \begin{OutPut}{Output}
590 \KKvUsePreset{TeXStyle}
591
592 \KKcodeS+
593 \usepackage{KKluaverb}
594
595 \begin{document}
596 Hello, KKTeX!
597 \end{document}
598 \KKcodeE
599
600 \KKcodeS
601 { [ \ ( \% \$ # & _ ^ ) / ] }
602 Inline mathmode: $a + b = \frac{x}{y}$
603 Display-style mathmode:
604 \[a + b = \frac{x}{y}\]
605 \KKcodeE
606 \end{OutPut}
607
608 \section{Text Mapping}
609 \KKvScanOff
610 By using \verb|\KKvSetMap|, you can replace a certain text in the argument of \verb|\KKverb| and \verb|\KKcodeS/E| environment.
611
612 \begin{SourceCode}{Input}{TeX}[Actual Use]
613 \KKvSetMap{!}{〈EXCLAMATION〉}
614 \KKvSetMap{?}{〈QUESTION〉}
615
616 \KKverb|Wait, you really change them!?|
617
618 \KKvSetMap{!}{!}
619 \KKvSetMap{?}{?}
620 \KKverb|Oh, how can I reset them!?|
621 \end{SourceCode}
622 \KKvScanOn
623 \begin{OutPut}{Output}
624 \KKvSetMap{!}{〈EXCLAMATION〉}
625 \KKvSetMap{?}{〈QUESTION〉}
626
627 \KKverb|Wait, you really change them!?|
628
629 \KKvSetMap{!}{!}
630 \KKvSetMap{?}{?}
631 \KKverb|Oh, how can I reset them!?|
632 \end{OutPut}
633
634 \KKvScanOff
635 Using this, you can visualize all spaces in the argument of \verb|\KKverb| and \verb|\KKcodeS/E| environment.
636 \KKvScanOn
637 \namiKK{However, you have to use \KKverb|\KKvSpaceForce| if you want to reset.}
638 By default, this package automatically replaces any spaces to Unicode character U+00A0 (Non-breaking Space). Therefore, you need to use the special command if you want to quit visualizing spaces.
639
640 \KKvScanOff
641 \begin{SourceCode}{Input}{TeX}[Actual Use]
642 \KKvSetMap{ }{<sp>}
643 \KKverb| Look! All spaces are visualized!! |
644
645 \KKvSpaceForce
646 \KKverb| Oh, spaces are no longer visualized. |
647 \end{SourceCode}
648 \KKvScanOn
649 \begin{OutPut}{Output}
650 \KKvSetMap{ }{<sp>}
651 \KKverb| Look! All spaces are visualized!! |
652
653 \KKvSpaceForce
654 \KKverb| Oh, spaces are no longer visualized. |
655 \end{OutPut}
656 \end{document}
657