diff options
author | Karl Berry <karl@freefriends.org> | 2023-02-11 21:16:41 +0000 |
---|---|---|
committer | Karl Berry <karl@freefriends.org> | 2023-02-11 21:16:41 +0000 |
commit | f9e3b88ca0a578b474fab0440a030136f034ab2e (patch) | |
tree | 62948f912e8aa0353fda5787b73bbc89cc5e4e77 /Master/texmf-dist | |
parent | 28c6dbff46efa29add42b37b26f7c7cf7b51199e (diff) |
codehigh (11feb23)
git-svn-id: svn://tug.org/texlive/trunk@65787 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist')
-rw-r--r-- | Master/texmf-dist/doc/latex/codehigh/codehigh.pdf | bin | 119611 -> 125913 bytes | |||
-rw-r--r-- | Master/texmf-dist/doc/latex/codehigh/codehigh.tex | 59 | ||||
-rw-r--r-- | Master/texmf-dist/tex/latex/codehigh/codehigh.sty | 38 |
3 files changed, 94 insertions, 3 deletions
diff --git a/Master/texmf-dist/doc/latex/codehigh/codehigh.pdf b/Master/texmf-dist/doc/latex/codehigh/codehigh.pdf Binary files differindex 088eb890e81..21c152b571d 100644 --- a/Master/texmf-dist/doc/latex/codehigh/codehigh.pdf +++ b/Master/texmf-dist/doc/latex/codehigh/codehigh.pdf diff --git a/Master/texmf-dist/doc/latex/codehigh/codehigh.tex b/Master/texmf-dist/doc/latex/codehigh/codehigh.tex index c3bddd46329..5f1e0295e75 100644 --- a/Master/texmf-dist/doc/latex/codehigh/codehigh.tex +++ b/Master/texmf-dist/doc/latex/codehigh/codehigh.tex @@ -2,7 +2,7 @@ \documentclass[oneside]{book} \usepackage[a4paper,margin=2cm]{geometry} -\newcommand*{\myversion}{2022E} +\newcommand*{\myversion}{2023A} \newcommand*{\mydate}{Version \myversion\ (\the\year-\mylpad\month-\mylpad\day)} \newcommand*{\mylpad}[1]{\ifnum#1<10 0\the#1\else\the#1\fi} @@ -16,6 +16,7 @@ urlcolor=blue3, linkcolor=green3, } +\usepackage{tabularx,booktabs} \begin{document} @@ -177,6 +178,62 @@ Note that \verb!codehigh! package will load \verb!ninecolors!% To modify or add languages and themes, please read the source files \verb!codehigh.sty! and \verb!codehigh.lua! for reference. +\section{Fake Verbatim Command} + +\CodeHigh{language=latex/table,style/main=gray9,style/code=gray9,style/demo=white} + +To ease the pain of writing verbatim commands +(such as in \verb|tabularx| and \verb|tabularray| tables), +This package provides \verb|\fakeverb| command. + +This command will remove the backslashes in the following control symbols +before typesetting its content: + +\renewcommand\arraystretch{1.3} +\begin{center} +\begin{tabularx}{0.9\linewidth}{llX} +\toprule +Input & Result & Remark \\ +\midrule +\fakeverb{\\\\} & \fakeverb{\\} & + Need to be escaped only when typesetting other control symbols in this table \\ +\fakeverb{\\\{} & \fakeverb{\{} & + Need to be escaped only when left and right curly braces are unmatched \\ +\fakeverb{\\\}} & \fakeverb{\}} & + Need to be escaped only when left and right curly braces are unmatched \\ +\fakeverb{\\\#} & \fakeverb{\#} & + Always need to be escaped \\ +\fakeverb{\\\^} & \fakeverb{\^} & + Need to be escaped only when there are more than one in a row \\ +\texttt{\textbackslash\textvisiblespace} & \texttt{\textvisiblespace} & + Need to be escaped only when more than one in a row or after control words \\ +\fakeverb{\\\%} & \fakeverb{\%} & + Always need to be escaped \\ +\bottomrule +\end{tabularx} +\end{center} + +The argument of \verb|\fakeverb| command need to be enclosed with curly braces. +Therefore it could be safely used inside \verb|tabularray| tables and other LaTeX commands. + +Here is an example of using \verb!\fakeverb! commands inside \verb|tabularx| environment: + +\begin{demohigh}[language=latex/table] +\begin{tabularx}{0.5\textwidth}{lX} +\hline + Alpha & \fakeverb{\abc{}$&^_^uvw 123} \\ +\hline + Beta & \fakeverb{\bfseries\ \#\%} \\ +\hline +\end{tabularx} +\end{demohigh} + +Here is another example of using \verb!\fakeverb! commands inside \verb|\fbox| command: + +\begin{demohigh}[language=latex/latex2] +Hello\fbox{\fakeverb{$\left\\\{A\right.$\#}}Verb! +\end{demohigh} + \chapter{The Source Code} \dochighinput[language=latex/latex3]{codehigh.sty} diff --git a/Master/texmf-dist/tex/latex/codehigh/codehigh.sty b/Master/texmf-dist/tex/latex/codehigh/codehigh.sty index d9bfaec0e7c..62438d7dac1 100644 --- a/Master/texmf-dist/tex/latex/codehigh/codehigh.sty +++ b/Master/texmf-dist/tex/latex/codehigh/codehigh.sty @@ -12,11 +12,11 @@ \NeedsTeXFormat{LaTeX2e} \RequirePackage{expl3} -\ProvidesExplPackage{codehigh}{2022-04-29}{2022E} +\ProvidesExplPackage{codehigh}{2023-02-11}{2023A} {Highlight codes and demos with l3regex and lpeg} %\RequirePackage{xparse} -\RequirePackage{l3benchmark} +%\RequirePackage{l3benchmark} \RequirePackage{catchfile} \RequirePackage{xcolor} \RequirePackage{ninecolors} @@ -600,6 +600,40 @@ } %%% ------------------------------------------------------- +%%> \section{Fake Verbatim Command} +%%% ------------------------------------------------------- + +\tl_new:N \l__codehigh_fake_code_tl + +\NewDocumentCommand \fakeverb { +m } + { + \group_begin: + \tl_set:Nn \l__codehigh_fake_code_tl {#1} + \__codehigh_fake_verb:N \l__codehigh_fake_code_tl + \group_end: + } + +\cs_new_protected:Npn \__codehigh_fake_verb:N #1 + { + \regex_replace_all:nnN { \c{\\} } { \\ } #1 + % use \cO to avoid errors of unmatched braces + \regex_replace_all:nnN { \c{\{} } { \cO\{ } #1 + \regex_replace_all:nnN { \c{\}} } { \cO\} } #1 + % use \cO to avoid doubled hash characters + \regex_replace_all:nnN { \c{\#} } { \cO\# } #1 + % need to escape ^ because ^^ and ^^^^ are special + \regex_replace_all:nnN { \c{\^} } { \^ } #1 + % why we can not use \c{\ } instead of \c{\h}? + \regex_replace_all:nnN { \c{\h} } { \ } #1 + \regex_replace_all:nnN { \c{\%} } { \% } #1 + % remove spaces after control words + \regex_replace_all:nnN { . } { \c{string}\0 } #1 + \tl_set:Ne #1 { #1 } + %\tl_log:N #1 + \ttfamily \frenchspacing \tl_to_str:N #1 + } + +%%% ------------------------------------------------------- %%> \section{Tracing CodeHigh} %%% ------------------------------------------------------- |