diff options
Diffstat (limited to 'Master')
-rw-r--r-- | Master/texmf-dist/doc/luatex/nodetree/README.md | 63 | ||||
-rw-r--r-- | Master/texmf-dist/doc/luatex/nodetree/nodetree.pdf | bin | 396294 -> 357181 bytes | |||
-rw-r--r-- | Master/texmf-dist/source/luatex/nodetree/nodetree.dtx | 2007 | ||||
-rw-r--r-- | Master/texmf-dist/source/luatex/nodetree/nodetree.ins | 10 | ||||
-rw-r--r-- | Master/texmf-dist/tex/luatex/nodetree/nodetree-embed.sty | 183 | ||||
-rw-r--r-- | Master/texmf-dist/tex/luatex/nodetree/nodetree.lua | 1747 | ||||
-rw-r--r-- | Master/texmf-dist/tex/luatex/nodetree/nodetree.sty | 29 | ||||
-rw-r--r-- | Master/texmf-dist/tex/luatex/nodetree/nodetree.tex | 30 |
8 files changed, 1810 insertions, 2259 deletions
diff --git a/Master/texmf-dist/doc/luatex/nodetree/README.md b/Master/texmf-dist/doc/luatex/nodetree/README.md index 2b92a67fa21..7f21098f113 100644 --- a/Master/texmf-dist/doc/luatex/nodetree/README.md +++ b/Master/texmf-dist/doc/luatex/nodetree/README.md @@ -1,4 +1,3 @@ - ![nodetree](https://raw.githubusercontent.com/Josef-Friedrich/nodetree/master/graphics/packagename.png) # Abstract @@ -19,7 +18,7 @@ terminal to generate the document. # License -Copyright (C) 2016 by Josef Friedrich <josef@friedrich.rocks> +Copyright (C) 2016-2020 by Josef Friedrich <josef@friedrich.rocks> ------------------------------------------------------------------------ This work may be distributed and/or modified under the conditions of the LaTeX Project Public License, either version 1.3 of this license @@ -102,3 +101,63 @@ Office ![nodetree](https://raw.githubusercontent.com/Josef-Friedrich/nodetree/master/graphics/ligatures.png) +# Development + +First delete the stable version installed by TeX Live. Because the +package `nodetree` belongs to the collection `collection-latexextra`, the +option `--force` must be used to delete the package. + + tlmgr remove --force nodetree + +## Deploying a new version + +Update the version number in the file `nodetree.dtx` on this locations: + +### In the markup for the file `nodetree.sty` (approximately at the line number 30) + + %<*package> + [2016/07/18 v1.2 Visualize node lists in a tree view] + %<*package> + +### In the markup for the file `nodetree-embed.sty` (approximately at the line number 220) + + %<*package> + [2016/07/18 v1.2 Visualize node lists in a tree view] + %<*package> + +### In the markup for the package documentation (approximately at the line number 50) + +Add a changes entry: + +```latex +\changes{v1.2}{2020/05/20}{...} +``` + +### In documentation (documentation.tex) (approximately at the line number 70) + +```latex +\date{v2.0 from 2020/05/29} +``` + +### In the file `nodetree.lua` (approximately at the line number 20) + +```lua +if not modules then modules = { } end modules ['nodetree'] = { + version = '1.2' +} +``` + +### Update the copyright year: + +``` +sed -i 's/(C) 2016-2020/(C) 2016-2021/g' nodetree.ins +sed -i 's/(C) 2016-2020/(C) 2016-2021/g' nodetree.dtx +``` + +### Command line tasks: + +``` +git tag -a v1.4 +make +make ctan +``` diff --git a/Master/texmf-dist/doc/luatex/nodetree/nodetree.pdf b/Master/texmf-dist/doc/luatex/nodetree/nodetree.pdf Binary files differindex 0ea7228abea..c7cdf1d72c1 100644 --- a/Master/texmf-dist/doc/luatex/nodetree/nodetree.pdf +++ b/Master/texmf-dist/doc/luatex/nodetree/nodetree.pdf diff --git a/Master/texmf-dist/source/luatex/nodetree/nodetree.dtx b/Master/texmf-dist/source/luatex/nodetree/nodetree.dtx index 24416e17ced..5b18176843b 100644 --- a/Master/texmf-dist/source/luatex/nodetree/nodetree.dtx +++ b/Master/texmf-dist/source/luatex/nodetree/nodetree.dtx @@ -1,6 +1,6 @@ % \iffalse meta-comment % -% Copyright (C) 2016 by Josef Friedrich <josef@friedrich.rocks> +% Copyright (C) 2016-2020 by Josef Friedrich <josef@friedrich.rocks> % ---------------------------------------------------------------------- % This work may be distributed and/or modified under the conditions of % the LaTeX Project Public License, either version 1.3 of this license @@ -28,648 +28,8 @@ %<package>\NeedsTeXFormat{LaTeX2e}[1999/12/01] %<package>\ProvidesPackage{nodetree} %<*package> - [2016/07/18 v1.2 Visualize node lists in a tree view] + [2020/05/29 v2.0 Visualize node lists in a tree view] %</package> -%<*driver> -\documentclass{ltxdoc} -\usepackage{paralist,fontspec,graphicx,fancyvrb} -\usepackage[ - colorlinks=true, - linkcolor=red, - filecolor=red, - urlcolor=red, -]{hyperref} -%\usepackage{nodetree} -\EnableCrossrefs -\CodelineIndex -\RecordChanges - -\setmonofont{DejaVu Sans Mono} - -\def\nodetreelua#1{\texttt{\scantokens{\catcode`\_=12\relax#1}}} - -\def\secref#1{(\rightarrow\ \ref{#1})} - -\newcommand{\tmpgraphics}[1]{ - \noindent - \includegraphics[scale=0.4]{graphics/#1} -} - -\DefineVerbatimEnvironment{code}{Verbatim} -{ - frame=single, - fontsize=\footnotesize, -} - -\begin{document} - -\providecommand*{\url}{\texttt} -\GetFileInfo{nodetree.dtx} -\title{The \textsf{nodetree} package} -\author{% - Josef Friedrich\\% - \url{josef@friedrich.rocks}\\% - \href{https://github.com/Josef-Friedrich/nodetree}{github.com/Josef-Friedrich/nodetree}% -} -\date{\fileversion~from \filedate} - -\maketitle - -\noindent -\includegraphics[width=\linewidth]{graphics/packagename} - -\newpage - -\tableofcontents - -\newpage - -%----------------------------------------------------------------------- -% Abstract -%----------------------------------------------------------------------- - -\section{Abstract} - -|nodetree| is a development package that visualizes the structure of -node lists. |nodetree| shows its debug informations in the consoles’ -output when you compile a Lua\TeX{} file. It uses a similar visual -representation for node lists as the UNIX |tree| command uses for a -folder structure. - -Node lists are the main building blocks of each document generated by -the \TeX{} engine \emph{Lua\TeX}. The package |nodetree| doesn‘t change -the rendered document. The tree view can only be seen when using a -terminal to generate the document. - -|nodetree| is inspired by a -\href{https://gist.github.com/pgundlach/556247} -{gist from Patrick Gundlach}. - -%----------------------------------------------------------------------- -% Usage -%----------------------------------------------------------------------- - -\section{Usage} - -The package |nodetree| can be used both with Lua\TeX{} and Lua\LaTeX{}. -You have to use both engines in a text console. Run for example -|luatex luatex-test.tex| to list the nodes using Lua\TeX{}. - -\begin{code} -\input{nodetree.tex} -\nodetreeregister{postline} - -Lorem ipsum dolor. -\bye -\end{code} - -Or run |lualatex lualatex-test.tex| to show a node tree using -Lua\LaTeX{}. In Lua\LaTeX{} you can omit |\nodetreeregister{postline}|. -|\usepackage{nodetree}| registers automatically the -|post_linebreak_filter|. If you don’t want debug the -|post_linebreak_filter| use |\nodetreeunregister{postline}|. - -\begin{code} -\documentclass{article} -\usepackage{nodetree} - -\begin{document} -Lorem ipsum dolor. -\end{document} -\end{code} - -%% -% inside Lua code -%% - -\subsection{Debug nodes inside Lua code} - -Use the Lua function |nodetree.analyze(head)| to debug nodes inside your -Lua code. The following code snippet demonstrates the usage in Lua\TeX{}. -|head| is the current node. - -\begin{code} -\input{nodetree.tex} - -\directlua{ - local test = function (head) - nodetree.analyze(head) - end - callback.register('post_linebreak_filter', test) -} - -Lorem ipsum dolor. -\bye -\end{code} - -This example illustrates how the function has to be applied in -Lua\LaTeX{}. - -\begin{code} -\documentclass{article} -\usepackage{nodetree} - -\begin{document} - -\directlua{ - local test = function (head) - nodetree.analyze(head) - end - luatexbase.add_to_callback('post_linebreak_filter', test, 'test') -} - -Lorem ipsum dolor. -\end{document} -\end{code} - -%----------------------------------------------------------------------- -% Macros -%----------------------------------------------------------------------- - -\section{Macros} - -%% -% \nodetreeregister -%% - -\subsection{\cmd{\nodetreeregister}} - -\DescribeMacro{\nodetreeregister} -\cmd{\nodetreeregister}\marg{callbacks}: The argument \marg{callbacks} -takes a comma separated list of callback aliases as described in -\secref{sec:option-callback}. - -%% -% \nodetreeunregister -%% - -\subsection{\cmd{\nodetreeunregister}} - -\DescribeMacro{\nodetreeunregister} -\cmd{\nodetreeunregister}\marg{callbacks}: The argument \marg{callbacks} -takes a comma separated list of callback aliases as described in -\secref{sec:option-callback}. - -%% -% \nodetreeoption -%% - -\subsection{\cmd{\nodetreeoption}} - -\DescribeMacro{\nodetreeoption} -\cmd{\nodetreeoption}\oarg{option}\marg{value}: \secref{sec:options} -This macro sets the option \oarg{option} to the value \marg{value}. - -%% -% \nodetreeset -%% - -\subsection{\cmd{\nodetreeset}} - -\DescribeMacro{\nodetreeset} -\cmd{\nodetreeset}\marg{kv-options}: -This macro can only be used in Lua\LaTeX{}. \marg{kv-options} are key -value pairs. - -\begin{code} -\nodetreeset{color=no,callbacks={hpack,vpack},verbosity=2} -\end{code} - -%----------------------------------------------------------------------- -% Options -%----------------------------------------------------------------------- - -\section{Options} -\label{sec:options} - -%% -% callback -%% - -\subsection{Option \texttt{callback}} -\label{sec:option-callback} - -The option |callback| is the most important setting of the package. You -have to specify one alias to select the |callback|. Because of the -underscores the callback name contains it can not set by its technical -name (\rightarrow{} Figure \ref{fig:callback}). - -This macros process callback options: -\cmd{\nodetreeregister}\marg{callbacks}, -\cmd{\nodetreeunregister}\marg{callbacks}, -\cmd{\nodetreeset}\marg{callback=<callbacks>} and -\cmd{\usepackage}\oarg{callback=<callbacks>}\marg{nodetree}. - -Use commas to specify mulitple callbacks. Avoid using whitespaces: - -\begin{code} -\nodetreeregister{preline,line,postline} -\end{code} - -Wrap your callback aliases in curly braces for the macro |\nodetreeset|: - -\begin{code} -\nodetreeset{callback={preline,line,postline}} -\end{code} - -The same applies for the macro |\usepackage|: - -\begin{code} -\usepackage{callback={preline,line,postline}} -\end{code} - -%% -% Tabular callbacks -%% - -\newcommand{\nodetreecallback}[3]{ - \nodetreelua{#1} & \nodetreelua{#2} & \nodetreelua{#3} \\ -} - -\begin{figure} - -\noindent -\begin{tabular}{lll} -\textbf{Alias (short)} & \textbf{Alias (longer)} & \textbf{Callback} \\ -\nodetreecallback{contribute}{contributefilter}{contribute_filter} -\nodetreecallback{buildpage}{buildpagefilter}{buildpage_filter} -\nodetreecallback{preline}{prelinebreakfilter}{pre_linebreak_filter} -\nodetreecallback{line}{linebreakfilter}{linebreak_filter} -\nodetreecallback{append}{appendtovlistfilter}{append_to_vlist_filter} -\nodetreecallback{postline}{postlinebreakfilter}{post_linebreak_filter} -\nodetreecallback{hpack}{hpackfilter}{hpack_filter} -\nodetreecallback{vpack}{vpackfilter}{vpack_filter} -\nodetreecallback{hpackq}{hpackquality}{hpack_quality} -\nodetreecallback{vpackq}{vpackquality}{vpack_quality} -\nodetreecallback{process}{processrule}{process_rule} -\nodetreecallback{preout}{preoutputfilter}{pre_output_filter} -\nodetreecallback{hyph}{hyphenate}{hyphenate} -\nodetreecallback{liga}{ligaturing}{ligaturing} -\nodetreecallback{kern}{kerning}{kerning} -\nodetreecallback{insert}{insertlocalpar}{insert_local_par} -\nodetreecallback{mhlist}{mlisttohlist}{mlist_to_hlist} -\end{tabular} - -\caption{The callback aliases} -\label{fig:callback} -\end{figure} - -%% -% verbosity -%% - -\subsection{Option \texttt{verbosity}} - -Higher integer values result in a more verbose output. The default value -for this options is |1|. At the moment only verbosity level |2| is -implemented. - -%% -% color -%% - -\subsection{Option \texttt{color}} - -The default option for |color| is |colored|. Use any other string (for -example |none| or |no|) to disable the colored terminal output of the -package. - -\begin{code} -\usepackage[color=no]{nodetree} -\end{code} - -%% -% unit -%% - -\subsection{Option \texttt{unit}} - -The option |unit| sets the length unit to display all length values of -the nodes. The default option for |unit| is |pt|. See figure -\ref{fig:fixed-units} and \ref{fig:relative-units} for possible values. - -\begin{figure} -\begin{tabular}{lp{10cm}} -\textbf{Unit} & -\textbf{Description} \\ - -pt & -Point 1/72.27 inch. The conversion to metric units, to two decimal -places, is 1 point = 2.85 mm = 28.45 cm. \\ - -pc & -Pica, 12 pt \\ - -in & -Inch, 72.27 pt \\ - -bp & -Big point, 1/72 inch. This length is the definition of a point in -PostScript and many desktop publishing systems. \\ - -cm & -Centimeter \\ - -mm & -Millimeter \\ - -dd & -Didot point, 1.07 pt \\ - -cc & -Cicero, 12 dd \\ - -sp & -Scaled point, 1/65536 pt \\ -\end{tabular} -\caption{Fixed units} -\label{fig:fixed-units} -\end{figure} - -\begin{figure} -\begin{tabular}{lp{10cm}} -\textbf{Unit} & -\textbf{Description} \\ - -ex & -x-height of the current font \\ - -em & -Width of the capital letter M \\ -\end{tabular} -\caption{Relative units} -\label{fig:relative-units} -\end{figure} - -%% -% decimalplaces -%% - -\subsection{Option \texttt{decimalplaces}} - -The options |decimalplaces| sets the number of decimal places for some -node fields. - -\begin{code} -\nodetreeoption[decimalplaces]{4} -\end{code} - -gets - -\begin{code} -├─GLYPH char: "a"; width: 5pt; height: 4.3055pt; -\end{code} - -If |decimalplaces| is set to |0| only integer values are shown. - -\begin{code} -├─GLYPH char: "a"; width: 5pt; height: 4pt; -\end{code} - -%----------------------------------------------------------------------- -% Visual tree structure -%----------------------------------------------------------------------- - -\section{Visual tree structure} - -%% -% Two different connections -%% - -\subsection{Two different connections} - -Nodes in Lua\TeX{} are connected. The |nodetree| package distinguishs -between the |list| and |field| connections. - -\begin{itemize} - \item |list|: Nodes, which are double connected by |next| and - |previous| fields. - \item |field|: Connections to nodes by other fields than |next| and - |previous| fields, e. g. |head|, |pre|. -\end{itemize} - -%% -% Unicode characters -%% - -\subsection{Unicode characters to show the tree view} - -\renewcommand{\arraystretch}{1.5} - -The package |nodetree| uses the unicode box drawing symbols. Your -default terminal font should contain this characters to obtain the tree -view. Eight box drawing characters are necessary. - -\noindent -\begin{tabular}{lcl} -\textbf{Code} & \textbf{Character} & \textbf{Name} \\ -U+2500 & |─| & BOX DRAWINGS LIGHT HORIZONTAL \\ -U+2502 & |│| & BOX DRAWINGS LIGHT VERTICAL \\ -U+2514 & |└| & BOX DRAWINGS LIGHT UP AND RIGHT \\ -U+251C & |├| & BOX DRAWINGS LIGHT VERTICAL AND RIGHT \\ -U+2550 & |═| & BOX DRAWINGS DOUBLE HORIZONTAL \\ -U+2551 & |║| & BOX DRAWINGS DOUBLE VERTICAL \\ -U+255A & |╚| & BOX DRAWINGS DOUBLE UP AND RIGHT \\ -U+2560 & |╠| & BOX DRAWINGS DOUBLE VERTICAL AND RIGHT \\ -\end{tabular} - -For |list| connections \emph{light} characters are shown. - -\begin{code} -│ │ -│ ├─list1 -│ └─list2 -└─list3 -\end{code} - -|field| connections are visialized by \emph{Double} characters. - -\begin{code} -║ ║ -║ ╠═field1 -║ ╚═field2 -╚═field3 -\end{code} - -%----------------------------------------------------------------------- -% Examples -%----------------------------------------------------------------------- - -\newpage - -\section{Examples} - -%% -% packagename -%% - -\subsection{The node list of the package name} - -\begin{code} -\documentclass{article} -\usepackage{nodetree} -\begin{document} -nodetree -\end{document} -\end{code} - -\tmpgraphics{packagename} - -%% -% math -%% - -\newpage - -\subsection{The node list of a mathematical formula} - -\begin{code} -\documentclass{article} -\usepackage[callback={mhlist}]{nodetree} -\begin{document} -\[\left(a\right)\left[\frac{b}{a}\right]=a\,\] -\end{document} -\end{code} - -\tmpgraphics{math} - -%% -% ligatures -%% - -\newpage - -\subsection{The node list of the word \emph{Office}} - -The characters \emph{ffi} are deeply nested in a discretionary node. - -\begin{code} -\documentclass{article} -\usepackage{nodetree} -\begin{document} -Office -\end{document} -\end{code} - -\tmpgraphics{ligatures} - -%----------------------------------------------------------------------- -% Index -%----------------------------------------------------------------------- - - \DocInput{nodetree.dtx} - \pagebreak - \PrintChanges - \pagebreak - \PrintIndex -\end{document} -%</driver> -%<*readme> - -![nodetree](https://raw.githubusercontent.com/Josef-Friedrich/nodetree/master/graphics/packagename.png) - -# Abstract - -`nodetree` is a development package that visualizes the structure of -node lists. `nodetree` shows its debug informations in the consoles’ -output when you compile a LuaTeX file. It uses a similar visual -representation for node lists as the UNIX `tree` command uses for a -folder structure. - -Node lists are the main building blocks of each document generated by -the TeX engine LuaTeX. The package `nodetree` doesn‘t change -the rendered document. The tree view can only be seen when using a -terminal to generate the document. - -`nodetree` is inspired by a -[gist from Patrick Gundlach](https://gist.github.com/pgundlach/556247). - -# License - -Copyright (C) 2016 by Josef Friedrich <josef@friedrich.rocks> ------------------------------------------------------------------------- -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. - -# CTAN - -Since July 2016 the cloze package is included in the Comprehensive TeX -Archive Network (CTAN). - -* TeX archive: http://mirror.ctan.org/tex-archive/macros/luatex/generic/nodetree -* Package page: http://www.ctan.org/pkg/nodetree - -# Repository - -https://github.com/Josef-Friedrich/nodetree - -# Installation - -Get source: - - git clone git@github.com:Josef-Friedrich/nodetree.git - cd nodetree - -Compile: - - make - -or manually: - - luatex nodetree.ins - lualatex nodetree.dtx - makeindex -s gglo.ist -o nodetree.gls nodetree.glo - makeindex -s gind.ist -o nodetree.ind nodetree.idx - lualatex nodetree.dtx - -# Examples - -## The node list of the package name - -```latex -\documentclass{article} -\usepackage{nodetree} -\begin{document} -nodetree -\end{document} -``` - -![nodetree](graphics/packagename.png) - -## The node list of a mathematical formula - -```latex -\documentclass{article} -\usepackage[callback={mhlist}]{nodetree} -\begin{document} -\[\left(a\right)\left[\frac{b}{a}\right]=a\,\] -\end{document} -``` - -![nodetree](https://raw.githubusercontent.com/Josef-Friedrich/nodetree/master/graphics/math.png) - -## The node list of the word 'Office' - -The characters 'ffi' are deeply nested in a discretionary node. - -```latex -\documentclass{article} -\usepackage{nodetree} -\begin{document} -Office -\end{document} -``` - -![nodetree](https://raw.githubusercontent.com/Josef-Friedrich/nodetree/master/graphics/ligatures.png) - -%</readme> % \fi % % \CheckSum{0} @@ -695,6 +55,16 @@ Office % \changes{v1.0}{2016/07/07}{Inital release} % \changes{v1.1}{2016/07/13}{Fix the registration of same callbacks} % \changes{v1.2}{2016/07/18}{Fix difference between README.md in the upload and that from nodetree.dtx} +% \changes{v2.0}{2020/05/29}{ +% * Switch from lowercase macro names to PascalCase names for better readability. +% * The Lua code is no longer developed inside the DTX file, instead in a separate file named nodetree.lua. +% * Add a sub package named nodetree-embed.sty for embedding nodetree views into a \LaTeX{} document. +% * Add support for new node subtype names. +% * Add support for a new Lua\TeX{} node callback. +% * Add support for node properties. +% * Less verbose representation of node attributes. +% * Minor tree output adjustments. +% } % % \DoNotIndex{\newcommand,\newenvironment,\def,\directlua} % @@ -716,40 +86,68 @@ Office % \begin{macrocode} \directlua{ nodetree = require('nodetree') - nodetree.set_option('engine', 'luatex') - nodetree.set_default_options() } % \end{macrocode} % -% \begin{macro}{\nodetreeoption} +% \begin{macro}{\NodetreeSetOption} % \begin{macrocode} -\def\nodetreeoption[#1]#2{ +\def\NodetreeSetOption[#1]#2{ \directlua{ nodetree.set_option('#1', '#2') } } +\let\nodetreeoption\NodetreeSetOption +% \end{macrocode} +% \end{macro} +% +% \begin{macro}{\NodetreeResetOption} +% \begin{macrocode} +\def\NodetreeResetOption#1{ + \NodetreeSetOption[#1]{% + \directlua{ + tex.print(nodetree.get_default_option('#1')) + }% + }% +} % \end{macrocode} % \end{macro} % -% \begin{macro}{\nodetreeregister} +% \begin{macro}{\NodetreeReset} % \begin{macrocode} -\def\nodetreeregister#1{ +\def\NodetreeReset{ + \NodetreeResetOption{callback} + \NodetreeResetOption{channel} + \NodetreeResetOption{color} + \NodetreeResetOption{decimalplaces} + \NodetreeResetOption{engine} + \NodetreeResetOption{unit} + \NodetreeResetOption{verbosity} +} +\let\nodetreereset\NodetreeReset +% \end{macrocode} +% \end{macro} +% +% \begin{macro}{\NodetreeRegisterCallback} +% \begin{macrocode} +\def\NodetreeRegisterCallback#1{ \directlua{ nodetree.set_option('callback', '#1') nodetree.register_callbacks() } } +\let\nodetreeregister\NodetreeRegisterCallback % \end{macrocode} % \end{macro} % -% \begin{macro}{\nodetreeunregister} +% \begin{macro}{\NodetreeUnregisterCallback} % \begin{macrocode} -\def\nodetreeunregister#1{ +\def\NodetreeUnregisterCallback#1{ \directlua{ nodetree.set_option('callback', '#1') nodetree.unregister_callbacks() } } +\let\nodetreeunregister\NodetreeUnregisterCallback % \end{macrocode} % \end{macro} % @@ -765,9 +163,6 @@ Office % % \begin{macrocode} \input{nodetree} -\directlua{ - nodetree.set_option('engine', 'lualatex') -} % \end{macrocode} % % \begin{macrocode} @@ -777,1233 +172,303 @@ Office % \begin{macrocode} \SetupKeyvalOptions{ family=NT, - prefix=NT@ + prefix=NTK@ } % \end{macrocode} % % \begin{macrocode} \DeclareStringOption[term]{channel} -\define@key{NT}{channel}[]{\nodetreeoption[channel]{#1}} +\define@key{NT}{channel}[]{\NodetreeSetOption[channel]{#1}} % \end{macrocode} % % \begin{macrocode} \DeclareStringOption[postlinebreak]{callback} -\define@key{NT}{callback}[]{\nodetreeoption[callback]{#1}} +\define@key{NT}{callback}[]{\NodetreeSetOption[callback]{#1}} % \end{macrocode} % % \begin{macrocode} \DeclareStringOption[1]{verbosity} -\define@key{NT}{verbosity}[]{\nodetreeoption[verbosity]{#1}} +\define@key{NT}{verbosity}[]{\NodetreeSetOption[verbosity]{#1}} % \end{macrocode} % % \begin{macrocode} \DeclareStringOption[colored]{color} -\define@key{NT}{color}[]{\nodetreeoption[color]{#1}} +\define@key{NT}{color}[]{\NodetreeSetOption[color]{#1}} % \end{macrocode} % % \begin{macrocode} \DeclareStringOption[1]{unit} -\define@key{NT}{unit}[]{\nodetreeoption[unit]{#1}} +\define@key{NT}{unit}[]{\NodetreeSetOption[unit]{#1}} % \end{macrocode} % % \begin{macrocode} \DeclareStringOption[1]{decimalplaces} -\define@key{NT}{decimalplaces}[]{\nodetreeoption[decimalplaces]{#1}} +\define@key{NT}{decimalplaces}[]{\NodetreeSetOption[decimalplaces]{#1}} % \end{macrocode} % % \begin{macrocode} -\ProcessKeyvalOptions* +\ProcessKeyvalOptions{NT} \directlua{ - nodetree.set_default_options() nodetree.register_callbacks() } % \end{macrocode} % -% \begin{macro}{\nodetreeset} +% \begin{macro}{\NodetreeSet} % \begin{macrocode} -\newcommand{\nodetreeset}[1]{\setkeys{nodetree}{#1}} +\newcommand{\NodetreeSet}[1]{% + \setkeys{NT}{#1}% +} +\let\nodetreeset\NodetreeSet % \end{macrocode} % \end{macro} % % \iffalse %</package> -%<*luamain> +%<*packageembed> % \fi -% -% \makeatletter -% \c@CodelineNo 0 \relax -% \makeatother -% -% \subsection{The file \tt{nodetree.lua}} -% -% \begin{macrocode} -local nodex = {} -% \end{macrocode} -% -% \begin{macrocode} -local tpl = {} -% \end{macrocode} -% -% \begin{macrocode} -local tree = {} -% \end{macrocode} -% -% Nodes in Lua\TeX{} are connected. The nodetree view distinguishs -% between the |list| and |field| connections. -% -% \begin{itemize} -% \item |list|: Nodes, which are double connected by |next| and -% |previous| fields. -% \item |field|: Connections to nodes by other fields than |next| and -% |previous| fields, e. g. |head|, |pre|. -% \end{itemize} -% -% The lua table named |tree.state| holds state values for the current -% tree item. -% -% \begin{code} -% tree.state: -% - 1: -% - list: continue -% - field: stop -% - 2: -% - list: continue -% - field: stop -% \end{code} -% \begin{macrocode} -tree.state = {} -% \end{macrocode} -% -% \begin{macrocode} -local callbacks = {} -% \end{macrocode} -% -% \begin{macrocode} -local base = {} -% \end{macrocode} -% -% \begin{macrocode} -local options = {} -% \end{macrocode} -% -% \subsubsection{nodex --- Extend the node library} -% -% Get the node id form, e. g.: -% \begin{code} -% <node nil < 172 > nil : hlist 2> -% \end{code} -% \begin{macrocode} -function nodex.node_id(n) - return string.gsub(tostring(n), '^<node%s+%S+%s+<%s+(%d+).*', '%1') -end -% \end{macrocode} -% -% \begin{macrocode} -function nodex.subtype(n) - local typ = node.type(n.id) - local subtypes = { -% \end{macrocode} -% \paragraph{hlist (0)} -% \begin{macrocode} - hlist = { - [0] = 'unknown', - [1] = 'line', - [2] = 'box', - [3] = 'indent', - [4] = 'alignment', - [5] = 'cell', - [6] = 'equation', - [7] = 'equationnumber', - }, -% \end{macrocode} -% \paragraph{vlist (1)} -% \begin{macrocode} - vlist = { - [0] = 'unknown', - [4] = 'alignment', - [5] = 'cell', - }, -% \end{macrocode} -% \paragraph{rule (2)} -% \begin{macrocode} - rule = { - [0] = 'unknown', - [1] = 'box', - [2] = 'image', - [3] = 'empty', - [4] = 'user', - }, -% \end{macrocode} -% -% \noindent -% Nodes without subtypes: -% \begin{compactitem} -% \item ins (3) -% \item mark (4) -% \end{compactitem} -% \begin{macrocode} -% \end{macrocode} -% \paragraph{adjust (5)} -% \begin{macrocode} - adjust = { - [0] = 'normal', - [1] = 'pre', - }, -% \end{macrocode} -% \paragraph{boundary (6)} -% \begin{macrocode} - boundary = { - [0] = 'cancel', - [1] = 'user', - [2] = 'protrusion', - [3] = 'word', - }, -% \end{macrocode} -% \paragraph{disc (7)} -% \begin{macrocode} - disc = { - [0] = 'discretionary', - [1] = 'explicit', - [2] = 'automatic', - [3] = 'regular', - [4] = 'first', - [5] = 'second', - }, -% \end{macrocode} -% -% \noindent -% Nodes without subtypes: -% \begin{compactitem} -% \item whatsit (8) -% \item local\_par (9) -% \item dir (10) -% \end{compactitem} -% -% \paragraph{math (11)} -% \begin{macrocode} - math = { - [0] = 'beginmath', - [1] = 'endmath', - }, -% \end{macrocode} -% \paragraph{glue (12)} -% \begin{macrocode} - glue = { - [0] = 'userskip', - [1] = 'lineskip', - [2] = 'baselineskip', - [3] = 'parskip', - [4] = 'abovedisplayskip', - [5] = 'belowdisplayskip', - [6] = 'abovedisplayshortskip', - [7] = 'belowdisplayshortskip', - [8] = 'leftskip', - [9] = 'rightskip', - [10] = 'topskip', - [11] = 'splittopskip', - [12] = 'tabskip', - [13] = 'spaceskip', - [14] = 'xspaceskip', - [15] = 'parfillskip', - [16] = 'mathskip', - [17] = 'thinmuskip', - [18] = 'medmuskip', - [19] = 'thickmuskip', - [98] = 'conditionalmathskip', - [99] = 'muglue', - [100] = 'leaders', - [101] = 'cleaders', - [102] = 'xleaders', - [103] = 'gleaders', - }, -% \end{macrocode} -% \paragraph{kern (13)} -% \begin{macrocode} - kern = { - [0] = 'fontkern', - [1] = 'userkern', - [2] = 'accentkern', - [3] = 'italiccorrection', - }, -% \end{macrocode} -% -% \noindent -% Nodes without subtypes: -% \begin{compactitem} -% \item penalty (14) -% \item unset (15) -% \item style (16) -% \item choice (17) -% \end{compactitem} -% -% \paragraph{noad (18)} % \begin{macrocode} - noad = { - [0] = 'ord', - [1] = 'opdisplaylimits', - [2] = 'oplimits', - [3] = 'opnolimits', - [4] = 'bin', - [5] = 'rel', - [6] = 'open', - [7] = 'close', - [8] = 'punct', - [9] = 'inner', - [10] = 'under', - [11] = 'over', - [12] = 'vcenter', - }, -% \end{macrocode} -% \paragraph{radical (19)} -% \begin{macrocode} - radical = { - [0] = 'radical', - [1] = 'uradical', - [2] = 'uroot', - [3] = 'uunderdelimiter', - [4] = 'uoverdelimiter', - [5] = 'udelimiterunder', - [6] = 'udelimiterover', - }, +\NeedsTeXFormat{LaTeX2e}[1994/06/01] +\ProvidesPackage{nodetree-embed} + [2020/05/29 v2.0 Embed node trees into a LaTeX document] % \end{macrocode} % -% \noindent -% Nodes without subtypes: -% \begin{compactitem} -% \item fraction (20) -% \end{compactitem} -% -% \paragraph{accent (21)} -% \begin{macrocode} - accent = { - [0] = 'bothflexible', - [1] = 'fixedtop', - [2] = 'fixedbottom', - [3] = 'fixedboth', - }, -% \end{macrocode} -% \paragraph{fence (22)} % \begin{macrocode} - fence = { - [0] = 'unset', - [1] = 'left', - [2] = 'middle', - [3] = 'right', - }, +\RequirePackage{xcolor,mdframed,expl3,xparse,fontspec} % \end{macrocode} % -% \noindent -% Nodes without subtypes: -% \begin{compactitem} -% \item math\_char (23) -% \item sub\_box (24) -% \item sub\_mlist (25) -% \item math\_text\_char (26) -% \item delim (27) -% \item margin\_kern (28) -% \end{compactitem} -% -% \paragraph{glyph (29)} % \begin{macrocode} - glyph = { - [0] = 'character', - [1] = 'ligature', - [2] = 'ghost', - [3] = 'left', - [4] = 'right', - }, -% \end{macrocode} -% -% \noindent -% Nodes without subtypes: -% \begin{compactitem} -% \item align\_record (30) -% \item pseudo\_file (31) -% \item pseudo\_line (32) -% \item page\_insert (33) -% \item split\_insert (34) -% \item expr\_stack (35) -% \item nested\_list (36) -% \item span (37) -% \item attribute (38) -% \item glue\_spec (39) -% \item attribute\_list (40) -% \item temp (41) -% \item align\_stack (42) -% \item movement\_stack (43) -% \item if\_stack (44) -% \item unhyphenated (45) -% \item hyphenated (46) -% \item delta (47) -% \item passive (48) -% \item shape (49) -% \end{compactitem} -% \begin{macrocode} - } - subtypes.whatsit = node.whatsits() - local out = '' - if subtypes[typ] and subtypes[typ][n.subtype] then - out = subtypes[typ][n.subtype] - if options.verbosity > 1 then - out = out .. tpl.type_id(n.subtype) - end - return out - else - return tostring(n.subtype) - end - assert(false) -end -% \end{macrocode} -% -% \subsubsection{tpl --- Template function} -% -% \begin{macrocode} -function tpl.round(number) - local mult = 10^(options.decimalplaces or 0) - return math.floor(number * mult + 0.5) / mult -end -% \end{macrocode} -% -% \begin{macrocode} -function tpl.length(input) - input = tonumber(input) - input = input / tex.sp('1' .. options.unit) - return string.format('%g%s', tpl.round(input), options.unit) -end -% \end{macrocode} -% -% \begin{macrocode} -function tpl.fill(number, order, field) - if order ~= nil and order ~= 0 then - if field == 'stretch' then - out = '+' - else - out = '-' - end - return out .. string.format( - '%gfi%s', number / 2^16, - string.rep('l', order - 1) - ) - else - return tpl.length(number) - end -end +\input{nodetree} % \end{macrocode} % % \begin{macrocode} -tpl.node_colors = { - hlist = {'red', 'bright'}, - vlist = {'green', 'bright'}, - rule = {'blue', 'bright'}, - ins = {'blue'}, - mark = {'magenta'}, - adjust = {'cyan'}, - boundary = {'red', 'bright'}, - disc = {'green', 'bright'}, - whatsit = {'yellow', 'bright'}, - local_par = {'blue', 'bright'}, - dir = {'magenta', 'bright'}, - math = {'cyan', 'bright'}, - glue = {'magenta', 'bright'}, - kern = {'green', 'bright'}, - penalty = {'yellow', 'bright'}, - unset = {'blue'}, - style = {'magenta'}, - choice = {'cyan'}, - noad = {'red'}, - radical = {'green'}, - fraction = {'yellow'}, - accent = {'blue'}, - fence = {'magenta'}, - math_char = {'cyan'}, - sub_box = {'red', 'bright'}, - sub_mlist = {'green', 'bright'}, - math_text_char = {'yellow', 'bright'}, - delim = {'blue', 'bright'}, - margin_kern = {'magenta', 'bright'}, - glyph = {'cyan', 'bright'}, - align_record = {'red'}, - pseudo_file = {'green'}, - pseudo_line = {'yellow'}, - page_insert = {'blue'}, - split_insert = {'magenta'}, - expr_stack = {'cyan'}, - nested_list = {'red'}, - span = {'green'}, - attribute = {'yellow'}, - glue_spec = {'magenta'}, - attribute_list = {'cyan'}, - temp = {'magenta'}, - align_stack = {'red', 'bright'}, - movement_stack = {'green', 'bright'}, - if_stack = {'yellow', 'bright'}, - unhyphenated = {'magenta', 'bright'}, - hyphenated = {'cyan', 'bright'}, - delta = {'red'}, - passive = {'green'}, - shape = {'yellow'}, +\RequirePackage{kvoptions} +\SetupKeyvalOptions{ + family=NTE, + prefix=NTEK@ } % \end{macrocode} % % \begin{macrocode} -function tpl.color_code(code) - return string.char(27) .. '[' .. tostring(code) .. 'm' -end -% \end{macrocode} -% -% \begin{code} -% local colors = { -% -- attributes -% reset = 0, -% clear = 0, -% bright = 1, -% dim = 2, -% underscore = 4, -% blink = 5, -% reverse = 7, -% hidden = 8, -% -% -- foreground -% black = 30, -% red = 31, -% green = 32, -% yellow = 33, -% blue = 34, -% magenta = 35, -% cyan = 36, -% white = 37, -% -% -- background -% onblack = 40, -% onred = 41, -% ongreen = 42, -% onyellow = 43, -% onblue = 44, -% onmagenta = 45, -% oncyan = 46, -% onwhite = 47, -% } -% \end{code} -% \begin{macrocode} -function tpl.color(color, mode, background) - if options.color ~= 'colored' then - return '' - end -% \end{macrocode} -% -% \begin{macrocode} - local out = '' - local code = '' -% \end{macrocode} -% -% \begin{macrocode} - if mode == 'bright' then - out = tpl.color_code(1) - elseif mode == 'dim' then - out = tpl.color_code(2) - end -% \end{macrocode} -% -% \begin{macrocode} - if not background then - if color == 'reset' then code = 0 - elseif color == 'red' then code = 31 - elseif color == 'green' then code = 32 - elseif color == 'yellow' then code = 33 - elseif color == 'blue' then code = 34 - elseif color == 'magenta' then code = 35 - elseif color == 'cyan' then code = 36 - else code = 37 end - else - if color == 'black' then code = 40 - elseif color == 'red' then code = 41 - elseif color == 'green' then code = 42 - elseif color == 'yellow' then code = 43 - elseif color == 'blue' then code = 44 - elseif color == 'magenta' then code = 45 - elseif color == 'cyan' then code = 46 - elseif color == 'white' then code = 47 - else code = 40 end - end - return out .. tpl.color_code(code) -end -% \end{macrocode} -% -% \begin{macrocode} -function tpl.key_value(key, value) - local out = tpl.color('yellow') .. key .. ': ' - if value then - out = out .. tpl.color('white') .. value .. '; ' - end - return out .. tpl.color('reset') -end -% \end{macrocode} -% -% \begin{macrocode} -function tpl.char(input) - return string.format('%q', unicode.utf8.char(input)) -end -% \end{macrocode} -% -% \begin{macrocode} -function tpl.type(type, id) - local out = tpl.color( - tpl.node_colors[type][1], - tpl.node_colors[type][2] - ) - .. string.upper(type) - if options.verbosity > 1 then - out = out .. tpl.type_id(id) - end - return out .. tpl.color('reset') .. ' ' -end -% \end{macrocode} -% -% \begin{macrocode} -function tpl.callback_variable(variable_name, variable) - if variable ~= nil and variable ~= '' then - tpl.print(variable_name .. ': ' .. tostring(variable)) - end -end -% \end{macrocode} -% -% \begin{macrocode} -function tpl.line(length) - if length == 'long' then - return '------------------------------------------' - else - return '-----------------------' - end -end -% \end{macrocode} -% -% \begin{macrocode} -function tpl.callback(callback_name, variables) - tpl.print('\n\n') - tpl.print('Callback: ' .. tpl.color('red', '', true) .. - callback_name .. tpl.color('reset') - ) - if variables then - for name, value in pairs(variables) do - if value ~= nil and value ~= '' then - tpl.print(' - ' .. name .. ': ' .. tostring(value)) - end - end - end - tpl.print(tpl.line('long')) -end -% \end{macrocode} -% -% \begin{macrocode} -function tpl.type_id(id) - return '[' .. tostring(id) .. ']' -end -% \end{macrocode} -% -% \begin{macrocode} -function tpl.branch(connection_type, connection_state, last) - local c = connection_type - local s = connection_state - local l = last - if c == 'list' and s == 'stop' and l == false then - return ' ' - elseif c == 'field' and s == 'stop' and l == false then - return ' ' - elseif c == 'list' and s == 'continue' and l == false then - return '│ ' - elseif c == 'field' and s == 'continue' and l == false then - return '║ ' - elseif c == 'list' and s == 'continue' and l == true then - return '├─' - elseif c == 'field' and s == 'continue' and l == true then - return '╠═' - elseif c == 'list' and s == 'stop' and l == true then - return '└─' - elseif c == 'field' and s == 'stop' and l == true then - return '╚═' - end -end -% \end{macrocode} -% -% \begin{macrocode} -function tpl.branches(level, connection_type) - local out = '' - for i = 1, level - 1 do - out = out .. tpl.branch('list', tree.state[i]['list'], false) - out = out .. tpl.branch('field', tree.state[i]['field'], false) - end -% \end{macrocode} -% Format the last branches -% \begin{macrocode} - if connection_type == 'list' then - out = out .. tpl.branch('list', tree.state[level]['list'], true) - else - out = out .. tpl.branch('list', tree.state[level]['list'], false) - out = out .. tpl.branch('field', tree.state[level]['field'], true) - end - return out -end -% \end{macrocode} -% -% \begin{macrocode} -function tpl.print(text) - - if options.channel == 'log' then - if not log then - log = io.open(tex.jobname .. '_nodetree.log', 'a') - end - log:write(text, '\n') - else - print(' ' .. text) - end -end -% \end{macrocode} -% -% \subsubsection{tree --- Build the node tree} -% -% \begin{macrocode} -function tree.format_field(head, field) - local out = '' -% \end{macrocode} -% -% \begin{macrocode} - if not head[field] or head[field] == 0 then - return '' - end -% \end{macrocode} -% -% \begin{macrocode} - if options.verbosity < 2 and - -- glyph - field == 'font' or - field == 'left' or - field == 'right' or - field == 'uchyph' or - -- hlist - field == 'dir' or - field == 'glue_order' or - field == 'glue_sign' or - field == 'glue_set' or - -- glue - field == 'stretch_order' then - return '' - elseif options.verbosity < 3 and - field == 'prev' or - field == 'next' or - field == 'id' - then - return '' - end -% \end{macrocode} -% -% \begin{macrocode} - if field == 'prev' or field == 'next' then - out = nodex.node_id(head[field]) - elseif field == 'subtype' then - out = nodex.subtype(head) - elseif - field == 'width' or - field == 'height' or - field == 'depth' or - field == 'kern' or - field == 'shift' then - out = tpl.length(head[field]) - elseif field == 'char' then - out = tpl.char(head[field]) - elseif field == 'glue_set' then - out = tpl.round(head[field]) - elseif field == 'stretch' or field == 'shrink' then - out = tpl.fill(head[field], head[field .. '_order'], field) - else - out = tostring(head[field]) - end -% \end{macrocode} -% -% \begin{macrocode} - return tpl.key_value(field, out) -end -% \end{macrocode} -% -% |level| is a integer beginning with 1. The variable |connection_type| -% is a string, which can be either |list| or |field|. The variable -% |connection_state| is a string, which can be either |continue| or -% |stop|. -% \begin{macrocode} -function tree.set_state(level, connection_type, connection_state) - if not tree.state[level] then - tree.state[level] = {} - end - tree.state[level][connection_type] = connection_state -end -% \end{macrocode} -% -% \begin{macrocode} -function tree.analyze_fields(fields, level) - local max = 0 - local connection_state = '' - for _ in pairs(fields) do - max = max + 1 - end - local count = 0 - for field_name, recursion_node in pairs(fields) do - count = count + 1 - if count == max then - connection_state = 'stop' - else - connection_state = 'continue' - end - tree.set_state(level, 'field', connection_state) - tpl.print(tpl.branches(level, 'field') .. tpl.key_value(field_name)) - tree.analyze_list(recursion_node, level + 1) - end -end -% \end{macrocode} -% -% \begin{macrocode} -function tree.analyze_node(head, level) - local connection_state - local out = '' - if head.next then - connection_state = 'continue' - else - connection_state = 'stop' - end - tree.set_state(level, 'list', connection_state) - out = tpl.branches(level, 'list') - .. tpl.type(node.type(head.id), head.id) - if options.verbosity > 1 then - out = out .. tpl.key_value('no', nodex.node_id(head)) - end -% \end{macrocode} -% -% \begin{macrocode} - local fields = {} - for field_id, field_name in pairs(node.fields(head.id, head.subtype)) do - if field_name ~= 'next' and - field_name ~= 'prev' and - node.is_node(head[field_name]) then - fields[field_name] = head[field_name] - else - out = out .. tree.format_field(head, field_name) - end - end -% \end{macrocode} -% -% \begin{macrocode} - tpl.print(out) - tree.analyze_fields(fields, level) -end -% \end{macrocode} -% -% \begin{macrocode} -function tree.analyze_list(head, level) - while head do - tree.analyze_node(head, level) - head = head.next - end -end -% \end{macrocode} -% -% \begin{macrocode} -function tree.analyze_callback(head) - tree.analyze_list(head, 1) - tpl.print(tpl.line('short') .. '\n') -end -% \end{macrocode} -% -% \subsubsection{callbacks --- Callback wrapper} -% -% \begin{macrocode} -function callbacks.contribute_filter(extrainfo) - tpl.callback('contribute_filter', {extrainfo = extrainfo}) - return true -end -% \end{macrocode} -% -% \begin{macrocode} -function callbacks.buildpage_filter(extrainfo) - tpl.callback('buildpage_filter', {extrainfo = extrainfo}) - return true -end -% \end{macrocode} -% -% \begin{macrocode} -function callbacks.pre_linebreak_filter(head, groupcode) - tpl.callback('pre_linebreak_filter', {groupcode = groupcode}) - tree.analyze_callback(head) - return true -end -% \end{macrocode} -% -% \begin{macrocode} -function callbacks.linebreak_filter(head, is_display) - tpl.callback('linebreak_filter', {is_display = is_display}) - tree.analyze_callback(head) - return true -end -% \end{macrocode} -% -% TODO: Fix return values, page output -% \begin{macrocode} -function callbacks.append_to_vlist_filter(head, locationcode, prevdepth, mirrored) - local variables = { - locationcode = locationcode, - prevdepth = prevdepth, - mirrored = mirrored, - } - tpl.callback('append_to_vlist_filter', variables) - tree.analyze_callback(head) - return true -end +\directlua{ + nodetree = require('nodetree') + nodetree.check_shell_escape() +} % \end{macrocode} % % \begin{macrocode} -function callbacks.post_linebreak_filter(head, groupcode) - tpl.callback('post_linebreak_filter', {groupcode = groupcode}) - tree.analyze_callback(head) - return true -end +\define@key{NTE}{callback}[]{\NodetreeSetOption[callback]{#1}} % \end{macrocode} % % \begin{macrocode} -function callbacks.hpack_filter(head, groupcode, size, packtype, direction, attributelist) - local variables = { - groupcode = groupcode, - size = size, - packtype = packtype, - direction = direction, - attributelist = attributelist, - } - tpl.callback('hpack_filter', variables) - tree.analyze_callback(head) - return true -end +\DeclareStringOption[1]{verbosity} +\define@key{NTE}{verbosity}[]{\NodetreeSetOption[verbosity]{#1}} % \end{macrocode} % % \begin{macrocode} -function callbacks.vpack_filter(head, groupcode, size, packtype, maxdepth, direction, attributelist) - local variables = { - groupcode = groupcode, - size = size, - packtype = packtype, - maxdepth = tpl.length(maxdepth), - direction = direction, - attributelist = attributelist, - } - tpl.callback('vpack_filter', variables) - tree.analyze_callback(head) - return true -end +\DeclareStringOption[colored]{color} +\define@key{NTE}{color}[]{\NodetreeSetOption[color]{#1}} % \end{macrocode} % % \begin{macrocode} -function callbacks.hpack_quality(incident, detail, head, first, last) - local variables = { - incident = incident, - detail = detail, - first = first, - last = last, - } - tpl.callback('hpack_quality', variables) - tree.analyze_callback(head) -end +\DeclareStringOption[1]{unit} +\define@key{NTE}{unit}[]{\NodetreeSetOption[unit]{#1}} % \end{macrocode} % % \begin{macrocode} -function callbacks.vpack_quality(incident, detail, head, first, last) - local variables = { - incident = incident, - detail = detail, - first = first, - last = last, - } - tpl.callback('vpack_quality', variables) - tree.analyze_callback(head) -end +\DeclareStringOption[1]{decimalplaces} +\define@key{NTE}{decimalplaces}[]{\NodetreeSetOption[decimalplaces]{#1}} % \end{macrocode} % % \begin{macrocode} -function callbacks.process_rule(head, width, height) - local variables = { - width = width, - height = height, - } - tpl.callback('process_rule', variables) - tree.analyze_callback(head) - return true -end +\DeclareStringOption[monokaisoda]{theme} % \end{macrocode} % % \begin{macrocode} -function callbacks.pre_output_filter(head, groupcode, size, packtype, maxdepth, direction) - local variables = { - groupcode = groupcode, - size = size, - packtype = packtype, - maxdepth = maxdepth, - direction = direction, - } - tpl.callback('pre_output_filter', variables) - tree.analyze_callback(head) - return true -end +\DeclareStringOption[dark]{thememode} % \end{macrocode} % % \begin{macrocode} -function callbacks.hyphenate(head, tail) - tpl.callback('hyphenate') - tpl.print('head:') - tree.analyze_callback(head) - tpl.print('tail:') - tree.analyze_callback(tail) -end +\DeclareStringOption[Ubuntu Mono]{font} % \end{macrocode} % % \begin{macrocode} -function callbacks.ligaturing(head, tail) - tpl.callback('ligaturing') - tpl.print('head:') - tree.analyze_callback(head) - tpl.print('tail:') - tree.analyze_callback(tail) -end +\DeclareStringOption[\footnotesize]{fontsize} % \end{macrocode} % % \begin{macrocode} -function callbacks.kerning(head, tail) - tpl.callback('kerning') - tpl.print('head:') - tree.analyze_callback(head) - tpl.print('tail:') - tree.analyze_callback(tail) -end +\DeclareBoolOption{showmarkup} % \end{macrocode} % % \begin{macrocode} -function callbacks.insert_local_par(local_par, location) - tpl.callback('insert_local_par', {location = location}) - tree.analyze_callback(local_par) - return true -end +\ProcessKeyvalOptions{NTE} % \end{macrocode} % +% \begin{macro}{\NTE@colors} % \begin{macrocode} -function callbacks.mlist_to_hlist(head, display_type, need_penalties) - local variables = { - display_type = display_type, - need_penalties = need_penalties, +\ExplSyntaxOn +\def\NTE@colors{ + \str_case_e:nn{\NTEK@theme}{ + {bwdark}{ + \definecolor{NTEblack}{gray}{0} + \definecolor{NTEred}{gray}{1} + \definecolor{NTEgreen}{gray}{1} + \definecolor{NTEyellow}{gray}{1} + \definecolor{NTEblue}{gray}{1} + \definecolor{NTEmagenta}{gray}{1} + \definecolor{NTEcyan}{gray}{1} + \definecolor{NTEwhite}{gray}{1} + \definecolor{NTEblackbright}{gray}{0} + \definecolor{NTEredbright}{gray}{1} + \definecolor{NTEgreenbright}{gray}{1} + \definecolor{NTEyellowbright}{gray}{1} + \definecolor{NTEbluebright}{gray}{1} + \definecolor{NTEmagentabright}{gray}{1} + \definecolor{NTEcyanbright}{gray}{1} + \definecolor{NTEwhitebright}{gray}{1} + } + {bwlight}{ + \definecolor{NTEblack}{gray}{0} + \definecolor{NTEred}{gray}{0} + \definecolor{NTEgreen}{gray}{0} + \definecolor{NTEyellow}{gray}{0} + \definecolor{NTEblue}{gray}{0} + \definecolor{NTEmagenta}{gray}{0} + \definecolor{NTEcyan}{gray}{0} + \definecolor{NTEwhite}{gray}{1} + \definecolor{NTEblackbright}{gray}{0} + \definecolor{NTEredbright}{gray}{0} + \definecolor{NTEgreenbright}{gray}{0} + \definecolor{NTEyellowbright}{gray}{0} + \definecolor{NTEbluebright}{gray}{0} + \definecolor{NTEmagentabright}{gray}{0} + \definecolor{NTEcyanbright}{gray}{0} + \definecolor{NTEwhitebright}{gray}{1} + } + {monokaisoda}{ + \definecolor{NTEblack}{HTML}{1a1a1a} + \definecolor{NTEred}{HTML}{f4005f} + \definecolor{NTEgreen}{HTML}{98e024} + \definecolor{NTEyellow}{HTML}{fa8419} + \definecolor{NTEblue}{HTML}{9d65ff} + \definecolor{NTEmagenta}{HTML}{f4005f} + \definecolor{NTEcyan}{HTML}{58d1eb} + \definecolor{NTEwhite}{HTML}{c4c5b5} + \definecolor{NTEblackbright}{HTML}{625e4c} + \definecolor{NTEredbright}{HTML}{f4005f} + \definecolor{NTEgreenbright}{HTML}{98e024} + \definecolor{NTEyellowbright}{HTML}{e0d561} + \definecolor{NTEbluebright}{HTML}{9d65ff} + \definecolor{NTEmagentabright}{HTML}{f4005f} + \definecolor{NTEcyanbright}{HTML}{58d1eb} + \definecolor{NTEwhitebright}{HTML}{f6f6ef} + } } - tpl.callback('mlist_to_hlist', variables) - tree.analyze_callback(head) - return node.mlist_to_hlist(head, display_type, need_penalties) -end -% \end{macrocode} -% -% \subsubsection{base --- Exported base functions} -% -% \begin{macrocode} -function base.normalize_options() - options.verbosity = tonumber(options.verbosity) - options.decimalplaces = tonumber(options.decimalplaces) -end -% \end{macrocode} -% -% \begin{macrocode} -function base.set_default_options() - local defaults = { - verbosity = 1, - callback = 'postlinebreak', - engine = 'luatex', - color = 'colored', - decimalplaces = 2, - unit = 'pt', - channel = 'term', + \str_case_e:nn{\NTEK@thememode}{ + {dark}{ + \definecolor{NTEbackground}{named}{NTEblack} + \definecolor{NTEfont}{named}{NTEwhitebright} + } + {light}{ + \definecolor{NTEbackground}{named}{NTEwhitebright} + \definecolor{NTEfont}{named}{NTEblack} + } } - if not options then - options = {} - end - for key, value in pairs(defaults) do - if not options[key] then - options[key] = value - end - end - base.normalize_options() -end -% \end{macrocode} -% -% \begin{macrocode} -function base.set_option(key, value) - if not options then - options = {} - end - options[key] = value - base.normalize_options() -end -% \end{macrocode} -% -% \begin{macrocode} -function base.get_option(key) - if not options then - options = {} - end - if options[key] then - return options[key] - end -end -% \end{macrocode} -% -% \begin{macrocode} -function base.get_callback_name(alias) - if alias == 'contribute' or alias == 'contributefilter' then - return 'contribute_filter' -% \end{macrocode} -% -% \begin{macrocode} - elseif alias == 'buildpage' or alias == 'buildpagefilter' then - return 'buildpage_filter' -% \end{macrocode} -% -% \begin{macrocode} - elseif alias == 'preline' or alias == 'prelinebreakfilter' then - return 'pre_linebreak_filter' -% \end{macrocode} -% -% \begin{macrocode} - elseif alias == 'line' or alias == 'linebreakfilter' then - return 'linebreak_filter' -% \end{macrocode} -% -% \begin{macrocode} - elseif alias == 'append' or alias == 'appendtovlistfilter' then - return 'append_to_vlist_filter' -% \end{macrocode} -% -% \begin{macrocode} - elseif alias == 'postline' or alias == 'postlinebreakfilter' then - return 'post_linebreak_filter' -% \end{macrocode} -% -% \begin{macrocode} - elseif alias == 'hpack' or alias == 'hpackfilter' then - return 'hpack_filter' -% \end{macrocode} -% -% \begin{macrocode} - elseif alias == 'vpack' or alias == 'vpackfilter' then - return 'vpack_filter' -% \end{macrocode} -% TODO: Fix: Unable to register callback -% \begin{macrocode} - elseif alias == 'hpackq' or alias == 'hpackquality' then - return 'hpack_quality' -% \end{macrocode} -% TODO: Fix: Unable to register callback -% \begin{macrocode} - elseif alias == 'vpackq' or alias == 'vpackquality' then - return 'vpack_quality' -% \end{macrocode} -% -% \begin{macrocode} - elseif alias == 'process' or alias == 'processrule' then - return 'process_rule' -% \end{macrocode} -% -% \begin{macrocode} - elseif alias == 'preout' or alias == 'preoutputfilter' then - return 'pre_output_filter' -% \end{macrocode} -% -% \begin{macrocode} - elseif alias == 'hyph' or alias == 'hyphenate' then - return 'hyphenate' -% \end{macrocode} -% -% \begin{macrocode} - elseif alias == 'liga' or alias == 'ligaturing' then - return 'ligaturing' -% \end{macrocode} -% -% \begin{macrocode} - elseif alias == 'kern' or alias == 'kerning' then - return 'kerning' -% \end{macrocode} -% -% \begin{macrocode} - elseif alias == 'insert' or alias == 'insertlocalpar' then - return 'insert_local_par' -% \end{macrocode} -% -% \begin{macrocode} - elseif alias == 'mhlist' or alias == 'mlisttohlist' then - return 'mlist_to_hlist' -% \end{macrocode} -% -% \begin{macrocode} - else - return 'post_linebreak_filter' - end -end -% \end{macrocode} -% -% \begin{macrocode} -function base.register(cb) - if options.engine == 'lualatex' then - luatexbase.add_to_callback(cb, callbacks[cb], 'nodetree') - else - id, error = callback.register(cb, callbacks[cb]) - end -end +} +\ExplSyntaxOff % \end{macrocode} +% \end{macro} % +% \begin{macro}{\NTE@fonts} % \begin{macrocode} -function base.register_callbacks() - for alias in string.gmatch(options.callback, '([^,]+)') do - base.register(base.get_callback_name(alias)) - end -end +\def\NTE@fonts{ + \bfseries% + \NTEK@fontsize% + \setmonofont{\NTEK@font}% + \ttfamily% + \setlength{\parindent}{0pt}% + \setlength{\parskip}{-0.9pt}% +} % \end{macrocode} +% \end{macro} % +% \begin{macro}{\NodetreeSet} +% Same definition as in nodetree.sty. Only implement this command +% if not already registers. % \begin{macrocode} -function base.unregister(cb) - if options.engine == 'lualatex' then - luatexbase.remove_from_callback(cb, 'nodetree') - else - id, error = callback.register(cb, nil) - end -end +\providecommand{\NodetreeSet}[1]{% + \setkeys{NTE}{#1}% +} % \end{macrocode} +% \end{macro} % % \begin{macrocode} -function base.unregister_callbacks() - for alias in string.gmatch(options.callback, '([^,]+)') do - base.unregister(base.get_callback_name(alias)) - end -end +\newenvironment{NodetreeEmbedView}[1][]{ + \setkeys{NTE}{#1} + \NTE@colors + \begin{mdframed}[ + linecolor=black, + backgroundcolor=NTEbackground, + fontcolor=NTEfont, + ]% + \NTE@fonts +}{ + \end{mdframed}% +} % \end{macrocode} % -% \begin{macrocode} -function base.execute() - local c = base.get_callback() - if options.engine == 'lualatex' then - luatexbase.add_to_callback(c, callbacks.post_linebreak_filter, 'nodetree') - else - id, error = callback.register(c, callbacks.post_linebreak_filter) - end -end +% \begin{environment}{NodetreeEmbedEnv} +% \begin{macrocode} +\NewDocumentEnvironment { NodetreeEmbedEnv } { O{} +b } { + \setkeys{NTE}{#1} + \ifNTEK@showmarkup + \noindent + \texttt{\detokenize{#2}} + \else + \fi + \NTE@colors + \begin{NodetreeEmbedView} + \directlua{ + nodetree.compile_include('\luaescapestring{\unexpanded{#2}}') + } + \end{NodetreeEmbedView} +}{} +% \end{macrocode} +% \end{environment} + +% \begin{macro}{\NodetreeEmbedCmd} +% \begin{macrocode} +\NewDocumentCommand { \NodetreeEmbedCmd } { O{} +v } { + \setkeys{NTE}{#1} + \ifNTEK@showmarkup + \noindent + \texttt{#2} + \else + \fi + \NTE@colors + \begin{NodetreeEmbedView} + \directlua{ + nodetree.compile_include('\luaescapestring{\unexpanded{#2}}') + } + \end{NodetreeEmbedView} +} % \end{macrocode} +% \end{macro} % +% \begin{macro}{\NodetreeEmbedInput} % \begin{macrocode} -function base.analyze(head) - tpl.print('\n') - tree.analyze_list(head, 1) -end +\newcommand{\NodetreeEmbedInput}[2][]{ + \setkeys{NTE}{#1} + \begin{NodetreeEmbedView} + \input{#2.nttex} + \end{NodetreeEmbedView} +} +\let\nodetreeterminalemulator\NodetreeEmbedInput % \end{macrocode} +% \end{macro} % -% \begin{macrocode} -return base -% \end{macrocode} +\endinput % \iffalse -%</luamain> +%</packageembed> % \fi % % \Finale diff --git a/Master/texmf-dist/source/luatex/nodetree/nodetree.ins b/Master/texmf-dist/source/luatex/nodetree/nodetree.ins index 85d250818e7..9b187ab25c1 100644 --- a/Master/texmf-dist/source/luatex/nodetree/nodetree.ins +++ b/Master/texmf-dist/source/luatex/nodetree/nodetree.ins @@ -1,4 +1,4 @@ -% Copyright (C) 2016 by Josef Friedrich <josef@friedrich.rocks> +% Copyright (C) 2016-2020 by Josef Friedrich <josef@friedrich.rocks> % ---------------------------------------------------------------------- % This work may be distributed and/or modified under the conditions of % the LaTeX Project Public License, either version 1.3c of this license @@ -21,7 +21,7 @@ This is a generated file. -Copyright (C) 2016 by Josef Friedrich <josef@friedrich.rocks> +Copyright (C) 2016-2020 by Josef Friedrich <josef@friedrich.rocks> ---------------------------------------------------------------------- This work may be distributed and/or modified under the conditions of the LaTeX Project Public License, either version 1.3c of this license @@ -37,11 +37,7 @@ version 2008/05/05 or later. \generate{\file{nodetree.tex}{\from{nodetree.dtx}{tex}}} \generate{\file{nodetree.sty}{\from{nodetree.dtx}{package}}} - -\nopreamble -\nopostamble -\generate{\file{nodetree.lua}{\from{nodetree.dtx}{luamain}}} -\generate{\file{README.md}{\from{nodetree.dtx}{readme}}} +\generate{\file{nodetree-embed.sty}{\from{nodetree.dtx}{packageembed}}} \obeyspaces \Msg{*************************************************************} diff --git a/Master/texmf-dist/tex/luatex/nodetree/nodetree-embed.sty b/Master/texmf-dist/tex/luatex/nodetree/nodetree-embed.sty new file mode 100644 index 00000000000..ef6a49d7c5f --- /dev/null +++ b/Master/texmf-dist/tex/luatex/nodetree/nodetree-embed.sty @@ -0,0 +1,183 @@ +%% +%% This is file `nodetree-embed.sty', +%% generated with the docstrip utility. +%% +%% The original source files were: +%% +%% nodetree.dtx (with options: `packageembed') +%% +%% This is a generated file. +%% +%% Copyright (C) 2016-2020 by Josef Friedrich <josef@friedrich.rocks> +%% ---------------------------------------------------------------------- +%% This work may be distributed and/or modified under the conditions of +%% the LaTeX Project Public License, either version 1.3c 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.3c or later is part of all distributions of LaTeX +%% version 2008/05/05 or later. +%% +\NeedsTeXFormat{LaTeX2e}[1994/06/01] +\ProvidesPackage{nodetree-embed} + [2020/05/29 v2.0 Embed node trees into a LaTeX document] +\RequirePackage{xcolor,mdframed,expl3,xparse,fontspec} +\input{nodetree} +\RequirePackage{kvoptions} +\SetupKeyvalOptions{ + family=NTE, + prefix=NTEK@ +} +\directlua{ + nodetree = require('nodetree') + nodetree.check_shell_escape() +} +\define@key{NTE}{callback}[]{\NodetreeSetOption[callback]{#1}} +\DeclareStringOption[1]{verbosity} +\define@key{NTE}{verbosity}[]{\NodetreeSetOption[verbosity]{#1}} +\DeclareStringOption[colored]{color} +\define@key{NTE}{color}[]{\NodetreeSetOption[color]{#1}} +\DeclareStringOption[1]{unit} +\define@key{NTE}{unit}[]{\NodetreeSetOption[unit]{#1}} +\DeclareStringOption[1]{decimalplaces} +\define@key{NTE}{decimalplaces}[]{\NodetreeSetOption[decimalplaces]{#1}} +\DeclareStringOption[monokaisoda]{theme} +\DeclareStringOption[dark]{thememode} +\DeclareStringOption[Ubuntu Mono]{font} +\DeclareStringOption[\footnotesize]{fontsize} +\DeclareBoolOption{showmarkup} +\ProcessKeyvalOptions{NTE} +\ExplSyntaxOn +\def\NTE@colors{ + \str_case_e:nn{\NTEK@theme}{ + {bwdark}{ + \definecolor{NTEblack}{gray}{0} + \definecolor{NTEred}{gray}{1} + \definecolor{NTEgreen}{gray}{1} + \definecolor{NTEyellow}{gray}{1} + \definecolor{NTEblue}{gray}{1} + \definecolor{NTEmagenta}{gray}{1} + \definecolor{NTEcyan}{gray}{1} + \definecolor{NTEwhite}{gray}{1} + \definecolor{NTEblackbright}{gray}{0} + \definecolor{NTEredbright}{gray}{1} + \definecolor{NTEgreenbright}{gray}{1} + \definecolor{NTEyellowbright}{gray}{1} + \definecolor{NTEbluebright}{gray}{1} + \definecolor{NTEmagentabright}{gray}{1} + \definecolor{NTEcyanbright}{gray}{1} + \definecolor{NTEwhitebright}{gray}{1} + } + {bwlight}{ + \definecolor{NTEblack}{gray}{0} + \definecolor{NTEred}{gray}{0} + \definecolor{NTEgreen}{gray}{0} + \definecolor{NTEyellow}{gray}{0} + \definecolor{NTEblue}{gray}{0} + \definecolor{NTEmagenta}{gray}{0} + \definecolor{NTEcyan}{gray}{0} + \definecolor{NTEwhite}{gray}{1} + \definecolor{NTEblackbright}{gray}{0} + \definecolor{NTEredbright}{gray}{0} + \definecolor{NTEgreenbright}{gray}{0} + \definecolor{NTEyellowbright}{gray}{0} + \definecolor{NTEbluebright}{gray}{0} + \definecolor{NTEmagentabright}{gray}{0} + \definecolor{NTEcyanbright}{gray}{0} + \definecolor{NTEwhitebright}{gray}{1} + } + {monokaisoda}{ + \definecolor{NTEblack}{HTML}{1a1a1a} + \definecolor{NTEred}{HTML}{f4005f} + \definecolor{NTEgreen}{HTML}{98e024} + \definecolor{NTEyellow}{HTML}{fa8419} + \definecolor{NTEblue}{HTML}{9d65ff} + \definecolor{NTEmagenta}{HTML}{f4005f} + \definecolor{NTEcyan}{HTML}{58d1eb} + \definecolor{NTEwhite}{HTML}{c4c5b5} + \definecolor{NTEblackbright}{HTML}{625e4c} + \definecolor{NTEredbright}{HTML}{f4005f} + \definecolor{NTEgreenbright}{HTML}{98e024} + \definecolor{NTEyellowbright}{HTML}{e0d561} + \definecolor{NTEbluebright}{HTML}{9d65ff} + \definecolor{NTEmagentabright}{HTML}{f4005f} + \definecolor{NTEcyanbright}{HTML}{58d1eb} + \definecolor{NTEwhitebright}{HTML}{f6f6ef} + } + } + \str_case_e:nn{\NTEK@thememode}{ + {dark}{ + \definecolor{NTEbackground}{named}{NTEblack} + \definecolor{NTEfont}{named}{NTEwhitebright} + } + {light}{ + \definecolor{NTEbackground}{named}{NTEwhitebright} + \definecolor{NTEfont}{named}{NTEblack} + } + } +} +\ExplSyntaxOff +\def\NTE@fonts{ + \bfseries% + \NTEK@fontsize% + \setmonofont{\NTEK@font}% + \ttfamily% + \setlength{\parindent}{0pt}% + \setlength{\parskip}{-0.9pt}% +} +\providecommand{\NodetreeSet}[1]{% + \setkeys{NTE}{#1}% +} +\newenvironment{NodetreeEmbedView}[1][]{ + \setkeys{NTE}{#1} + \NTE@colors + \begin{mdframed}[ + linecolor=black, + backgroundcolor=NTEbackground, + fontcolor=NTEfont, + ]% + \NTE@fonts +}{ + \end{mdframed}% +} +\NewDocumentEnvironment { NodetreeEmbedEnv } { O{} +b } { + \setkeys{NTE}{#1} + \ifNTEK@showmarkup + \noindent + \texttt{\detokenize{#2}} + \else + \fi + \NTE@colors + \begin{NodetreeEmbedView} + \directlua{ + nodetree.compile_include('\luaescapestring{\unexpanded{#2}}') + } + \end{NodetreeEmbedView} +}{} + +\NewDocumentCommand { \NodetreeEmbedCmd } { O{} +v } { + \setkeys{NTE}{#1} + \ifNTEK@showmarkup + \noindent + \texttt{#2} + \else + \fi + \NTE@colors + \begin{NodetreeEmbedView} + \directlua{ + nodetree.compile_include('\luaescapestring{\unexpanded{#2}}') + } + \end{NodetreeEmbedView} +} +\newcommand{\NodetreeEmbedInput}[2][]{ + \setkeys{NTE}{#1} + \begin{NodetreeEmbedView} + \input{#2.nttex} + \end{NodetreeEmbedView} +} +\let\nodetreeterminalemulator\NodetreeEmbedInput +\endinput +%% +%% End of file `nodetree-embed.sty'. diff --git a/Master/texmf-dist/tex/luatex/nodetree/nodetree.lua b/Master/texmf-dist/tex/luatex/nodetree/nodetree.lua index 170f040c348..666413578df 100644 --- a/Master/texmf-dist/tex/luatex/nodetree/nodetree.lua +++ b/Master/texmf-dist/tex/luatex/nodetree/nodetree.lua @@ -1,16 +1,632 @@ -local nodex = {} -local tpl = {} -local tree = {} -tree.state = {} -local callbacks = {} -local base = {} +--- The nodetree package. +-- +-- Nodetree uses [LDoc](https://github.com/stevedonovan/ldoc) for the +-- source code documentation. The supported tags are described on in +-- the [wiki](https://github.com/stevedonovan/LDoc/wiki). +-- +-- Nodes in LuaTeX are connected. The nodetree view distinguishs +-- between the `list` and `field` connections. +-- +-- * `list`: Nodes, which are double connected by `next` and +-- `previous` fields. +-- * `field`: Connections to nodes by other fields than `next` and +-- `previous` fields, e. g. `head`, `pre`. +-- @module nodetree + +-- luacheck: globals node tex luatexbase lfs callback os unicode status modules + +if not modules then modules = { } end modules ['nodetree'] = { + version = '2.0', + comment = 'nodetree', + author = 'Josef Friedrich', + copyright = 'Josef Friedrich', + license = 'The LaTeX Project Public License Version 1.3c 2008-05-04' +} + +--- A counter for the compiled TeX examples. Some TeX code snippets +-- a written into file, wrapped with some TeX boilerplate code. +-- This written files are compiled. +local example_counter = 0 + +--- The default options +local default_options = { + callback = 'post_linebreak_filter', + channel = 'term', + color = 'colored', + decimalplaces = 2, + engine = 'luatex', -- Required for the callback registration + unit = 'pt', + verbosity = 1, +} + +--- The current options +-- They are changed very often. local options = {} -function nodex.node_id(n) +for key, value in pairs(default_options) do + options[key] = value +end + +if arg[0] == 'lualatex' then + options.engine = 'lualatex' +end + +--- File descriptor +local output_file + +--- The lua table named `tree_state` holds state values of the current +-- tree item. +-- +-- `tree_state`: +-- +-- * `1` (level): +-- * `list`: `continue` +-- * `field`: `stop` +-- * `2`: +-- * `list`: `continue` +-- * `field`: `stop` +-- @table +local tree_state = {} + +--- Format functions. +-- +-- Low level template functions. +-- +-- @section format + +local format = { + --- + -- @treturn string + underscore = function(string) + if options.channel == 'tex' then + return string.gsub(string, '_', '\\_') + else + return string + end + end, + + --- + -- @treturn string + escape = function(string) + if options.channel == 'tex' then + return string.gsub(string, [[\]], [[\string\]]) + else + return string + end + end, + + -- @treturn number + number = function(number) + local mult = 10^(options.decimalplaces or 0) + return math.floor(number * mult + 0.5) / mult + end, + + --- + -- @treturn string + whitespace = function(count) + local whitespace + local output = '' + if options.channel == 'tex' then + whitespace = '\\hspace{0.5em}' + else + whitespace = ' ' + end + if not count then + count = 1 + end + for _ = 1, count do + output = output .. whitespace + end + return output + end, + + --- + -- @treturn string + color_code = function(code) + return string.char(27) .. '[' .. tostring(code) .. 'm' + end, + + --- + -- @treturn string + color_tex = function(color, mode) + if not mode then mode = '' end + return 'NTE' .. color .. mode + end, + + --- + -- @treturn string + node_begin = function() + if options.channel == 'tex' then + return '\\mbox{' + else + return '' + end + end, + + --- + -- @treturn string + node_end = function() + if options.channel == 'tex' then + return '}' + else + return '' + end + end, + + --- + -- @treturn string + new_line = function(count) + local output = '' + if not count then + count = 1 + end + local new_line + if options.channel == 'tex' then + new_line = '\\par{}' + else + new_line = '\n' + end + + for _ = 1, count do + output = output .. new_line + end + return output + end, + + --- + -- @treturn string + type_id = function(id) + return '[' .. tostring(id) .. ']' + end +} + +--- Print the output to stdout or write it into a file (`output_file`). +-- New text is appended. +-- +-- @tparam string text A text string. +-- +local function nodetree_print(text) + if options.channel == 'log' or options.channel == 'tex' then + output_file:write(text) + else + io.write(text) + end +end + +--- Template functions. +-- @section template + +local template = { + node_colors = { + hlist = {'red', 'bright'}, + vlist = {'green', 'bright'}, + rule = {'blue', 'bright'}, + ins = {'blue'}, + mark = {'magenta'}, + adjust = {'cyan'}, + boundary = {'red', 'bright'}, + disc = {'green', 'bright'}, + whatsit = {'yellow', 'bright'}, + local_par = {'blue', 'bright'}, + dir = {'magenta', 'bright'}, + math = {'cyan', 'bright'}, + glue = {'magenta', 'bright'}, + kern = {'green', 'bright'}, + penalty = {'yellow', 'bright'}, + unset = {'blue'}, + style = {'magenta'}, + choice = {'cyan'}, + noad = {'red'}, + radical = {'green'}, + fraction = {'yellow'}, + accent = {'blue'}, + fence = {'magenta'}, + math_char = {'cyan'}, + sub_box = {'red', 'bright'}, + sub_mlist = {'green', 'bright'}, + math_text_char = {'yellow', 'bright'}, + delim = {'blue', 'bright'}, + margin_kern = {'magenta', 'bright'}, + glyph = {'cyan', 'bright'}, + align_record = {'red'}, + pseudo_file = {'green'}, + pseudo_line = {'yellow'}, + page_insert = {'blue'}, + split_insert = {'magenta'}, + expr_stack = {'cyan'}, + nested_list = {'red'}, + span = {'green'}, + attribute = {'yellow'}, + glue_spec = {'magenta'}, + attribute_list = {'cyan'}, + temp = {'magenta'}, + align_stack = {'red', 'bright'}, + movement_stack = {'green', 'bright'}, + if_stack = {'yellow', 'bright'}, + unhyphenated = {'magenta', 'bright'}, + hyphenated = {'cyan', 'bright'}, + delta = {'red'}, + passive = {'green'}, + shape = {'yellow'}, + }, + + --- + -- [SGR (Select Graphic Rendition) Parameters](https://en.wikipedia.org/wiki/ANSI_escape_code#SGR_parameters) + -- + -- __attributes__ + -- + -- | color |code| + -- |------------|----| + -- | reset | 0 | + -- | clear | 0 | + -- | bright | 1 | + -- | dim | 2 | + -- | underscore | 4 | + -- | blink | 5 | + -- | reverse | 7 | + -- | hidden | 8 | + -- + -- __foreground__ + -- + -- | color |code| + -- |------------|----| + -- | black | 30 | + -- | red | 31 | + -- | green | 32 | + -- | yellow | 33 | + -- | blue | 34 | + -- | magenta | 35 | + -- | cyan | 36 | + -- | white | 37 | + -- + -- __background__ + -- + -- | color |code| + -- |------------|----| + -- | onblack | 40 | + -- | onred | 41 | + -- | ongreen | 42 | + -- | onyellow | 43 | + -- | onblue | 44 | + -- | onmagenta | 45 | + -- | oncyan | 46 | + -- | onwhite | 47 | + -- + -- @tparam string color A color name (`black`, `red`, `green`, + -- `yellow`, `blue`, `magenta`, `cyan`, `white`). + -- @tparam string mode `bright` or `dim`. + -- @tparam boolean background Colorize the background not the text. + -- + -- @treturn string + color = function(color, mode, background) + if options.color ~= 'colored' then + return '' + end + + local output = '' + local code + + if mode == 'bright' then + output = format.color_code(1) + elseif mode == 'dim' then + output = format.color_code(2) + end + + if not background then + if color == 'reset' then code = 0 + elseif color == 'red' then code = 31 + elseif color == 'green' then code = 32 + elseif color == 'yellow' then code = 33 + elseif color == 'blue' then code = 34 + elseif color == 'magenta' then code = 35 + elseif color == 'cyan' then code = 36 + else code = 37 end + else + if color == 'black' then code = 40 + elseif color == 'red' then code = 41 + elseif color == 'green' then code = 42 + elseif color == 'yellow' then code = 43 + elseif color == 'blue' then code = 44 + elseif color == 'magenta' then code = 45 + elseif color == 'cyan' then code = 46 + elseif color == 'white' then code = 47 + else code = 40 end + end + return output .. format.color_code(code) + end, + + --- Format a single unicode character. + -- + -- @tparam string char A single input character. + -- + -- @treturn string + char = function(char) + char = string.format('%s', unicode.utf8.char(char)) + char = '\'' .. char .. '\'' + if options.channel == 'tex' then + char = format.escape(char) + end + return char + end, + + --- + -- @treturn string + line = function(length) + local output + if length == 'long' then + output = '------------------------------------------' + else + output = '-----------------------' + end + return output .. format.new_line() + end, + + --- + -- @treturn string + branch = function(connection_type, connection_state, last) + local c = connection_type + local s = connection_state + local l = last + if c == 'list' and s == 'stop' and l == false then + return format.whitespace(2) + elseif c == 'field' and s == 'stop' and l == false then + return format.whitespace(2) + elseif c == 'list' and s == 'continue' and l == false then + return '│' .. format.whitespace() + elseif c == 'field' and s == 'continue' and l == false then + return '║' .. format.whitespace() + elseif c == 'list' and s == 'continue' and l == true then + return '├─' + elseif c == 'field' and s == 'continue' and l == true then + return '╠═' + elseif c == 'list' and s == 'stop' and l == true then + return '└─' + elseif c == 'field' and s == 'stop' and l == true then + return '╚═' + end + return '' + end, +} + +--- +-- @treturn string +function template.fill(number, order, field) + local output + if order ~= nil and order ~= 0 then + if field == 'stretch' then + output = '+' + else + output = '-' + end + return output .. string.format( + '%g%s', number / 2^16, + template.colored_string( + 'fi' .. string.rep('l', order - 1), + 'white', + 'dim' + ) + ) + else + return template.length(number) + end +end + +--- Colorize a text string. +-- +-- @tparam string text A text string. +-- @tparam string color A color name (`black`, `red`, `green`, +-- `yellow`, `blue`, `magenta`, `cyan`, `white`). +-- @tparam string mode `bright` or `dim`. +-- @tparam boolean background Colorize the background not the text. +-- +-- @treturn string +function template.colored_string(text, color, mode, background) + if options.channel == 'tex' then + if mode == 'dim' then + mode = '' + end + return '\\textcolor{' .. + format.color_tex(color, mode) .. + '}{' .. + text .. + '}' + else + return template.color(color, mode, background) .. text .. template.color('reset') + end +end + +--- Format a scaled point input value into dimension string (`12pt`, +-- `1cm`) +-- +-- @tparam number input +-- +-- @treturn string +function template.length (input) + input = tonumber(input) + input = input / tex.sp('1' .. options.unit) + return string.format( + '%g%s', + format.number(input), + template.colored_string(options.unit, 'white', 'dim') + ) +end + +--- Convert a Lua table into a format string. +-- +-- @tparam table table A table to generate a inline view of. +-- +-- @treturn string +function template.table_inline(table) + local tex_escape = '' + if options.channel == 'tex' then + tex_escape = '\\' + end + if type(table) == 'table' then + local output = tex_escape .. '{' + local kv_list = '' + for key, value in pairs(table) do + if type(key) ~= 'numbers' then + key = '\'' .. + template.colored_string(key, 'cyan', 'dim') .. '\'' + end + kv_list = kv_list .. '[' .. key .. '] = ' .. + template.table_inline(value) .. ', ' + end + output = output .. kv_list:gsub(', $', '') + return output .. tex_escape .. '}' + else + return tostring(table) + end +end + +--- Format a key value pair (`key: value, `). +-- +-- @tparam string key A key +-- @tparam string|number value A value +-- @tparam string color A color name (`black`, `red`, `green`, +-- `yellow`, `blue`, `magenta`, `cyan`, `white`). +-- +-- @treturn string +function template.key_value(key, value, color) + if type(color) ~= 'string' then + color = 'yellow' + end + if options.channel == 'tex' then + key = format.underscore(key) + end + local output = template.colored_string(key .. ':', color) + if value then + output = output .. ' ' .. value .. ', ' + end + return output +end + +--- +-- @treturn string +function template.type(type, id) + local output + if options.channel == 'tex' then + output = format.underscore(type) + else + output = type + end + output = string.upper(output) + if options.verbosity > 1 then + output = output .. format.type_id(id) + end + return template.colored_string( + output .. format.whitespace(), + template.node_colors[type][1], + template.node_colors[type][2] + ) +end + +--- +-- @treturn string +function template.callback(callback_name, variables) + nodetree_print( + format.new_line(2) .. + 'Callback: ' .. + template.colored_string(format.underscore(callback_name), 'red', '', true) .. + format.new_line() + ) + if variables then + for name, value in pairs(variables) do + if value ~= nil and value ~= '' then + nodetree_print( + '- ' .. + format.underscore(name) .. + ': ' .. + tostring(value) .. + format.new_line() + ) + end + end + end + nodetree_print(template.line('long')) +end + +--- +-- @treturn string +function template.branches(level, connection_type) + local output = '' + for i = 1, level - 1 do + output = output .. template.branch('list', tree_state[i]['list'], false) + output = output .. template.branch('field', tree_state[i]['field'], false) + end +-- Format the last branches + if connection_type == 'list' then + output = output .. template.branch('list', tree_state[level]['list'], true) + else + output = output .. template.branch('list', tree_state[level]['list'], false) + output = output .. template.branch('field', tree_state[level]['field'], true) + end + return output +end + +--- Extend the node library +-- @section node_extended + +local node_extended = {} + +--- Get the ID of a node. +-- +-- We have to convert the node into a string and than have to extract +-- the ID from this string using a regular expression. If you convert a +-- node into a string it looks like: `<node nil < 172 > nil : +-- hlist 2>`. +-- +-- @tparam node n A node. +-- +-- @treturn string +function node_extended.node_id(n) return string.gsub(tostring(n), '^<node%s+%S+%s+<%s+(%d+).*', '%1') end -function nodex.subtype(n) - local typ = node.type(n.id) - local subtypes = { + +--- A table of all node subtype names. +-- +-- __Nodes without subtypes:__ +-- +-- * `ins` (3) +-- * `mark` (4) +-- * `whatsit` (8) +-- * `local_par` (9) +-- * `dir` (10) +-- * `penalty` (14) +-- * `unset` (15) +-- * `style` (16) +-- * `choice` (17) +-- * `fraction` (20) +-- * `math_char` (23) +-- * `sub_box` (24) +-- * `sub_mlist` (25) +-- * `math_text_char` (26) +-- * `delim` (27) +-- * `margin_kern` (28) +-- * `align_record` (30) +-- * `pseudo_file` (31) +-- * `pseudo_line` (32) +-- * `page_insert` (33) +-- * `split_insert` (34) +-- * `expr_stack` (35) +-- * `nested_list` (36) +-- * `span` (37) +-- * `attribute` (38) +-- * `glue_spec` (39) +-- * `attribute_list` (40) +-- * `temp` (41) +-- * `align_stack` (42) +-- * `movement_stack` (43) +-- * `if_stack` (44) +-- * `unhyphenated` (45) +-- * `hyphenated` (46) +-- * `delta` (47) +-- * `passive` (48) +-- * `shape` (49) +-- +-- @treturn table +local function get_node_subtypes () + local subtypes = { + -- hlist (0) hlist = { [0] = 'unknown', [1] = 'line', @@ -20,29 +636,60 @@ function nodex.subtype(n) [5] = 'cell', [6] = 'equation', [7] = 'equationnumber', + [8] = 'math', + [9] = 'mathchar', + [10] = 'hextensible', + [11] = 'vextensible', + [12] = 'hdelimiter', + [13] = 'vdelimiter', + [14] = 'overdelimiter', + [15] = 'underdelimiter', + [16] = 'numerator', + [17] = 'denominator', + [18] = 'limits', + [19] = 'fraction', + [20] = 'nucleus', + [21] = 'sup', + [22] = 'sub', + [23] = 'degree', + [24] = 'scripts', + [25] = 'over', + [26] = 'under', + [27] = 'accent', + [28] = 'radical', }, + -- vlist (1) vlist = { [0] = 'unknown', [4] = 'alignment', [5] = 'cell', }, + -- rule (2) rule = { - [0] = 'unknown', + [0] = 'normal', [1] = 'box', [2] = 'image', [3] = 'empty', [4] = 'user', + [5] = 'over', + [6] = 'under', + [7] = 'fraction', + [8] = 'radical', + [9] = 'outline', }, + -- adjust (5) adjust = { [0] = 'normal', [1] = 'pre', }, + -- boundary (6) boundary = { [0] = 'cancel', [1] = 'user', [2] = 'protrusion', [3] = 'word', }, + -- disc (7) disc = { [0] = 'discretionary', [1] = 'explicit', @@ -51,10 +698,12 @@ function nodex.subtype(n) [4] = 'first', [5] = 'second', }, + -- math (11) math = { [0] = 'beginmath', [1] = 'endmath', }, + -- glue (12) glue = { [0] = 'userskip', [1] = 'lineskip', @@ -83,12 +732,25 @@ function nodex.subtype(n) [102] = 'xleaders', [103] = 'gleaders', }, + -- kern (13) kern = { [0] = 'fontkern', [1] = 'userkern', [2] = 'accentkern', [3] = 'italiccorrection', }, + -- penalty (14) + penalty = { + [0] = 'userpenalty', + [1] = 'linebreakpenalty', + [2] = 'linepenalty', + [3] = 'wordpenalty', + [4] = 'finalpenalty', + [5] = 'noadpenalty', + [6] = 'beforedisplaypenalty', + [7] = 'afterdisplaypenalty', + [8] = 'equationnumberpenalty', + }, noad = { [0] = 'ord', [1] = 'opdisplaylimits', @@ -104,6 +766,7 @@ function nodex.subtype(n) [11] = 'over', [12] = 'vcenter', }, + -- radical (19) radical = { [0] = 'radical', [1] = 'uradical', @@ -113,18 +776,27 @@ function nodex.subtype(n) [5] = 'udelimiterunder', [6] = 'udelimiterover', }, + -- accent (21) accent = { [0] = 'bothflexible', [1] = 'fixedtop', [2] = 'fixedbottom', [3] = 'fixedboth', }, + -- fence (22) fence = { [0] = 'unset', [1] = 'left', [2] = 'middle', [3] = 'right', + [4] = 'no', + }, + -- margin_kern (28) + margin_kern = { + [0] = 'left', + [1] = 'right', }, + -- glyph (29) glyph = { [0] = 'character', [1] = 'ligature', @@ -134,232 +806,45 @@ function nodex.subtype(n) }, } subtypes.whatsit = node.whatsits() - local out = '' + return subtypes +end + +--- +-- @treturn string +function node_extended.subtype(n) + local typ = node.type(n.id) + local subtypes = get_node_subtypes() + + local output if subtypes[typ] and subtypes[typ][n.subtype] then - out = subtypes[typ][n.subtype] + output = subtypes[typ][n.subtype] if options.verbosity > 1 then - out = out .. tpl.type_id(n.subtype) + output = output .. format.type_id(n.subtype) end - return out + return output else return tostring(n.subtype) end - assert(false) -end -function tpl.round(number) - local mult = 10^(options.decimalplaces or 0) - return math.floor(number * mult + 0.5) / mult -end -function tpl.length(input) - input = tonumber(input) - input = input / tex.sp('1' .. options.unit) - return string.format('%g%s', tpl.round(input), options.unit) -end -function tpl.fill(number, order, field) - if order ~= nil and order ~= 0 then - if field == 'stretch' then - out = '+' - else - out = '-' - end - return out .. string.format( - '%gfi%s', number / 2^16, - string.rep('l', order - 1) - ) - else - return tpl.length(number) - end -end -tpl.node_colors = { - hlist = {'red', 'bright'}, - vlist = {'green', 'bright'}, - rule = {'blue', 'bright'}, - ins = {'blue'}, - mark = {'magenta'}, - adjust = {'cyan'}, - boundary = {'red', 'bright'}, - disc = {'green', 'bright'}, - whatsit = {'yellow', 'bright'}, - local_par = {'blue', 'bright'}, - dir = {'magenta', 'bright'}, - math = {'cyan', 'bright'}, - glue = {'magenta', 'bright'}, - kern = {'green', 'bright'}, - penalty = {'yellow', 'bright'}, - unset = {'blue'}, - style = {'magenta'}, - choice = {'cyan'}, - noad = {'red'}, - radical = {'green'}, - fraction = {'yellow'}, - accent = {'blue'}, - fence = {'magenta'}, - math_char = {'cyan'}, - sub_box = {'red', 'bright'}, - sub_mlist = {'green', 'bright'}, - math_text_char = {'yellow', 'bright'}, - delim = {'blue', 'bright'}, - margin_kern = {'magenta', 'bright'}, - glyph = {'cyan', 'bright'}, - align_record = {'red'}, - pseudo_file = {'green'}, - pseudo_line = {'yellow'}, - page_insert = {'blue'}, - split_insert = {'magenta'}, - expr_stack = {'cyan'}, - nested_list = {'red'}, - span = {'green'}, - attribute = {'yellow'}, - glue_spec = {'magenta'}, - attribute_list = {'cyan'}, - temp = {'magenta'}, - align_stack = {'red', 'bright'}, - movement_stack = {'green', 'bright'}, - if_stack = {'yellow', 'bright'}, - unhyphenated = {'magenta', 'bright'}, - hyphenated = {'cyan', 'bright'}, - delta = {'red'}, - passive = {'green'}, - shape = {'yellow'}, -} -function tpl.color_code(code) - return string.char(27) .. '[' .. tostring(code) .. 'm' -end -function tpl.color(color, mode, background) - if options.color ~= 'colored' then - return '' - end - local out = '' - local code = '' - if mode == 'bright' then - out = tpl.color_code(1) - elseif mode == 'dim' then - out = tpl.color_code(2) - end - if not background then - if color == 'reset' then code = 0 - elseif color == 'red' then code = 31 - elseif color == 'green' then code = 32 - elseif color == 'yellow' then code = 33 - elseif color == 'blue' then code = 34 - elseif color == 'magenta' then code = 35 - elseif color == 'cyan' then code = 36 - else code = 37 end - else - if color == 'black' then code = 40 - elseif color == 'red' then code = 41 - elseif color == 'green' then code = 42 - elseif color == 'yellow' then code = 43 - elseif color == 'blue' then code = 44 - elseif color == 'magenta' then code = 45 - elseif color == 'cyan' then code = 46 - elseif color == 'white' then code = 47 - else code = 40 end - end - return out .. tpl.color_code(code) -end -function tpl.key_value(key, value) - local out = tpl.color('yellow') .. key .. ': ' - if value then - out = out .. tpl.color('white') .. value .. '; ' - end - return out .. tpl.color('reset') -end -function tpl.char(input) - return string.format('%q', unicode.utf8.char(input)) -end -function tpl.type(type, id) - local out = tpl.color( - tpl.node_colors[type][1], - tpl.node_colors[type][2] - ) - .. string.upper(type) - if options.verbosity > 1 then - out = out .. tpl.type_id(id) - end - return out .. tpl.color('reset') .. ' ' -end -function tpl.callback_variable(variable_name, variable) - if variable ~= nil and variable ~= '' then - tpl.print(variable_name .. ': ' .. tostring(variable)) - end -end -function tpl.line(length) - if length == 'long' then - return '------------------------------------------' - else - return '-----------------------' - end end -function tpl.callback(callback_name, variables) - tpl.print('\n\n') - tpl.print('Callback: ' .. tpl.color('red', '', true) .. - callback_name .. tpl.color('reset') - ) - if variables then - for name, value in pairs(variables) do - if value ~= nil and value ~= '' then - tpl.print(' - ' .. name .. ': ' .. tostring(value)) - end - end - end - tpl.print(tpl.line('long')) -end -function tpl.type_id(id) - return '[' .. tostring(id) .. ']' -end -function tpl.branch(connection_type, connection_state, last) - local c = connection_type - local s = connection_state - local l = last - if c == 'list' and s == 'stop' and l == false then - return ' ' - elseif c == 'field' and s == 'stop' and l == false then - return ' ' - elseif c == 'list' and s == 'continue' and l == false then - return '│ ' - elseif c == 'field' and s == 'continue' and l == false then - return '║ ' - elseif c == 'list' and s == 'continue' and l == true then - return '├─' - elseif c == 'field' and s == 'continue' and l == true then - return '╠═' - elseif c == 'list' and s == 'stop' and l == true then - return '└─' - elseif c == 'field' and s == 'stop' and l == true then - return '╚═' - end -end -function tpl.branches(level, connection_type) - local out = '' - for i = 1, level - 1 do - out = out .. tpl.branch('list', tree.state[i]['list'], false) - out = out .. tpl.branch('field', tree.state[i]['field'], false) - end - if connection_type == 'list' then - out = out .. tpl.branch('list', tree.state[level]['list'], true) - else - out = out .. tpl.branch('list', tree.state[level]['list'], false) - out = out .. tpl.branch('field', tree.state[level]['field'], true) - end - return out -end -function tpl.print(text) - if options.channel == 'log' then - if not log then - log = io.open(tex.jobname .. '_nodetree.log', 'a') - end - log:write(text, '\n') - else - print(' ' .. text) - end -end +--- Build the node tree. +-- @section tree + +local tree = {} + +--- +-- @tparam node head +-- @tparam string field +-- +-- @treturn string function tree.format_field(head, field) - local out = '' - if not head[field] or head[field] == 0 then + local output +-- Character "0" should be printed in a tree, because in TeX fonts the +-- 0 slot usually has a symbol. + if not head[field] or (head[field] == 0 and field ~= "char") then return '' end + if options.verbosity < 2 and -- glyph field == 'font' or @@ -381,37 +866,73 @@ function tree.format_field(head, field) then return '' end + if field == 'prev' or field == 'next' then - out = nodex.node_id(head[field]) + output = node_extended.node_id(head[field]) elseif field == 'subtype' then - out = nodex.subtype(head) + output = format.underscore(node_extended.subtype(head)) elseif field == 'width' or field == 'height' or field == 'depth' or field == 'kern' or field == 'shift' then - out = tpl.length(head[field]) + output = template.length(head[field]) elseif field == 'char' then - out = tpl.char(head[field]) + output = template.char(head[field]) elseif field == 'glue_set' then - out = tpl.round(head[field]) + output = format.number(head[field]) elseif field == 'stretch' or field == 'shrink' then - out = tpl.fill(head[field], head[field .. '_order'], field) + output = template.fill(head[field], head[field .. '_order'], field) else - out = tostring(head[field]) + output = tostring(head[field]) end - return tpl.key_value(field, out) + + return template.key_value(field, output) end + +--- +-- Attributes are key/value number pairs. They are printed as an inline +-- list. The attribute `0` with the value `0` is skipped because this +-- attribute is in every node by default. +-- +-- @tparam node head +-- +-- @treturn string +function tree.format_attributes(head) + if not head then + return '' + end + local output = '' + local attr = head.next + while attr do + if attr.number ~= 0 or (attr.number == 0 and attr.value ~= 0) then + output = output .. tostring(attr.number) .. '=' .. tostring(attr.value) .. ' ' + end + attr = attr.next + end + return output +end + +--- +-- @tparam number level `level` is a integer beginning with 1. +-- @tparam number connection_type The variable `connection_type` +-- is a string, which can be either `list` or `field`. +-- @tparam connection_state `connection_state` is a string, which can +-- be either `continue` or `stop`. function tree.set_state(level, connection_type, connection_state) - if not tree.state[level] then - tree.state[level] = {} + if not tree_state[level] then + tree_state[level] = {} end - tree.state[level][connection_type] = connection_state + tree_state[level][connection_type] = connection_state end + +--- +-- @tparam table fields +-- @tparam number level function tree.analyze_fields(fields, level) local max = 0 - local connection_state = '' + local connection_state for _ in pairs(fields) do max = max + 1 end @@ -424,293 +945,603 @@ function tree.analyze_fields(fields, level) connection_state = 'continue' end tree.set_state(level, 'field', connection_state) - tpl.print(tpl.branches(level, 'field') .. tpl.key_value(field_name)) + nodetree_print( + format.node_begin() .. + template.branches(level, 'field') .. + template.key_value(field_name) .. + format.node_end() .. + format.new_line() + ) tree.analyze_list(recursion_node, level + 1) end end + +--- +-- @tparam node head +-- @tparam number level function tree.analyze_node(head, level) local connection_state - local out = '' + local output if head.next then connection_state = 'continue' else connection_state = 'stop' end tree.set_state(level, 'list', connection_state) - out = tpl.branches(level, 'list') - .. tpl.type(node.type(head.id), head.id) + output = template.branches(level, 'list') + .. template.type(node.type(head.id), head.id) if options.verbosity > 1 then - out = out .. tpl.key_value('no', nodex.node_id(head)) + output = output .. template.key_value('no', node_extended.node_id(head)) end + + -- We store the attributes output to append it to the field list. + local attributes + + -- We store fields which are nodes for later treatment. local fields = {} - for field_id, field_name in pairs(node.fields(head.id, head.subtype)) do - if field_name ~= 'next' and - field_name ~= 'prev' and + + -- Inline fields, for example: char: 'm', width: 25pt, height: 13.33pt, + local output_fields = '' + for _, field_name in pairs(node.fields(head.id, head.subtype)) do + if field_name == 'attr' then + attributes = tree.format_attributes(head.attr) + elseif field_name ~= 'next' and field_name ~= 'prev' and node.is_node(head[field_name]) then fields[field_name] = head[field_name] else - out = out .. tree.format_field(head, field_name) + output_fields = output_fields .. tree.format_field(head, field_name) end end - tpl.print(out) + if output_fields ~= '' then + output = output .. output_fields + end + + -- Append the attributes output if available + if attributes ~= '' then + output = output .. template.key_value('attr', attributes, 'blue') + end + + output = output:gsub(', $', '') + + nodetree_print( + format.node_begin() .. + output .. + format.node_end() .. + format.new_line() + ) + + local property = node.getproperty(head) + if property then + nodetree_print( + format.node_begin() .. + template.branches(level, 'field') .. + ' ' .. + template.colored_string('properties:', 'blue') .. ' ' .. + template.table_inline(property) .. + format.node_end() .. + format.new_line() + ) + end + tree.analyze_fields(fields, level) end + +--- +-- @tparam node head +-- @tparam number level function tree.analyze_list(head, level) while head do tree.analyze_node(head, level) head = head.next end end + +--- +-- @tparam node head function tree.analyze_callback(head) tree.analyze_list(head, 1) - tpl.print(tpl.line('short') .. '\n') + nodetree_print(template.line('short') .. format.new_line()) end -function callbacks.contribute_filter(extrainfo) - tpl.callback('contribute_filter', {extrainfo = extrainfo}) - return true -end -function callbacks.buildpage_filter(extrainfo) - tpl.callback('buildpage_filter', {extrainfo = extrainfo}) - return true -end -function callbacks.pre_linebreak_filter(head, groupcode) - tpl.callback('pre_linebreak_filter', {groupcode = groupcode}) - tree.analyze_callback(head) - return true -end -function callbacks.linebreak_filter(head, is_display) - tpl.callback('linebreak_filter', {is_display = is_display}) - tree.analyze_callback(head) - return true -end -function callbacks.append_to_vlist_filter(head, locationcode, prevdepth, mirrored) - local variables = { - locationcode = locationcode, - prevdepth = prevdepth, - mirrored = mirrored, - } - tpl.callback('append_to_vlist_filter', variables) - tree.analyze_callback(head) - return true -end -function callbacks.post_linebreak_filter(head, groupcode) - tpl.callback('post_linebreak_filter', {groupcode = groupcode}) - tree.analyze_callback(head) - return true -end -function callbacks.hpack_filter(head, groupcode, size, packtype, direction, attributelist) - local variables = { - groupcode = groupcode, - size = size, - packtype = packtype, - direction = direction, - attributelist = attributelist, - } - tpl.callback('hpack_filter', variables) - tree.analyze_callback(head) - return true -end -function callbacks.vpack_filter(head, groupcode, size, packtype, maxdepth, direction, attributelist) - local variables = { - groupcode = groupcode, - size = size, - packtype = packtype, - maxdepth = tpl.length(maxdepth), - direction = direction, - attributelist = attributelist, - } - tpl.callback('vpack_filter', variables) - tree.analyze_callback(head) - return true -end -function callbacks.hpack_quality(incident, detail, head, first, last) - local variables = { - incident = incident, - detail = detail, - first = first, - last = last, - } - tpl.callback('hpack_quality', variables) - tree.analyze_callback(head) -end -function callbacks.vpack_quality(incident, detail, head, first, last) - local variables = { - incident = incident, - detail = detail, - first = first, - last = last, - } - tpl.callback('vpack_quality', variables) - tree.analyze_callback(head) -end -function callbacks.process_rule(head, width, height) - local variables = { - width = width, - height = height, - } - tpl.callback('process_rule', variables) - tree.analyze_callback(head) - return true -end -function callbacks.pre_output_filter(head, groupcode, size, packtype, maxdepth, direction) - local variables = { - groupcode = groupcode, - size = size, - packtype = packtype, - maxdepth = maxdepth, - direction = direction, - } - tpl.callback('pre_output_filter', variables) - tree.analyze_callback(head) - return true -end -function callbacks.hyphenate(head, tail) - tpl.callback('hyphenate') - tpl.print('head:') - tree.analyze_callback(head) - tpl.print('tail:') - tree.analyze_callback(tail) -end -function callbacks.ligaturing(head, tail) - tpl.callback('ligaturing') - tpl.print('head:') - tree.analyze_callback(head) - tpl.print('tail:') - tree.analyze_callback(tail) -end -function callbacks.kerning(head, tail) - tpl.callback('kerning') - tpl.print('head:') - tree.analyze_callback(head) - tpl.print('tail:') - tree.analyze_callback(tail) -end -function callbacks.insert_local_par(local_par, location) - tpl.callback('insert_local_par', {location = location}) - tree.analyze_callback(local_par) - return true -end -function callbacks.mlist_to_hlist(head, display_type, need_penalties) - local variables = { - display_type = display_type, - need_penalties = need_penalties, - } - tpl.callback('mlist_to_hlist', variables) - tree.analyze_callback(head) - return node.mlist_to_hlist(head, display_type, need_penalties) -end -function base.normalize_options() - options.verbosity = tonumber(options.verbosity) - options.decimalplaces = tonumber(options.decimalplaces) -end -function base.set_default_options() - local defaults = { - verbosity = 1, - callback = 'postlinebreak', - engine = 'luatex', - color = 'colored', - decimalplaces = 2, - unit = 'pt', - channel = 'term', - } + +--- Callback wrapper. +-- @section callbacks + +local callbacks = { + + --- + -- @tparam string extrainfo + contribute_filter = function(extrainfo) + template.callback('contribute_filter', {extrainfo = extrainfo}) + return true + end, + + --- + -- @tparam string extrainfo + buildpage_filter = function(extrainfo) + template.callback('buildpage_filter', {extrainfo = extrainfo}) + return true + end, + + --- + -- @tparam string n + -- @tparam string i + build_page_insert = function(n, i) + print('lol') + template.callback('build_page_insert', {n = n, i = i}) + return 0 + end, + + --- + -- @tparam node head + -- @tparam string groupcode + pre_linebreak_filter = function(head, groupcode) + template.callback('pre_linebreak_filter', {groupcode = groupcode}) + tree.analyze_callback(head) + return true + end, + + --- + -- @tparam node head + -- @tparam boolean is_display + linebreak_filter = function(head, is_display) + template.callback('linebreak_filter', {is_display = is_display}) + tree.analyze_callback(head) + return true + end, + + --- + -- @tparam node box + -- @tparam string locationcode + -- @tparam number prevdepth + -- @tparam boolean mirrored + append_to_vlist_filter = function(box, locationcode, prevdepth, mirrored) + local variables = { + locationcode = locationcode, + prevdepth = prevdepth, + mirrored = mirrored, + } + template.callback('append_to_vlist_filter', variables) + tree.analyze_callback(box) + return box + end, + + --- + -- @tparam node head + -- @tparam string groupcode + post_linebreak_filter = function(head, groupcode) + template.callback('post_linebreak_filter', {groupcode = groupcode}) + tree.analyze_callback(head) + return true + end, + + --- + -- @tparam node head + -- @tparam string groupcode + -- @tparam number size + -- @tparam string packtype + -- @tparam string direction + -- @tparam node attributelist + hpack_filter = function(head, groupcode, size, packtype, direction, attributelist) + local variables = { + groupcode = groupcode, + size = size, + packtype = packtype, + direction = direction, + attributelist = attributelist, + } + template.callback('hpack_filter', variables) + tree.analyze_callback(head) + return true + end, + + --- + -- @tparam node head + -- @tparam string groupcode + -- @tparam number size + -- @tparam string packtype + -- @tparam number maxdepth + -- @tparam string direction + -- @tparam node attributelist + vpack_filter = function(head, groupcode, size, packtype, maxdepth, direction, attributelist) + local variables = { + groupcode = groupcode, + size = size, + packtype = packtype, + maxdepth = template.length(maxdepth), + direction = direction, + attributelist = attributelist, + } + template.callback('vpack_filter', variables) + tree.analyze_callback(head) + return true + end, + + --- + -- @tparam string incident + -- @tparam number detail + -- @tparam node head + -- @tparam number first + -- @tparam number last + hpack_quality = function(incident, detail, head, first, last) + local variables = { + incident = incident, + detail = detail, + first = first, + last = last, + } + template.callback('hpack_quality', variables) + tree.analyze_callback(head) + end, + + --- + -- @tparam string incident + -- @tparam number detail + -- @tparam node head + -- @tparam number first + -- @tparam number last + vpack_quality = function(incident, detail, head, first, last) + local variables = { + incident = incident, + detail = detail, + first = first, + last = last, + } + template.callback('vpack_quality', variables) + tree.analyze_callback(head) + end, + + --- + -- @tparam node head + -- @tparam number width + -- @tparam number height + process_rule = function(head, width, height) + local variables = { + width = width, + height = height, + } + template.callback('process_rule', variables) + tree.analyze_callback(head) + return true + end, + + --- + -- @tparam node head + -- @tparam string groupcode + -- @tparam number size + -- @tparam string packtype + -- @tparam number maxdepth + -- @tparam string direction + pre_output_filter = function(head, groupcode, size, packtype, maxdepth, direction) + local variables = { + groupcode = groupcode, + size = size, + packtype = packtype, + maxdepth = maxdepth, + direction = direction, + } + template.callback('pre_output_filter', variables) + tree.analyze_callback(head) + return true + end, + + --- + -- @tparam node head + -- @tparam node tail + hyphenate = function(head, tail) + template.callback('hyphenate') + nodetree_print('head:') + tree.analyze_callback(head) + nodetree_print('tail:') + tree.analyze_callback(tail) + end, + + --- + -- @tparam node head + -- @tparam node tail + ligaturing = function(head, tail) + template.callback('ligaturing') + nodetree_print('head:') + tree.analyze_callback(head) + nodetree_print('tail:') + tree.analyze_callback(tail) + end, + + --- + -- @tparam node head + -- @tparam node tail + kerning = function(head, tail) + template.callback('kerning') + nodetree_print('head:') + tree.analyze_callback(head) + nodetree_print('tail:') + tree.analyze_callback(tail) + end, + + --- + -- @tparam node local_par + -- @tparam string location + insert_local_par = function(local_par, location) + template.callback('insert_local_par', {location = location}) + tree.analyze_callback(local_par) + return true + end, + + --- + -- @tparam node head + -- @tparam string display_type + -- @tparam boolean need_penalties + mlist_to_hlist = function(head, display_type, need_penalties) + local variables = { + display_type = display_type, + need_penalties = need_penalties, + } + template.callback('mlist_to_hlist', variables) + tree.analyze_callback(head) + return node.mlist_to_hlist(head, display_type, need_penalties) + end, +} + +--- Set a single option key value pair. +-- +-- @tparam string key The key of the option pair. +-- @tparam number|string value The value of the option pair. +local function set_option(key, value) if not options then options = {} end - for key, value in pairs(defaults) do - if not options[key] then - options[key] = value - end + if key == 'verbosity' or key == 'decimalplaces' then + options[key] = tonumber(value) + else + options[key] = value end - base.normalize_options() end -function base.set_option(key, value) + +--- Set multiple key value pairs using a table. +-- +-- @tparam table opts Options +local function set_options(opts) if not options then options = {} end - options[key] = value - base.normalize_options() -end -function base.get_option(key) - if not options then - options = {} + for key, value in pairs(opts) do + set_option(key, value) end - if options[key] then - return options[key] +end + +--- Check if the given callback name exists. +-- +-- Throw an error if it doen’t. +-- +-- @tparam string callback_name The name of a callback to check. +-- +-- @treturn string The unchanged input of the function. +local function check_callback_name(callback_name) + local info = callback.list() + if info[callback_name] == nil then + tex.error( + 'Package "nodetree": Unkown callback name or callback alias: "' .. + callback_name .. + '"' + ) end + return callback_name end -function base.get_callback_name(alias) + +--- Get the real callback name from an alias string. +-- +-- @tparam string alias The alias of a callback name or the callback +-- name itself. +-- +-- @treturn string The real callback name. +local function get_callback_name(alias) + local callback_name + -- Listed as in the LuaTeX reference manual. if alias == 'contribute' or alias == 'contributefilter' then - return 'contribute_filter' - elseif alias == 'buildpage' or alias == 'buildpagefilter' then - return 'buildpage_filter' + callback_name = 'contribute_filter' + + -- Formerly called buildpage, now there is a build_page_insert. + elseif alias == 'buildfilter' or alias == 'buildpagefilter' then + callback_name = 'buildpage_filter' + + -- Untested: I don’t know how to invoke this filter. + elseif alias == 'buildinsert' or alias == 'buildpageinsert' then + callback_name = 'build_page_insert' + elseif alias == 'preline' or alias == 'prelinebreakfilter' then - return 'pre_linebreak_filter' + callback_name = 'pre_linebreak_filter' + elseif alias == 'line' or alias == 'linebreakfilter' then - return 'linebreak_filter' + callback_name = 'linebreak_filter' + elseif alias == 'append' or alias == 'appendtovlistfilter' then - return 'append_to_vlist_filter' - elseif alias == 'postline' or alias == 'postlinebreakfilter' then - return 'post_linebreak_filter' + callback_name = 'append_to_vlist_filter' + + -- postlinebreak is not documented. + elseif alias == 'postline' or alias == 'postlinebreak' or alias == 'postlinebreakfilter' then + callback_name = 'post_linebreak_filter' + elseif alias == 'hpack' or alias == 'hpackfilter' then - return 'hpack_filter' + callback_name = 'hpack_filter' + elseif alias == 'vpack' or alias == 'vpackfilter' then - return 'vpack_filter' + callback_name = 'vpack_filter' + elseif alias == 'hpackq' or alias == 'hpackquality' then - return 'hpack_quality' + callback_name = 'hpack_quality' + elseif alias == 'vpackq' or alias == 'vpackquality' then - return 'vpack_quality' + callback_name = 'vpack_quality' + elseif alias == 'process' or alias == 'processrule' then - return 'process_rule' + callback_name = 'process_rule' + elseif alias == 'preout' or alias == 'preoutputfilter' then - return 'pre_output_filter' + callback_name = 'pre_output_filter' + elseif alias == 'hyph' or alias == 'hyphenate' then - return 'hyphenate' + callback_name = 'hyphenate' + elseif alias == 'liga' or alias == 'ligaturing' then - return 'ligaturing' + callback_name = 'ligaturing' + elseif alias == 'kern' or alias == 'kerning' then - return 'kerning' + callback_name = 'kerning' + elseif alias == 'insert' or alias == 'insertlocalpar' then - return 'insert_local_par' + callback_name = 'insert_local_par' + elseif alias == 'mhlist' or alias == 'mlisttohlist' then - return 'mlist_to_hlist' + callback_name = 'mlist_to_hlist' + else - return 'post_linebreak_filter' + callback_name = alias end + return check_callback_name(callback_name) end -function base.register(cb) + +--- Register a callback. +-- +-- @tparam string cb The name of a callback. +local function register_callback(cb) if options.engine == 'lualatex' then luatexbase.add_to_callback(cb, callbacks[cb], 'nodetree') else - id, error = callback.register(cb, callbacks[cb]) + callback.register(cb, callbacks[cb]) end end -function base.register_callbacks() - for alias in string.gmatch(options.callback, '([^,]+)') do - base.register(base.get_callback_name(alias)) - end -end -function base.unregister(cb) + +--- Unregister a callback. +-- +-- @tparam string cb The name of a callback. +local function unregister_callback(cb) if options.engine == 'lualatex' then luatexbase.remove_from_callback(cb, 'nodetree') else - id, error = callback.register(cb, nil) + register_callback(cb, nil) end end -function base.unregister_callbacks() - for alias in string.gmatch(options.callback, '([^,]+)') do - base.unregister(base.get_callback_name(alias)) - end -end -function base.execute() - local c = base.get_callback() - if options.engine == 'lualatex' then - luatexbase.add_to_callback(c, callbacks.post_linebreak_filter, 'nodetree') - else - id, error = callback.register(c, callbacks.post_linebreak_filter) + +--- Exported functions. +-- @section export + +local export = { + set_option = set_option, + set_options = set_options, + + --- + register_callbacks = function() + if options.channel == 'log' or options.channel == 'tex' then + -- nt = nodetree + -- jobname.nttex + -- jobname.ntlog + local file_name = tex.jobname .. '.nt' .. options.channel + io.open(file_name, 'w'):close() -- Clear former content + output_file = io.open(file_name, 'a') + end + for alias in string.gmatch(options.callback, '([^,]+)') do + register_callback(get_callback_name(alias)) + end + end, + + --- + unregister_callbacks = function() + for alias in string.gmatch(options.callback, '([^,]+)') do + unregister_callback(get_callback_name(alias)) + end + end, + + --- Compile a TeX snippet. + -- + -- Write some TeX snippets into a temporary LaTeX file, compile this + -- file using `latexmk` and read the generated `*.nttex` file and + -- return its content. + -- + -- @tparam string tex_markup + -- + -- @treturn string + compile_include = function(tex_markup) + -- Generate a subfolder for all tempory files: _nodetree-jobname. + local parent_path = lfs.currentdir() .. '/' .. '_nodetree-' .. tex.jobname + lfs.mkdir(parent_path) + + -- Generate the temporary LuaTeX or LuaLaTeX file. + example_counter = example_counter + 1 + local filename_tex = example_counter .. '.tex' + local absolute_path_tex = parent_path .. '/' .. filename_tex + output_file = io.open(absolute_path_tex, 'w') + + local format_option = function (key, value) + return '\\NodetreeSetOption[' .. key .. ']{' .. value .. '}' .. '\n' + end + + -- Process the options + local options = + format_option('channel', 'tex') .. + format_option('verbosity', options.verbosity) .. + format_option('unit', options.unit) .. + format_option('decimalplaces', options.decimalplaces) .. + '\\NodetreeUnregisterCallback{post_linebreak_filter}' .. '\n' .. + '\\NodetreeRegisterCallback{' .. options.callback .. '}' + + local prefix = '%!TEX program = lualatex\n' .. + '\\documentclass{article}\n' .. + '\\usepackage{nodetree}\n' .. + options .. '\n' .. + '\\begin{document}\n' + local suffix = '\n\\end{document}' + output_file:write(prefix .. tex_markup .. suffix) + output_file:close() + + -- Compile the temporary LuaTeX or LuaLaTeX file. + os.spawn({ 'latexmk', '-cd', '-pdflua', absolute_path_tex }) + local include_file = assert(io.open(parent_path .. '/' .. example_counter .. '.nttex', 'rb')) + local include_content = include_file:read("*all") + include_file:close() + include_content = include_content:gsub('[\r\n]', '') + tex.print(include_content) + end, + + --- Check for `--shell-escape` + -- + check_shell_escape = function() + local info = status.list() + if info.shell_escape == 0 then + tex.error('Package "nodetree-embed": You have to use the --shell-escape option') + end + end, + + --- Print a node tree. + --- + -- @tparam node head The head node of a node list. + -- @tparam table opts Options as a table. + print = function(head, opts) + if opts and type(opts) == 'table' then + set_options(opts) + end + nodetree_print(format.new_line()) + tree.analyze_list(head, 1) + end, + + --- Format a scaled point value into a formated string. + -- + -- @tparam number sp A scaled point value + -- + -- @treturn string + format_dim = function(sp) + return template.length(sp) + end, + + --- Get a default option that is not changed. + -- @tparam string key The key of the option. + -- + -- @treturn string|number|boolean + get_default_option = function(key) + return default_options[key] end -end -function base.analyze(head) - tpl.print('\n') - tree.analyze_list(head, 1) -end -return base +} + +--- Use export.print +-- @tparam node head +export.analyze = export.print + +return export diff --git a/Master/texmf-dist/tex/luatex/nodetree/nodetree.sty b/Master/texmf-dist/tex/luatex/nodetree/nodetree.sty index ec8dfda1bbf..0432b81ae43 100644 --- a/Master/texmf-dist/tex/luatex/nodetree/nodetree.sty +++ b/Master/texmf-dist/tex/luatex/nodetree/nodetree.sty @@ -8,7 +8,7 @@ %% %% This is a generated file. %% -%% Copyright (C) 2016 by Josef Friedrich <josef@friedrich.rocks> +%% Copyright (C) 2016-2020 by Josef Friedrich <josef@friedrich.rocks> %% ---------------------------------------------------------------------- %% This work may be distributed and/or modified under the conditions of %% the LaTeX Project Public License, either version 1.3c of this license @@ -22,34 +22,33 @@ %% \NeedsTeXFormat{LaTeX2e}[1999/12/01] \ProvidesPackage{nodetree} - [2016/07/18 v1.2 Visualize node lists in a tree view] + [2020/05/29 v2.0 Visualize node lists in a tree view] \input{nodetree} -\directlua{ - nodetree.set_option('engine', 'lualatex') -} \RequirePackage{kvoptions} \SetupKeyvalOptions{ family=NT, - prefix=NT@ + prefix=NTK@ } \DeclareStringOption[term]{channel} -\define@key{NT}{channel}[]{\nodetreeoption[channel]{#1}} +\define@key{NT}{channel}[]{\NodetreeSetOption[channel]{#1}} \DeclareStringOption[postlinebreak]{callback} -\define@key{NT}{callback}[]{\nodetreeoption[callback]{#1}} +\define@key{NT}{callback}[]{\NodetreeSetOption[callback]{#1}} \DeclareStringOption[1]{verbosity} -\define@key{NT}{verbosity}[]{\nodetreeoption[verbosity]{#1}} +\define@key{NT}{verbosity}[]{\NodetreeSetOption[verbosity]{#1}} \DeclareStringOption[colored]{color} -\define@key{NT}{color}[]{\nodetreeoption[color]{#1}} +\define@key{NT}{color}[]{\NodetreeSetOption[color]{#1}} \DeclareStringOption[1]{unit} -\define@key{NT}{unit}[]{\nodetreeoption[unit]{#1}} +\define@key{NT}{unit}[]{\NodetreeSetOption[unit]{#1}} \DeclareStringOption[1]{decimalplaces} -\define@key{NT}{decimalplaces}[]{\nodetreeoption[decimalplaces]{#1}} -\ProcessKeyvalOptions* +\define@key{NT}{decimalplaces}[]{\NodetreeSetOption[decimalplaces]{#1}} +\ProcessKeyvalOptions{NT} \directlua{ - nodetree.set_default_options() nodetree.register_callbacks() } -\newcommand{\nodetreeset}[1]{\setkeys{nodetree}{#1}} +\newcommand{\NodetreeSet}[1]{% + \setkeys{NT}{#1}% +} +\let\nodetreeset\NodetreeSet \endinput %% %% End of file `nodetree.sty'. diff --git a/Master/texmf-dist/tex/luatex/nodetree/nodetree.tex b/Master/texmf-dist/tex/luatex/nodetree/nodetree.tex index 71373b5d716..2451c936eca 100644 --- a/Master/texmf-dist/tex/luatex/nodetree/nodetree.tex +++ b/Master/texmf-dist/tex/luatex/nodetree/nodetree.tex @@ -8,7 +8,7 @@ %% %% This is a generated file. %% -%% Copyright (C) 2016 by Josef Friedrich <josef@friedrich.rocks> +%% Copyright (C) 2016-2020 by Josef Friedrich <josef@friedrich.rocks> %% ---------------------------------------------------------------------- %% This work may be distributed and/or modified under the conditions of %% the LaTeX Project Public License, either version 1.3c of this license @@ -22,26 +22,44 @@ %% \directlua{ nodetree = require('nodetree') - nodetree.set_option('engine', 'luatex') - nodetree.set_default_options() } -\def\nodetreeoption[#1]#2{ +\def\NodetreeSetOption[#1]#2{ \directlua{ nodetree.set_option('#1', '#2') } } -\def\nodetreeregister#1{ +\let\nodetreeoption\NodetreeSetOption +\def\NodetreeResetOption#1{ + \NodetreeSetOption[#1]{% + \directlua{ + tex.print(nodetree.get_default_option('#1')) + }% + }% +} +\def\NodetreeReset{ + \NodetreeResetOption{callback} + \NodetreeResetOption{channel} + \NodetreeResetOption{color} + \NodetreeResetOption{decimalplaces} + \NodetreeResetOption{engine} + \NodetreeResetOption{unit} + \NodetreeResetOption{verbosity} +} +\let\nodetreereset\NodetreeReset +\def\NodetreeRegisterCallback#1{ \directlua{ nodetree.set_option('callback', '#1') nodetree.register_callbacks() } } -\def\nodetreeunregister#1{ +\let\nodetreeregister\NodetreeRegisterCallback +\def\NodetreeUnregisterCallback#1{ \directlua{ nodetree.set_option('callback', '#1') nodetree.unregister_callbacks() } } +\let\nodetreeunregister\NodetreeUnregisterCallback \endinput %% %% End of file `nodetree.tex'. |