From 43f963c6e7c57e4278ebb7644cef82b408d66f95 Mon Sep 17 00:00:00 2001 From: Karl Berry Date: Sun, 14 Jul 2019 20:48:21 +0000 Subject: pseudo (14jul19) git-svn-id: svn://tug.org/texlive/trunk@51641 c570f23f-e606-0410-a88d-b1316a301751 --- Master/texmf-dist/doc/latex/pseudo/Makefile | 21 +- Master/texmf-dist/doc/latex/pseudo/README.md | 94 +++++ Master/texmf-dist/doc/latex/pseudo/VERSION | 2 +- .../doc/latex/pseudo/doc/fig/hilitefig.tex | 2 +- .../texmf-dist/doc/latex/pseudo/doc/fig/kwfig.tex | 28 ++ .../doc/latex/pseudo/doc/fig/pausefig.tex | 2 +- .../doc/latex/pseudo/doc/fig/readmecode.tex | 15 + .../doc/latex/pseudo/doc/fig/readmefig.svg | 411 +++++++++++++++++++++ .../doc/latex/pseudo/doc/fig/readmefig.tex | 16 + Master/texmf-dist/doc/latex/pseudo/doc/pseudo.pdf | Bin 528156 -> 555540 bytes Master/texmf-dist/doc/latex/pseudo/doc/pseudo.tex | 113 +++++- 11 files changed, 698 insertions(+), 6 deletions(-) create mode 100644 Master/texmf-dist/doc/latex/pseudo/doc/fig/kwfig.tex create mode 100644 Master/texmf-dist/doc/latex/pseudo/doc/fig/readmecode.tex create mode 100644 Master/texmf-dist/doc/latex/pseudo/doc/fig/readmefig.svg create mode 100644 Master/texmf-dist/doc/latex/pseudo/doc/fig/readmefig.tex (limited to 'Master/texmf-dist/doc') diff --git a/Master/texmf-dist/doc/latex/pseudo/Makefile b/Master/texmf-dist/doc/latex/pseudo/Makefile index 8b649a353f4..388a7bea2f9 100644 --- a/Master/texmf-dist/doc/latex/pseudo/Makefile +++ b/Master/texmf-dist/doc/latex/pseudo/Makefile @@ -1,5 +1,9 @@ +TARGETS=doc/pseudo.pdf doc/fig/readmefig.svg + LATEX=latexmk -norc -pdf -auxdir=build -outdir=build -FIGS=build/hilitefig.pdf build/pausefig.pdf +FIGS=build/hilitefig.pdf build/pausefig.pdf build/kwfig.pdf + +all: $(TARGETS) doc/pseudo.pdf: build/pseudo.pdf cp $< $@ @@ -16,6 +20,9 @@ build/hilitefig.pdf: doc/fig/hilitefig.tex pseudo.sty build/pausefig.pdf: doc/fig/pausefig.tex pseudo.sty $(LATEX) $< +build/kwfig.pdf: doc/fig/kwfig.tex pseudo.sty + $(LATEX) $< + pseudo.sty: VERSION LICENSE doc/pseudo.tex cat LICENSE | sed -e "s/^/% /" | sed -e "s/^% \$$/%/" > pseudo.sty echo "%" >> pseudo.sty @@ -31,3 +38,15 @@ pseudo.sty: VERSION LICENSE doc/pseudo.tex -e "/^\$$/d" \ -e "p" \ -e "}" >> pseudo.sty + +build/readmecode.tex: doc/fig/readmecode.tex + cp $< $@ + +build/readmefig.pdf: doc/fig/readmefig.tex build/readmecode.tex + $(LATEX) $< + +doc/fig/readmefig.svg: build/readmefig.pdf + pdf2svg $< $@ + +doc/fig/readmecode.tex: README.md + cat $< | sed -n -e "/\\begin{pseudo}\\*$$/,/\\end{pseudo}/p" > $@ diff --git a/Master/texmf-dist/doc/latex/pseudo/README.md b/Master/texmf-dist/doc/latex/pseudo/README.md index 5c175168fb7..90df5792f4e 100644 --- a/Master/texmf-dist/doc/latex/pseudo/README.md +++ b/Master/texmf-dist/doc/latex/pseudo/README.md @@ -1,3 +1,5 @@ +# pseudo.sty + The **pseudo** package permits writing pseudocode without much fuss and with quite a bit of configurability. Its main environment combines aspects of `enumeration`, `tabbing` and `tabular` for nonintrusive line numbering, @@ -6,3 +8,95 @@ common syntactic elements such as keywords, identifiers and comments. The package is written by [Magnus Lie Hetland](mailto:mlh@ntnu.no) and released under the [MIT license](LICENSE). + +## Using pseudo + +You can find more detailed instructions in [the +documentation](doc/pseudo.pdf), but it's really quite simple to get started. +The package is [available via CTAN](https://ctan.org/pkg/pseudo), and so is +part of several TeX distributions. If the newest version isn't in yours, try +to run an update. In TeX Live, for example, you could run use the [TeX Live +Utility](http://amaxwell.github.io/tlutility/) (part of distributions such as +[MacTeX](https://tug.org/mactex/)). Alternatively, you can just download the +[pseudo.sty](pseudo.sty) file and drop it where your `latex` can find it +(possibly just in the same directory as your document). + +Assuming you want numbered lines (the default) and have most text set as +keywords (set by the `kw` switch), you simply import **pseudo** using + +```tex +\usepackage[kw]{pseudo} +``` + +and then set your pseudocode in a `pseudo` environment. Lines are terminated +by the normal `\\` command, which may be extended with one or more pluses or +minuses to indicate a change in indentation level. You suppress the automatic +numbering of the following line using a star (i.e., either `\\*`, or +`\begin{pseudo}*`), and can typeset a procedure header using `\hd{Name}(...)`. +For [example](https://mipmip.org/tidbits/pasa.pdf): + +```tex +\begin{pseudo}* + + \hd{Backward}(V, E, v, i) \\ + + $v.\id{label} = i$ \\ + + for $(u,v)\in E$ \\+ + if $0 < v.\id{label} < i$ \\+ + \pr{Backward}(V, E, u, i) \\-- + + for $(u,v)\in E$ \\+ + if $u.\id{label} \== 0$ \\+ + \pr{Backward}(V, E, u, i+1) + +\end{pseudo} +``` + +This produces: + + + +There is also a starred version of the environment (`pseudo*`), which +is unnumbered. + +The commands `\pr` and `\id` indicate procedure calls and identifiers. +If we hadn't used the `kw` option, the main text would not be set as keywords, +but as plain text. We could then use `\kw` to mark up keywords. Some of these +may be used a lot, so I might want to declare a shortcut. For example, if +I use + +```tex +\DeclarePseudoKeyword \While {while} +``` + +I'd be able to use `\While` rather than `\kw{while}` later. Several such +formatting and declaration commands exist: + +| Type of text | Command | Declaration | +| ------------ | ------------------- | ----------------------------------------------- | +| Keywords | `\kw{while}` | `\DeclarePseudoKeyword \While {while}` | +| Constants | `\cn{false}` | `\DeclarePseudoConstant \False {false}` | +| Identifiers | `\id{rank}` | `\DeclarePseudoIdentifier \Rank {rank}` | +| Strings | `\st{Hello!}` | `\DeclarePseudoString \Hello {Hello!}` | +| Procedures | `\pr{Euclid}(a, b)` | `\DeclarePseudoProcedure \Euclid {Euclid}` | +| Functions | `\fn{length}(A)` | `\DeclarePseudoFunction \Length {length}` | +| Comments | `\ct{Important!}` | `\DeclarePseudoComment \Important {Important!}` | + +For normal text (e.g., when using the `kw` switch), there is also `\tn` (along +with `\DeclarePseudoNormal`). + +Since the short names of these commands are prone to collisions with other +packages, **pseudo** won't insist on using them. If you import **pseudo** +*after* some other package that already uses, say, `\id`, then **pseudo** +won't define it. All of these are still available with the `pseudo` prefix, +however (e.g., `\pseudoid`), and the declaration commands still work. + +Beyond the styling of text, there are also the `\==` and `\..` commands +(also written `\eqs` and `\dts`) for typesetting double equals sign and double +dots. + +This covers most of the core functionality, but there are also more obscure +features (such as dimming or highlighting lines) and a host of configuration +keys for getting the pseudocode looking more like you'd want it to. For +details, consult [the documentation](doc/pseudo.pdf). diff --git a/Master/texmf-dist/doc/latex/pseudo/VERSION b/Master/texmf-dist/doc/latex/pseudo/VERSION index 524cb55242b..45a1b3f4452 100644 --- a/Master/texmf-dist/doc/latex/pseudo/VERSION +++ b/Master/texmf-dist/doc/latex/pseudo/VERSION @@ -1 +1 @@ -1.1.1 +1.1.2 diff --git a/Master/texmf-dist/doc/latex/pseudo/doc/fig/hilitefig.tex b/Master/texmf-dist/doc/latex/pseudo/doc/fig/hilitefig.tex index 8cffae23a43..b0e9cf7780d 100644 --- a/Master/texmf-dist/doc/latex/pseudo/doc/fig/hilitefig.tex +++ b/Master/texmf-dist/doc/latex/pseudo/doc/fig/hilitefig.tex @@ -1,6 +1,6 @@ \documentclass[beamer,preview,multi]{standalone} \usepackage{pseudo} -\pseudoset{hpad, compact} +\pseudoset{hpad, compact, kwfont=\bfseries} \standaloneenv{myenv} diff --git a/Master/texmf-dist/doc/latex/pseudo/doc/fig/kwfig.tex b/Master/texmf-dist/doc/latex/pseudo/doc/fig/kwfig.tex new file mode 100644 index 00000000000..8d25a73a492 --- /dev/null +++ b/Master/texmf-dist/doc/latex/pseudo/doc/fig/kwfig.tex @@ -0,0 +1,28 @@ +\documentclass[beamer,preview,multi, border={-.14pt .14pt 0pt .03pt}]{standalone} + +% To silence the warning from the first execution of \kwfont, in this case: +\usepackage{silence} +\WarningFilter{latexfont}{Font shape} +\WarningFilter{latexfont}{Some font shapes} + +\usepackage{varwidth} + +\usepackage{pseudo} +\pseudoset{compact} + +\standaloneenv{myenv} + +\begin{document} + +% Contents duplicated from pseudo.doc: +\begin{standaloneframe} +\begin{myenv} +\begin{varwidth}{\linewidth} +\textbf{while}\\ % Extended +\kw{while}\\ % Keyword +{\fontseries{b}\selectfont while} % Non-extended +\end{varwidth} +\end{myenv} +\end{standaloneframe} + +\end{document} diff --git a/Master/texmf-dist/doc/latex/pseudo/doc/fig/pausefig.tex b/Master/texmf-dist/doc/latex/pseudo/doc/fig/pausefig.tex index bbc7ee91fd2..0e2645724d7 100644 --- a/Master/texmf-dist/doc/latex/pseudo/doc/fig/pausefig.tex +++ b/Master/texmf-dist/doc/latex/pseudo/doc/fig/pausefig.tex @@ -1,6 +1,6 @@ \documentclass[beamer,preview,multi]{standalone} \usepackage{pseudo} -\pseudoset{compact} +\pseudoset{compact, kwfont=\bfseries} \setbeamercovered{transparent} \standaloneenv{myenv} diff --git a/Master/texmf-dist/doc/latex/pseudo/doc/fig/readmecode.tex b/Master/texmf-dist/doc/latex/pseudo/doc/fig/readmecode.tex new file mode 100644 index 00000000000..9ad11a0aa91 --- /dev/null +++ b/Master/texmf-dist/doc/latex/pseudo/doc/fig/readmecode.tex @@ -0,0 +1,15 @@ +\begin{pseudo}* + + \hd{Backward}(V, E, v, i) \\ + + $v.\id{label} = i$ \\ + + for $(u,v)\in E$ \\+ + if $0 < v.\id{label} < i$ \\+ + \pr{Backward}(V, E, u, i) \\-- + + for $(u,v)\in E$ \\+ + if $u.\id{label} \== 0$ \\+ + \pr{Backward}(V, E, u, i+1) + +\end{pseudo} diff --git a/Master/texmf-dist/doc/latex/pseudo/doc/fig/readmefig.svg b/Master/texmf-dist/doc/latex/pseudo/doc/fig/readmefig.svg new file mode 100644 index 00000000000..0fc3a645a30 --- /dev/null +++ b/Master/texmf-dist/doc/latex/pseudo/doc/fig/readmefig.svg @@ -0,0 +1,411 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Master/texmf-dist/doc/latex/pseudo/doc/fig/readmefig.tex b/Master/texmf-dist/doc/latex/pseudo/doc/fig/readmefig.tex new file mode 100644 index 00000000000..27a5778288a --- /dev/null +++ b/Master/texmf-dist/doc/latex/pseudo/doc/fig/readmefig.tex @@ -0,0 +1,16 @@ +\documentclass[preview,multi,12pt]{standalone} +\usepackage{adjustbox} +\usepackage[kw]{pseudo} +\pseudoset{compact} + +\standaloneenv{myenv} + +\begin{document} + +\begin{myenv} +\begin{adjustbox}{scale=1.25} +\input{readmecode} +\end{adjustbox} +\end{myenv} + +\end{document} diff --git a/Master/texmf-dist/doc/latex/pseudo/doc/pseudo.pdf b/Master/texmf-dist/doc/latex/pseudo/doc/pseudo.pdf index 4cdab2e88cf..3a92422f35e 100644 Binary files a/Master/texmf-dist/doc/latex/pseudo/doc/pseudo.pdf and b/Master/texmf-dist/doc/latex/pseudo/doc/pseudo.pdf differ diff --git a/Master/texmf-dist/doc/latex/pseudo/doc/pseudo.tex b/Master/texmf-dist/doc/latex/pseudo/doc/pseudo.tex index a93daee46db..9148d16289c 100644 --- a/Master/texmf-dist/doc/latex/pseudo/doc/pseudo.tex +++ b/Master/texmf-dist/doc/latex/pseudo/doc/pseudo.tex @@ -28,6 +28,10 @@ \let\origbfseries\bfseries \def\bfseries{\fontseries{b}\selectfont} +\let\origtt\texttt +\def\texttt#1{\textnormal{\origtt{#1}}} +% Still getting warnings about OT1/cmtt/b/n ... + \usepackage{tikz} \usetikzlibrary{matrix,calc,decorations.pathreplacing,calligraphy} \tikzset{ @@ -290,7 +294,16 @@ \ior_map_inline:Nn \g_tmpa_ior { - % Just using the first paragraph + % Skip the first paragraph + \regex_match:nnT { ##1 } { \c{par} } { + \ior_map_break: + } + + } + + \ior_map_inline:Nn \g_tmpa_ior { + + % Just using the next paragraph \regex_match:nnTF { ##1 } { \c{par} } { \ior_map_break: } { @@ -1556,10 +1569,66 @@ vs.\ foo \kw{bar} \end{pseudo*} \end{texexp} + The initial value isn't \emph{quite} as straightforward as indicated, + however. + For more info, see \refc{kwfont}. \end{docKey} \begin{docCommand}{kwfont}{} + \parindent1.5em + \noindent \fontcmd{kw} + Its initial definition is \emph{essentially} + \code{\cs{fontseries}\braces{b}\cs{selectfont}}, except the first time + it's called (normally when evaluating the initial value of + \refk{indent-text}), it also runs a check to see if the font selection + \emph{worked}, as in some cases (such as in a default + \pkg[https://ctan.org/pkg/beamer]{beamer} presentation), the non-extended + bold may not be available. In that case, it defaults to an extended bold + (\cs{bfseries}) instead. At this point, the command is redefined to + \code{\cs{fontseries}\braces{b}\cs{selectfont}} or \cs{bfseries}, as + appropriate (i.e., without this check). So, while + \code{\refc{kw}\braces{hello}} produces the non-extended \kw{hello} in a + default \LaTeX\ document, it yields the extended {\origbfseries\sffamily + hello} in a default \pkg[https://ctan.org/pkg/beamer]{beamer} + presentation. Perhaps more clearly, this is the result in plain \LaTeX\ + (using \pkg[https://ctan.org/tex-archive/info/lmodern]{lmodern}): + +{\let\bfseries\origbfseries +\begin{texexp} +\textbf{while}\\ % Extended +\kw{while}\\ % Keyword +{\fontseries{b}\selectfont while} % Non-extended +\end{texexp} +}\ignorespaces\par + + \noindent + The same code results in the the following in + \pkg[https://ctan.org/pkg/beamer]{beamer}: + + \medskip\noindent + \includegraphics{kwfig} + + \medskip\noindent + You'll also get a font warning,\footnote{Of course, if you use a different + font or theme, e.g., with the \pkg[https://ctan.org/pkg/beamer]{beamer} + command \code{\cs{usefonttheme}\braces{serif}}, you may not have any issues to + begin with.} though only once, as it's suppressed after the first occurrence, + so the fact that the font selection doesn't work on the last line isn't + reported. Note, however, that the current implementation of \refc{kwfont} + actually \emph{piggybacks} on this warning to determine if the non-extended + bold is available. This means that if you've tried (and failed) to use + \code{\cs{fontseries}\braces{b}} \emph{before} the fist use of \refc{kwfont}, + the fallback (i.e., extended bold) won't be triggered. + + Also note that \refk{indent-text} (which will tend to be the first + occurrence use of \refc{kwfont}) won't be evaluated (to determine + \refk{indent-length}) until you actually start a \refe{pseudo} + environment, so if you're \emph{aware} that you don't have non-extended + bold available, and you set \code*{\refk{kwfont} = \cs{bfseries}}, for + example, there will be no attempt to use the non-extended version, and you + won't get the font warning that the default implementation produces in + that case. \end{docCommand} \begin{docKey}{label}{\,=\,\meta{commands}}{% @@ -2612,7 +2681,10 @@ which the current line is indented. The initial indent level may be set using variants we'll need of some standard commands: \begin{source} \cs_generate_variant:Nn \tl_if_novalue:nTF { VTF } +\cs_generate_variant:Nn \tl_set:Nn { Ne } \cs_generate_variant:Nn \regex_extract_once:nnNTF { nVNTF } +% \cs_generate_variant:Nn \regex_match:nnF { nVF } +\cs_generate_variant:Nn \regex_match:nnF { neF } \end{source} \paragraph{Defining columns.} The \refk{preamble} is is configurable, but the \pkg[https://ctan.org/pkg/array]{array} package makes sure it doesn't expand @@ -2822,6 +2894,43 @@ commands: (As a side-effect, we've now also defined \cs{pseudonf} and \cs{pseudotn}, which we don't really need.) % +While we're at it, we'll define the initial value for \refc{kwfont}, which is +generally non-extended bold, if that's available, but extended bold otherwise: +\begin{source} +\cs_new:Nn \@@_b_or_bx: { + + % Note: We're relying on the warning text in \@defaultsubs + % being defined by \selectfont if the desired font isn't + % found. This won't happen, however, if the same + % \curr@fontshape combination has been attempted before + % (cf. source2e.pdf page 179). + + \group_begin: + + \cs_if_exist:NT \@defaultsubs { + \@@_gsave_as:NN \@defaultsubs \@@_defaultsubs + \cs_gset_eq:NN \@defaultsubs \relax + } + + % This is what we'd like: + \cs_gset:Nn \@@_b_or_bx: { \fontseries{b}\selectfont } + + % Try it: + \@@_b_or_bx: + + % Fallback, if that failed: + \cs_if_exist:NT \@defaultsubs { + \cs_gset_eq:NN \@@_b_or_bx: \bfseries + \group_insert_after:N \@@_b_or_bx: + } + + \group_end: + +} +\end{source} +Note that the command redefines itself after the first use, so as not to +execute the check every time. + The \refc{pr} command is also a font shortcut, but in addition takes optional parenthesis-delimited arguments, which are set in math mode: \begin{source} @@ -3053,7 +3162,7 @@ typesetting the pseudocode. indent-level .int_set:N = \l_@@_initial_indent_level_int, kwfont .tl_set:N = \kwfont, - kwfont .initial:n = \fontseries{b}\selectfont, + kwfont .initial:n = \@@_b_or_bx:, kw .meta:n = { font = \kwfont }, kw .value_forbidden:n = true, -- cgit v1.2.3