|
1 | 1 | % -*- coding: utf-8 -*-
|
2 |
| -\documentclass{article} |
| 2 | +\documentclass[oneside]{book} |
3 | 3 | \usepackage[a4paper,margin=2cm]{geometry}
|
4 | 4 |
|
5 | 5 | \usepackage{codehigh}
|
6 |
| -%\usepackage{arev} |
7 | 6 | \usepackage{hyperref}
|
8 | 7 | \hypersetup{
|
9 | 8 | colorlinks=true,
|
10 | 9 | urlcolor=blue3,
|
| 10 | + linkcolor=green3, |
11 | 11 | }
|
12 | 12 |
|
13 | 13 | \newcommand*{\myversion}{2021B}
|
14 |
| -\newcommand*{\mydate}{\the\year/\mylpad\month/\mylpad\day\ (v\myversion)} |
| 14 | +\newcommand*{\mydate}{Version \myversion\ (\the\year-\mylpad\month-\mylpad\day)} |
15 | 15 | \newcommand*{\mylpad}[1]{\ifnum#1<10 0\the#1\else\the#1\fi}
|
16 | 16 |
|
17 | 17 | \begin{document}
|
18 | 18 |
|
19 |
| -\title{\textsf{\color{green3}Codehigh Package: Highlight Codes and Demos with LaTeX3}% |
20 |
| - \footnote{\url{https://github.com/lvjr/codehigh}}} |
21 |
| -\author{Jianrui Lyu ( [email protected])} |
| 19 | +\title{\textsf{\color{green3}Codehigh: Highlight Codes and Demos with l3RegEx and LPeg}} |
| 20 | +\author{Jianrui Lyu ( [email protected]) \\ \url{https://github.com/lvjr/codehigh}} |
22 | 21 | \date{\mydate}
|
23 | 22 | \maketitle
|
24 | 23 |
|
25 |
| -\verb!Codehigh! package uses \verb!l3regex! package in \LaTeX3 Programming Layer |
26 |
| -to parse and highlight source codes and demos. |
27 |
| -In theory it would be more powerful than \verb!listings! package, |
28 |
| -and more easy to use than \verb!minted! package. |
| 24 | +\tableofcontents |
| 25 | + |
| 26 | +\chapter{Package Interface} |
| 27 | + |
| 28 | +\section{Introduction} |
| 29 | + |
| 30 | +\verb!Codehigh! package uses \verb!l3regex!\footnote{\url{https://www.ctan.org/pkg/l3regex}} |
| 31 | +package in \LaTeX3 Programming Layer to parse and highlight source codes and demos. |
| 32 | +It is more powerful than \verb!listings! package, and more easy to use than \verb!minted! package. |
| 33 | +But it is slower than both of them. |
| 34 | +Therefore in LuaTeX the package provides another way to highlight code: using \verb!LPeg!% |
| 35 | +\footnote{\url{http://www.inf.puc-rio.br/~roberto/lpeg/}}. |
| 36 | +\verb!LPeg! is much more powerful and faster than \verb!l3regex!. |
| 37 | + |
29 | 38 | At present, this package is in \underline{\color{red3}\textbf{experimental}} status.
|
30 | 39 | Don’t use it in important documents, unless you have time
|
31 | 40 | to update them for the newer versions of \verb!codehigh! package in the future.
|
32 | 41 |
|
33 |
| -\bigskip |
34 |
| -\hrule |
35 |
| -\bigskip |
| 42 | +\section{Highlighting Code} |
36 | 43 |
|
37 |
| -The following is typeset with \verb!verbatim! environment. |
| 44 | +There are several predefined languages: \verb!latex!, \verb!latex/latex2!, \verb!latex/latex3!, |
| 45 | +\verb!latex/math! and \verb!latex/table!. |
| 46 | +The following example is typeset by \verb!codehigh! environment with default option \verb!language=latex!. |
| 47 | +\begin{codehigh} |
| 48 | +% -*- coding: utf-8 -*- |
| 49 | +\documentclass{article} |
| 50 | +\usepackage[a4paper,margin=2cm]{geometry} |
| 51 | +\usepackage{codehigh} |
| 52 | +\usepackage{hyperref} |
| 53 | +\newcommand*{\myversion}{2021C} |
| 54 | +\newcommand*{\mydate}{Version \myversion\ (\the\year-\mylpad\month-\mylpad\day)} |
| 55 | +\newcommand*{\mylpad}[1]{\ifnum#1<10 0\the#1\else\the#1\fi} |
| 56 | +\setlength{\abc}{1} |
| 57 | +\begin{document} |
| 58 | +% some comment |
| 59 | +\section{Section Name} |
| 60 | +\subsection*{Suction Name} |
| 61 | +Math $a+b$. |
| 62 | +\end{document} |
| 63 | +\end{codehigh} |
| 64 | + |
| 65 | +The following example is typeset by \verb!codehigh! environment with option \verb!language=latex/latex2!. |
| 66 | +\begin{codehigh}[language=latex/latex2] |
| 67 | +\def\abcd#1#2{ |
| 68 | + % some comment |
| 69 | + \unskip |
| 70 | + \setlength{\parindent}{0pt}% |
| 71 | + \setlength{\parskip}{0pt}% |
| 72 | + \setcounter{choice}{0}% |
| 73 | + \let\item=\my@item@temp |
| 74 | + \settowidth{\my@item@len}{\vbox{\halign{##1\hfil\cr\BODY\crcr}}}% |
| 75 | + \setcounter{choice}{0}% |
| 76 | +} |
| 77 | +\end{codehigh} |
| 78 | +This language is for highlighting LaTeX2 classes and packages. |
| 79 | +Note that private commands and public commands are highlighted with different colors. |
| 80 | + |
| 81 | +The following example is typeset by \verb!codehigh! environment with option \verb!language=latex/latex3!. |
| 82 | +\begin{codehigh}[language=latex/latex3] |
| 83 | +\cs_new_protected:Npn \__codehigh_typeset_demo: |
| 84 | + { |
| 85 | + \__codehigh_build_code: |
| 86 | + \__codehigh_build_demo: |
| 87 | + \dim_set:Nn \l_tmpa_dim { \box_wd:N \g__codehigh_code_box } |
| 88 | + \dim_set:Nn \l_tmpb_dim { \box_wd:N \g__codehigh_demo_box } |
| 89 | + \par\addvspace{0.5em}\noindent |
| 90 | + % more code |
| 91 | + } |
| 92 | +\end{codehigh} |
| 93 | +This language is for highlighting LaTeX3 classes and packages. |
| 94 | +Note that private commands/variables and public commands/variables are highlighted with different colors. |
| 95 | + |
| 96 | +The following example is typeset by \verb!codehigh! environment with option \verb!language=latex/math!. |
| 97 | +\begin{codehigh}[language=latex/math] |
| 98 | +\begin{align} |
| 99 | + \pi\left[\frac13z^3\right]\sin(2x+1)_0^4 = \frac{64}{3}\pi |
| 100 | +\end{align} |
| 101 | +\end{codehigh} |
38 | 102 |
|
39 |
| -\begin{verbatim} |
| 103 | +The following example is typeset by \verb!codehigh! environment with option \verb!language=latex/table!. |
| 104 | +\begin{codehigh}[language=latex/table] |
40 | 105 | \begin{tabular}[b]{|lc|r|}
|
41 | 106 | \hline
|
42 |
| -One & Two & Three \\ %[4pt] |
| 107 | +One & Two & Three \\ |
43 | 108 | %\hline
|
44 | 109 | Four & Five & Six \\
|
45 | 110 | \hline%\hline\hline
|
46 |
| -Seven & Eight & Nine \\ %* [1em] |
| 111 | +Seven & Eight & Nine \\ |
47 | 112 | \hline
|
48 | 113 | \end{tabular}
|
49 |
| -\end{verbatim} |
| 114 | +\end{codehigh} |
50 | 115 |
|
51 |
| -\medskip |
52 |
| -The following is typeset with \verb!codehigh! environment. |
| 116 | +\section{Highlighting Demo} |
53 | 117 |
|
54 |
| -\begin{codehigh} |
55 |
| -\begin{tabular}[b]{|lc|r|} |
| 118 | +The followings are typeset by \verb!demohigh! environment with option \verb!language=latex/table!. |
| 119 | +\begin{demohigh}[language=latex/table] |
| 120 | +\begin{tabular}{lccr} |
56 | 121 | \hline
|
57 |
| -One & Two & Three \\ %[4pt] |
58 |
| -%\hline |
59 |
| -Four & Five & Six \\ |
60 |
| -\hline%\hline\hline |
61 |
| -Seven & Eight & Nine \\ %* [1em] |
| 122 | + Alpha & Beta & Gamma & Delta \\ |
| 123 | +\hline |
| 124 | + Epsilon & Zeta & Eta & Theta \\ |
| 125 | +\hline |
| 126 | + Iota & Kappa & Lambda & Mu \\ |
| 127 | +\hline |
| 128 | +\end{tabular} |
| 129 | +\end{demohigh} |
| 130 | +\begin{demohigh}[language=latex/table] |
| 131 | +\begin{tabular}{llccrr} |
| 132 | +\hline |
| 133 | + Alpha & Beta & Gamma & Delta & Epsilon & Zeta \\ |
| 134 | +\hline |
| 135 | + Eta & Theta & Iota & Kappa & Lambda & Mu \\ |
62 | 136 | \hline
|
63 | 137 | \end{tabular}
|
| 138 | +\end{demohigh} |
| 139 | +Note that \verb!demohigh! environment will measure the width of source lines. |
| 140 | +When it is too large, the result will be put below. |
| 141 | + |
| 142 | +\section{Highlighting File} |
| 143 | + |
| 144 | +Using \verb!\dochighinput! command, you can input and highlight some file. |
| 145 | +The last chapter of this manual is typeset with the following code line: |
| 146 | +\begin{codehigh} |
| 147 | +\dochighinput[language=latex/latex3]{codehigh.sty} |
64 | 148 | \end{codehigh}
|
65 | 149 |
|
66 |
| -\medskip |
67 |
| -The following is typeset with \verb!demohigh! environment. |
| 150 | +\section{Customization} |
68 | 151 |
|
| 152 | +The following example changes default background colors with \verb!\CodeHigh! command: |
| 153 | +\begin{codehigh} |
| 154 | +\CodeHigh{language=latex/table,style/main=yellow9,style/code=red9,style/demo=azure9} |
| 155 | +\end{codehigh} |
| 156 | +\CodeHigh{language=latex/table,style/main=yellow9,style/code=red9,style/demo=azure9} |
| 157 | +Note that \verb!codehigh! package will load \verb!ninecolors!% |
| 158 | +\footnote{\url{https://www.ctan.org/pkg/ninecolors}} package for proper color contrast. |
69 | 159 | \begin{demohigh}
|
70 |
| -\begin{tabular}[b]{|lc|r|} |
| 160 | +\begin{tabular}{lccr} |
71 | 161 | \hline
|
72 |
| -One & Two & Three \\ %[4pt] |
73 |
| -%\hline |
74 |
| -Four & Five & Six \\ |
75 |
| -\hline%\hline\hline |
76 |
| -Seven & Eight & Nine \\ %* [1em] |
| 162 | + Alpha & Beta & Gamma & Delta \\ |
| 163 | +\hline |
| 164 | + Epsilon & Zeta & Eta & Theta \\ |
| 165 | +\hline |
| 166 | + Iota & Kappa & Lambda & Mu \\ |
77 | 167 | \hline
|
78 | 168 | \end{tabular}
|
79 | 169 | \end{demohigh}
|
80 | 170 |
|
81 |
| -\medskip |
82 |
| -Please read the source file \verb!codehigh.tex! of this document for reference. |
| 171 | +To modify or add languages and themes, please read the source files |
| 172 | +\verb!codehigh.sty! and \verb!codehigh.lua! for reference. |
| 173 | + |
| 174 | +\chapter{Source Code} |
| 175 | + |
| 176 | +\dochighinput[language=latex/latex3]{codehigh.sty} |
83 | 177 |
|
84 | 178 | \end{document}
|
0 commit comments