Skip to content

Commit cbf31da

Browse files
committed
update manual
1 parent 8394266 commit cbf31da

File tree

1 file changed

+131
-37
lines changed

1 file changed

+131
-37
lines changed

codehigh.tex

+131-37
Original file line numberDiff line numberDiff line change
@@ -1,84 +1,178 @@
11
% -*- coding: utf-8 -*-
2-
\documentclass{article}
2+
\documentclass[oneside]{book}
33
\usepackage[a4paper,margin=2cm]{geometry}
44

55
\usepackage{codehigh}
6-
%\usepackage{arev}
76
\usepackage{hyperref}
87
\hypersetup{
98
colorlinks=true,
109
urlcolor=blue3,
10+
linkcolor=green3,
1111
}
1212

1313
\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)}
1515
\newcommand*{\mylpad}[1]{\ifnum#1<10 0\the#1\else\the#1\fi}
1616

1717
\begin{document}
1818

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}}
2221
\date{\mydate}
2322
\maketitle
2423

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+
2938
At present, this package is in \underline{\color{red3}\textbf{experimental}} status.
3039
Don’t use it in important documents, unless you have time
3140
to update them for the newer versions of \verb!codehigh! package in the future.
3241

33-
\bigskip
34-
\hrule
35-
\bigskip
42+
\section{Highlighting Code}
3643

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}
38102

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]
40105
\begin{tabular}[b]{|lc|r|}
41106
\hline
42-
One & Two & Three \\ %[4pt]
107+
One & Two & Three \\
43108
%\hline
44109
Four & Five & Six \\
45110
\hline%\hline\hline
46-
Seven & Eight & Nine \\ %* [1em]
111+
Seven & Eight & Nine \\
47112
\hline
48113
\end{tabular}
49-
\end{verbatim}
114+
\end{codehigh}
50115

51-
\medskip
52-
The following is typeset with \verb!codehigh! environment.
116+
\section{Highlighting Demo}
53117

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}
56121
\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 \\
62136
\hline
63137
\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}
64148
\end{codehigh}
65149

66-
\medskip
67-
The following is typeset with \verb!demohigh! environment.
150+
\section{Customization}
68151

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.
69159
\begin{demohigh}
70-
\begin{tabular}[b]{|lc|r|}
160+
\begin{tabular}{lccr}
71161
\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 \\
77167
\hline
78168
\end{tabular}
79169
\end{demohigh}
80170

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}
83177

84178
\end{document}

0 commit comments

Comments
 (0)