-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcodehilite.sty
More file actions
586 lines (534 loc) · 20.9 KB
/
codehilite.sty
File metadata and controls
586 lines (534 loc) · 20.9 KB
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
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
%%
%% This is file `codehilite.sty'.
%%
%% This file contains macros for including syntax-colored inlined code
%% in LaTeX.
%%
%% Copyright 2014 Tao B. Schardl
%%
%% LaTeX for in-paragraph highlighted code is based heavily on minted
%% by Konrad Rudolph (Copyright 2010--2011). In particular, parts of
%% minted.sty have been reproduced here (generally with minor naming
%% modifications) to provide basic support for in-paragraph
%% syntax-highlighted code environment, "codehilite." The codehilite
%% environment does not use the latex pygments formatter, but a
%% derivative formatter that is compatible with LaTeX, such as
%% pure-LaTeX comments and hiding of content in the source code from
%% the pretty-printed version.
%%
%% 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.
%% 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 2005/12/01 or later.
%%
\NeedsTeXFormat{LaTeX2e}
\def\codehilite@filename{codehilite.sty}
\def\codehilite@fileversion{1.0}
\def\codehilite@filedate{2012/08/07}
\ProvidesPackage{codehilite}[\codehilite@filedate{} v\codehilite@fileversion{} Macros for syntax highlighting code in LaTeX]
% Required packages
\RequirePackage{fancyvrb}
\RequirePackage{keyval}
\RequirePackage{xcolor}
% TB 02/23/2013: To get hyperref to work with fancyvrb, maintain a
% separate line counter
\newcounter{HRefFancyVerbLine}
\AtBeginDocument{
\def\FV@refstepcounter#1{%
\stepcounter{#1}%
\refstepcounter{HRefFancyVerbLine}%
\protected@edef\@currentlabel%
{\csname p@#1\endcsname\arabic{FancyVerbLine}}%
}
}
% Use the style automatically generated by the cilkhilite pygments
% plugin.
%
% This should be replaced with something less cilkbook-centric
% \usepackage{cilkbookstyle}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Macros for in-paragraph colored code
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%-------------------------------------------------------------------------
%% Internal macros
% Commands for syntax-highlighted in-paragraph code environment. Code
% based heavily on minted.sty by Konrad Rudolph (Copyright 2010--2011).
\def\codehilite@resetoptions{}
\newcommand\codehilite@defopt[1]{%
\expandafter\def\expandafter\codehilite@resetoptions\expandafter{%
\codehilite@resetoptions%
\@namedef{codehilite@opt@#1}{}}}
\newcommand\codehilite@opt[1]{%
\expandafter\detokenize%
\expandafter\expandafter\expandafter{\csname codehilite@opt@#1\endcsname}}
%% Helper macros to define options to codehilite environment
\newcommand\codehilite@define@opt[3][\@empty]{%
\codehilite@defopt{#2}%
\ifx#1\@empty%
\define@key{codehilite@opt}{#2}{\@namedef{codehilite@opt@#2}{#3}}%
\else%
\define@key{codehilite@opt}{#2}[#1]{\@namedef{codehilite@opt@#2}{#3}}%
\fi}
\newcommand\codehilite@define@switch[3][]{%
\codehilite@defopt{#2}%
\define@booleankey{codehilite@opt}{#2}%
{\@namedef{codehilite@opt@#2}{#3}}%
{\@namedef{codehilite@opt@#2}{#1}}}
\codehilite@defopt{extra}
\newcommand\codehilite@define@extra[1]{%
\define@key{codehilite@opt}{#1}{%
\expandafter\def\expandafter\codehilite@opt@extra\expandafter{%
\codehilite@opt@extra,#1=##1}}}
\newcommand\codehilite@define@extra@switch[1]{%
\define@booleankey{codehilite@opt}{#1}%
{\expandafter\def\expandafter\codehilite@opt@extra\expandafter{%
\codehilite@opt@extra,#1}}%
{\expandafter\def\expandafter\codehilite@opt@extra\expandafter{%
\codehilite@opt@extra,#1=false}}}
%% Options for codehilite environment
\codehilite@define@switch{texcl}{-P texcomments}
\codehilite@define@switch{mathescape}{-P mathescape}
\codehilite@define@switch{linenos}{-P linenos}
\codehilite@define@switch{startinline}{-P startinline}
\codehilite@define@switch{reindent}{-P reindent}
\codehilite@define@switch{hidebydefault}{-P hidebydefault}
% \codehilite@define@switch[-P funcnamehighlighting=False]%
% {funcnamehighlighting}{-P funcnamehighlighting}
\codehilite@define@opt[Verbatim]{verbenvironment}{#1}
\codehilite@define@opt[Verbatim]{inparcodeenvironment}{#1}
\codehilite@define@opt{gobble}{-F gobble:n=#1}
\codehilite@define@extra{frame}
\codehilite@define@extra{framesep}
\codehilite@define@extra{framerule}
\codehilite@define@extra{rulecolor}
\codehilite@define@extra{numbers}
\codehilite@define@extra{numbersep}
\codehilite@define@extra{firstnumber}
\codehilite@define@extra{stepnumber}
\codehilite@define@extra{firstline}
\codehilite@define@extra{lastline}
\codehilite@define@extra{baselinestretch}
\codehilite@define@extra{xleftmargin}
\codehilite@define@extra{xrightmargin}
\codehilite@define@extra{fillcolor}
\codehilite@define@extra{tabsize}
\codehilite@define@extra{fontfamily}
\codehilite@define@extra{fontsize}
\codehilite@define@extra{fontshape}
\codehilite@define@extra{fontseries}
\codehilite@define@extra{formatcom}
\codehilite@define@extra{label}
\codehilite@define@extra@switch{numberblanklines}
\codehilite@define@extra@switch{showspaces}
\codehilite@define@extra@switch{resetmargins}
\codehilite@define@extra@switch{samepage}
\codehilite@define@extra@switch{showtabs}
\codehilite@define@extra@switch{obeytabs}
%% Helper macro writing verbatim code to a file.
%% Do not invoke this directly.
\def\codehilite@defaultcodeout{\jobname.code}
% \newwrite\@codehilite@outfile
\newwrite\codehilite@code
\newcommand\codehilite@savecode[2][\codehilite@defaultcodeout]{%
\immediate\openout\codehilite@code#1%
\immediate\write\codehilite@code{#2}%
\immediate\closeout\codehilite@code}
\def\codehilite@getLexerString#1{-l #1 }
\def\codehilite@getSaveVerbString#1{-P verbenvironment=Save#1 }
% Helper macro for calling pygmentize on a given file from TeX.
% Do not invoke this directly
\newcommand\codehilite@pygmentize[2][\codehilite@defaultcodeout]{%
% \@iffileonpath{#1}%
% {%
% \edef\@codehilite@outcode{\@filef@und}%
% \immediate\openout\@codehilite@outfile#1.out %
% \immediate\closeout\@codehilite@outfile#1.out %
% \@iffileonpath{#1.out}%
% {%
% \edef\@codehilite@outpyg{\@filef@und}%
\def\codehilite@cmd{pygmentize -l #2 -f cilkbook -F tokenmerge
-P verbenvironment=\codehilite@opt{verbenvironment}
\codehilite@opt{gobble}
\codehilite@opt{texcl}
\codehilite@opt{mathescape}
\codehilite@opt{startinline}
\codehilite@opt{reindent}
\codehilite@opt{hidebydefault}
% \codehilite@opt{funcnamehighlighting}
\codehilite@opt{linenos}
-P "verboptions=\codehilite@opt{extra}"
-o #1.out #1}%
\immediate\typeout{\codehilite@cmd}%
\immediate\write18{\codehilite@cmd}%
% }{\PackageWarning{\@currname}{File `#1.out' not found}}%
% }{\PackageWarning{\@currname}{File `#1' not found}}
% \DeleteFile{\codehilite@defaultcodeout.out}
}
\newcounter{InParCodeNumber}
\newcommand\codehilite@InParCode@OutFile{\jobname-ipcode.ipvrb}
\newcommand\codehilite@InParCode@InFile{\jobname-ipcode.sty}
\newwrite\codehilite@InParCode@Out
\newcommand\codehilite@theInParCode@Number{\roman{InParCodeNumber}}
\newcommand\codehilite@InParCode@ID{@codehilite@InParCode@\codehilite@theInParCode@Number}
\AtBeginDocument {
\IfFileExists{\jobname-ipcode.sty}{\usepackage{\jobname-ipcode}}%
{\PackageWarning{\@currname}{File `\jobname-ipcode.sty' not found}}
\setcounter{InParCodeNumber}{1}
\immediate\openout\codehilite@InParCode@Out\codehilite@InParCode@OutFile
}
\AtEndDocument {
\closeout\codehilite@InParCode@Out
}
\def\DefineSaveUseVerbatimEnvironment#1#2{
\DefineVerbatimEnvironment{Save#1}{SaveVerbatim}{#2}
\edef\codehilite@UseVerbatimName{\csname Use#1\endcsname}
\expandafter\def\codehilite@UseVerbatimName{\FV@Command{#2}{UseVerbatim}}
}
%%-------------------------------------------------------------------------
%% External macros
% Macro for setting default options for codehilite
\newcommand\codehiliteset[1]{
\expandafter\def\expandafter\codehilite@resetoptions\expandafter{%
\codehilite@resetoptions
\setkeys{codehilite@opt}{#1}}}
% Environment for in-paragraph code
\newenvironment{codehilite}[2][]
{\VerbatimEnvironment%
\def\codehilite@proglang{#2}%
\codehilite@resetoptions%
\setkeys{codehilite@opt}{#1}%
\begin{VerbatimOut}[codes={\catcode`\^^I=12}]{\codehilite@defaultcodeout}}%
{\end{VerbatimOut}%
\codehilite@pygmentize{\codehilite@proglang}%
\input{\codehilite@defaultcodeout.out}%
%\DeleteFile{\codehilite@defaultcodeout}
}
% Command to add new in-paragraph code environments
\newcommand\newcodehilite[3][\@empty]{
\ifx#1\@empty%
\def\codehilite@envname{#2code}%
\else%
\def\codehilite@envname{#1}%
\fi
\newenvironment{\codehilite@envname}
{\VerbatimEnvironment\begin{codehilite}[#3]{#2}}
{\end{codehilite}}
\newenvironment{\codehilite@envname *}[1]
{\VerbatimEnvironment\begin{codehilite}[#3,##1]{#2}}
{\end{codehilite}}}
\def\DefineInParCodeEnvironment#1#2{%
\DefineVerbatimEnvironment{#1}{Verbatim}{#2}%
\DefineSaveUseVerbatimEnvironment{#1}{#2}%
}
\DefineVerbatimEnvironment{VcodehiliteOut}{VcodehiliteOut}{}
\def\VcodehiliteOut{\FV@Environment{}{VcodehiliteOut}}
\def\FVB@VcodehiliteOut{%
\@bsphack
\begingroup
\FV@UseKeyValues
\FV@DefineWhiteSpace
\def\FV@Space{\space}%
\FV@DefineTabOut
\def\FV@ProcessLine{\immediate\write\codehilite@InParCode@Out}%
% \immediate\openout\FV@OutFile #1\relax
\let\FV@FontScanPrep\relax
%% DG/SR modification begin - May. 18, 1998 (to avoid problems with ligatures)
\let\@noligs\relax
%% DG/SR modification end
\FV@Scan}
\def\FVE@VcodehiliteOut{%
\endgroup\@esphack%
\def\codehilite@InParCode@SVName{FV@SV@\codehilite@InParCode@ID}%
\@ifundefined{\codehilite@InParCode@SVName}%
{\PackageWarning{\@currname}{No entry found for `\codehilite@InParCode@ID'}}%
{%
\def\codehilite@InParCode@UseVerbatimName{\csname Use\codehilite@opt{inparcodeenvironment}\endcsname}%
\codehilite@InParCode@UseVerbatimName{\codehilite@InParCode@ID}%
}%
\stepcounter{InParCodeNumber}%
}
\newenvironment{codehiliteOut}[2][]
{%
\VerbatimEnvironment
\def\codehilite@proglang{#2}%
\codehilite@resetoptions%
\setkeys{codehilite@opt}{#1}%
%\show\codehilite@opt{inparcodeenvironment}%
\immediate\write\codehilite@InParCode@Out{%
\codehilite@InParCode@ID[
\codehilite@getLexerString{\codehilite@proglang}
\codehilite@getSaveVerbString{\codehilite@opt{inparcodeenvironment}}
\codehilite@opt{gobble}
\codehilite@opt{texcl}
\codehilite@opt{mathescape}
\codehilite@opt{startinline}
\codehilite@opt{reindent}
\codehilite@opt{hidebydefault}
% \codehilite@opt{funcnamehighlighting}
\codehilite@opt{linenos}
-P "verboptions=\codehilite@opt{extra}"]}%
\begin{VcodehiliteOut}
}
{\end{VcodehiliteOut}}
% \newenvironment{codehiliteOut}[2][]
% {%
% \VerbatimEnvironment
% \def\codehilite@proglang{#2}%
% \codehilite@resetoptions%
% \setkeys{codehilite@opt}{#1}%
% %\show\codehilite@opt{inparcodeenvironment}%
% \immediate\write\codehilite@InParCode@Out{%
% \codehilite@InParCode@ID[
% \codehilite@getLexerString{\codehilite@proglang}
% \codehilite@getSaveVerbString{\codehilite@opt{inparcodeenvironment}}
% \codehilite@opt{gobble}
% \codehilite@opt{texcl}
% \codehilite@opt{mathescape}
% \codehilite@opt{startinline}
% \codehilite@opt{reindent}
% \codehilite@opt{hidebydefault}
% % \codehilite@opt{funcnamehighlighting}
% \codehilite@opt{linenos}
% -P "verboptions=\codehilite@opt{extra}"]}%
% \@bsphack
% \begingroup
% \FV@UseKeyValues
% \FV@DefineWhiteSpace
% \def\FV@Space{\space}%
% \FV@DefineTabOut
% \def\FV@ProcessLine{\immediate\write\codehilite@InParCode@Out}%
% % \immediate\openout\FV@OutFile #1\relax
% \let\FV@FontScanPrep\relax
% \let\@noligs\relax
% \FV@Scan}%
% {%
% \endgroup\@esphack%
% \def\codehilite@InParCode@SVName{FV@SV@\codehilite@InParCode@ID}%
% \@ifundefined{\codehilite@InParCode@SVName}%
% {\PackageWarning{\@currname}{No entry found for `\codehilite@InParCode@ID'}}%
% {%
% \def\codehilite@InParCode@UseVerbatimName{\csname Use\codehilite@opt{inparcodeenvironment}\endcsname}%
% \codehilite@InParCode@UseVerbatimName{\codehilite@InParCode@ID}%
% }%
% \stepcounter{InParCodeNumber}%
% }
\newcommand\newcodehiliteOut[3][\@empty]{
\ifx#1\@empty%
\def\codehilite@envname{#2code}%
\else%
\def\codehilite@envname{#1}%
\fi
\newenvironment{\codehilite@envname}
{\VerbatimEnvironment\begin{codehiliteOut}[#3]{#2}}
{\end{codehiliteOut}}
\newenvironment{\codehilite@envname *}[1]
{\VerbatimEnvironment\begin{codehiliteOut}[#3,##1]{#2}}
{\end{codehiliteOut}}}
\newcommand\codehiliteIn[1]{\input{#1-ippyg}}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Macros for inline colored code
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Hook into the start of every \terminal{} command. This hook allows
% custom formatting of \terminal{} commands, similar to the \everymath
% and \everydisplay hooks for math modes.
\def\everyterminal#1{\texttt{#1}}
% Generic command to format a TeX string to look like code. This
% command does no special syntax-coloring.
%
% Arguments:
% #1 - code string (TeX string)
% \newcommand{\terminal}[1]{\texttt{#1}}
%\def\terminal#1{\texttt{\textcolor{terminalcolor}{#1}}}
\def\terminal#1{{%
\ifmmode\text{\everyterminal{#1}}%
\else\everyterminal{#1}\fi}}
%\def\terminal#1{{\everyterminal\ifmmode\text{\texttt{#1}}\else\texttt{#1}\fi}}
%%---------------------------------------------------------------------------
%% Internal macros
\newcommand\codehilite@definlinecode[2]{\expandafter\let\csname #1\endcsname=#2}
\newcommand\codehilite@newinlinecode[3]{\codehilite@definlinecode{#1}{#2}}
\IfFileExists{\jobname-inlinecode.sty}{\usepackage{\jobname-inlinecode}}%
{\PackageWarning{\@currname}{File `\jobname-inlinecode.sty' not found}}
% Auxiliary file for inlined code. The aux file is processed
% separately between LaTeX runs using the pyginline script.
\newwrite\codehilite@inlinecodeaux
\AtBeginDocument{
% \openout\codehilite@inlinecodeaux=\jobname-inlinecode.vrb.tmp
\immediate\openout\codehilite@inlinecodeaux=\jobname-inlinecode.vrb
}
\AtEndDocument{%
% Close the output
\closeout\codehilite@inlinecodeaux%
% {\def\codehilite@cmd{mv \jobname-inlinecode.vrb.tmp \jobname-inlinecode.vrb}
% \immediate\write18{\codehilite@cmd}}%
}
% % If we had any inlined code, move output .vrb.tmp to .vrb for processing by pyginline
% \IfFileExists{\jobname-inlinecode.vrb.tmp}%
% {\def\codehilite@cmd{mv \jobname-inlinecode.vrb.tmp \jobname-inlinecode.vrb}
% \immediate\write18{\codehilite@cmd}}%
% % Otherwise just touch \jobname-inlinecode.sty for next iteration
% {\def\codehilite@cmd{touch \jobname-inlinecode.sty}
% \immediate\write18{\codehilite@cmd}}}
% Functions to mangle a given code string into a TeX csname.
% Helper function for reading a catcode
\newcommand\@getcatcode[1]{\the\catcode`#1}
% Helper function for mangling names to something TeX is OK with.
\catcode`\^^G=12
\newcommand\@mangle[1]{\@@mangle#1^^G}
\def\@@mangle#1{%
\ifx#1^^G\else%
\ifcase\@getcatcode{#1}%
@back\or @lcrl\or @rcrl\or @dollar\or @amp\or @ret\or @hash\or @carrot%
\or @under\or #1\or @spc\or #1\or%
\ifx#1.%
@dot\else\ifx#1-%
@dash\else\ifx#1+%
@plus\else\ifx#1*%
@times\else\ifx#1/%
@slash\else\ifx#1=%
@equals\else\ifx#1:%
@colon\else\ifx#1;%
@semicolon\else\ifx#1'%
@squote\else\ifx#1"%
@dquote\else\ifx#1,%
@comma\else\ifx#1|%
@pipe\else\ifx#1(%
@lprn\else\ifx#1)%
@rprn\else\ifx#1[%
@lsqr\else\ifx#1]%
@rsqr\else\ifx#1<%
@lang\else\ifx#1>%
@rang\else\ifx#1!%
@bang\else\ifx#1?%
@qust\else\ifx0#1%
@zero\else\ifx1#1%
@one\else\ifx2#1%
@two\else\ifx3#1%
@three\else\ifx4#1%
@four\else\ifx5#1%
@five\else\ifx6#1%
@six\else\ifx7#1%
@seven\else\ifx8#1%
@eight\else\ifx9#1%
@nine\else#1%
\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi%
\or @tilde@\or @perc@\or #1\fi%
\expandafter\@@mangle\fi}
% Helper function for hash code lines into TeX csnames.
\def\codehilite@hashcodename#1#2{codehilite@code@#1@\expandafter\@mangle\expandafter{#2}}
% Helper function for adding code lines to the inlinecode aux file.
\def\codehilite@registerinlinecode#1#2{\expandafter\def\csname #1\endcsname{#2}}
\newcommand\codehilite@recordinlinecode[2]{%
%\edef\codehilite@name{codehilite@code@#1@\expandafter\mangle\expandafter{#2}}%
\edef\codehilite@name{\codehilite@hashcodename{#1}{#2}}%
\@ifundefined{\codehilite@name}%
{\@ifundefined{@\codehilite@name}%
{\immediate\write\codehilite@inlinecodeaux{%
\noexpand\codehilite@newinlinecode{@\codehilite@name}{#2}{#1}}%
\PackageWarning{\@currname}{File `\jobname-inlinecode.sty' not found or out of date}%
\expandafter\expandafter\expandafter\codehilite@registerinlinecode%
\expandafter\expandafter\expandafter{%
\expandafter\expandafter\expandafter\codehilite@name%
\expandafter\expandafter\expandafter}%
\expandafter\expandafter\expandafter{\expandafter\detokenize\expandafter{#2}}%
}%
{\expandafter\expandafter\expandafter\codehilite@registerinlinecode%
\expandafter\expandafter\expandafter{%
\expandafter\expandafter\expandafter\codehilite@name%
\expandafter\expandafter\expandafter}%
\expandafter\expandafter\expandafter{\csname @\codehilite@name\endcsname}%
\immediate\write\codehilite@inlinecodeaux{%
\noexpand\codehilite@newinlinecode{@\codehilite@name} %
{\expandafter\expandafter\expandafter\detokenize%
\expandafter\expandafter\expandafter{\csname \codehilite@name\endcsname}}%
{null}}}%
}{}}
%%-------------------------------------------------------------------------
%% External macros
\newcommand\mangle[1]{
\DefineShortVerb{#1}%
\SaveVerb[aftersave={%
\UndefineShortVerb{#1}%
\expandafter\@mangle\expandafter{\FV@SV@codehilite@verb}%
}]{codehilite@verb}#1}
% The following commands are verb-like commands for inserting
% syntax-colored code. To denote a verbatim string, the string must
% be fenced by two identical characters that do not appear in the
% string itself, e.g. |hello, world!|. Standard characters to use to
% fence the verbatim string are "|" and "+".
% Primary verb-like command for inserting inlined syntax-colored code.
%
% Arguments:
% #1 - language (optional, defaults to empty)
% #2 - verbatim string
%
% You may use this command where you would otherwise use \verb||
\newcommand\codevrb[2][\@empty]{%
\DefineShortVerb{#2}%
\SaveVerb[aftersave={%
\UndefineShortVerb{#2}%
\ifx#1\@empty%
\terminal{\FV@SV@codehilite@verb}%
\else%
\edef\codehilite@name{\codehilite@hashcodename{#1}{\FV@SV@codehilite@verb}}%
\codehilite@recordinlinecode{#1}{\FV@SV@codehilite@verb}%
\terminal{\@nameuse{\codehilite@name}\unskip}%
\fi%
}]{codehilite@verb}#2}
% Verb-like command to define a syntax-colored string for later use with \usecodevrb{}.
%
% Arguments:
% #1 - language
% #2 - name of the colored string. This name should be a valid TeX csname.
% #3 - verbatim string
\newcommand\defcodevrb[3]{%
\DefineShortVerb{#3}%
\SaveVerb[aftersave={%
\UndefineShortVerb{#3}%
\codehilite@recordinlinecode{#1}{\FV@SV@codehilite@verb}%
\edef\codehilite@name{codehilite@code@named@#2}%
\edef\codehilite@codehash{\codehilite@hashcodename{#1}{\FV@SV@codehilite@verb}}%
\expandafter\expandafter\expandafter\codehilite@registerinlinecode%
\expandafter\expandafter\expandafter{%
\expandafter\expandafter\expandafter\codehilite@name%
\expandafter\expandafter\expandafter}%
\expandafter\expandafter\expandafter{%
\csname \codehilite@codehash\endcsname}%
}]{codehilite@verb}#3}
% Command to use a named inline-code string, defined by \defcodevrb.
%
% Arguments:
% #1 - name of the colored string, as defined by argument #2 of
% \defcodevrb.
\newcommand\@usecodevrb[1]{%
\@ifundefined{codehilite@code@named@#1}%
{\terminal{\textcolor{red}{#1 UNDEFINED}}}%
{\terminal{\@nameuse{codehilite@code@named@#1}\unskip}}}
\newcommand\usecodevrb[1]{\protect\@usecodevrb{#1}}
% These commands allow you to define and undefine a special character
% as an abbreviation to enclose inlined code of a particular language.
\def\DefineShortCodeVerb{\FV@Command{}{DefineShortCodeVerb}}
\newcommand\FVC@DefineShortCodeVerb[2]{
\begingroup
\lccode`\~=`#2%
\lowercase{\gdef\@tempg{\edef~}\global\let\@temph~}%
\endgroup
\expandafter\let\csname FV@AC@\string#2\endcsname\@temph
\expandafter\edef\csname FV@CC@\string#2\endcsname{\the\catcode`#2}%
\expandafter\let\csname FV@KV@\string#2\endcsname\FV@KeyValues
\@tempg{%
\let\noexpand\FV@KeyValues\expandafter\noexpand
\csname FV@KV@\string#2\endcsname
\noexpand\codevrb[#1]\expandafter\@gobble\string#2}%
% \noexpand\FVC@Verb\expandafter\@gobble\string#2}%
\expandafter\def\expandafter\dospecials\expandafter{\dospecials\do#2}%
\expandafter\def\expandafter\@sanitize\expandafter{\@sanitize\@makeother#2}%
\catcode`#2=\active}%
\newcommand\UndefineShortCodeVerb[1]{%
\@ifundefined{FV@CC@\string#1}%
{\FV@Error{`\expandafter\@gobble\string#1' is not a short
verb character}\FV@eha}%
{\FV@UndefineShortVerb#1}}