diff options
author | Karl Berry <karl@freefriends.org> | 2019-10-02 21:18:19 +0000 |
---|---|---|
committer | Karl Berry <karl@freefriends.org> | 2019-10-02 21:18:19 +0000 |
commit | 40da9ba138cb7756f970eca33d3896daf628c2c9 (patch) | |
tree | f672783eed5ba42c2d67d5d76ff542d14eb1b377 | |
parent | 74b90237d9652cb087fea6622543cf4bd13cfd54 (diff) |
scontents (2oct19)
git-svn-id: svn://tug.org/texlive/trunk@52260 c570f23f-e606-0410-a88d-b1316a301751
-rw-r--r-- | Master/texmf-dist/doc/latex/scontents/README.md | 9 | ||||
-rw-r--r-- | Master/texmf-dist/doc/latex/scontents/scontents.pdf | bin | 244760 -> 266405 bytes | |||
-rw-r--r-- | Master/texmf-dist/source/latex/scontents/scontents.dtx | 1149 | ||||
-rw-r--r-- | Master/texmf-dist/source/latex/scontents/scontents.ins | 53 | ||||
-rw-r--r-- | Master/texmf-dist/tex/latex/scontents/scontents.sty | 281 |
5 files changed, 932 insertions, 560 deletions
diff --git a/Master/texmf-dist/doc/latex/scontents/README.md b/Master/texmf-dist/doc/latex/scontents/README.md index c5ea1504613..cc40a942143 100644 --- a/Master/texmf-dist/doc/latex/scontents/README.md +++ b/Master/texmf-dist/doc/latex/scontents/README.md @@ -1,6 +1,6 @@ ## scontents — Stores LaTeX contents in memory or files -- Version: 1.3 -- Date: 2019/09/24 +- Version: 1.4 +- Date: 2019/10/03 - Author: Pablo González ## Description @@ -21,6 +21,11 @@ The package `scontents` is present in `TeXLive` and `MiKTeX`, use the package manager to install. For a manual installation, put `scontents.dtx` in your working directory and run `tex scontents.dtx`. +## Examples + +The file `scontents.pdf` contains attached examples, which can be extracted +from the PDF viewer or using `pdfdetach -saveall scontents.pdf` from command line. + ## License The scontents package may be modified and distributed under the terms and conditions of the [LaTeX Project Public License](https://www.latex-project.org/lppl/), version 1.3c or greater. diff --git a/Master/texmf-dist/doc/latex/scontents/scontents.pdf b/Master/texmf-dist/doc/latex/scontents/scontents.pdf Binary files differindex 3dd1234ddba..8e48969cc48 100644 --- a/Master/texmf-dist/doc/latex/scontents/scontents.pdf +++ b/Master/texmf-dist/doc/latex/scontents/scontents.pdf diff --git a/Master/texmf-dist/source/latex/scontents/scontents.dtx b/Master/texmf-dist/source/latex/scontents/scontents.dtx index 1aa64dcc3de..fd0504e7a2c 100644 --- a/Master/texmf-dist/source/latex/scontents/scontents.dtx +++ b/Master/texmf-dist/source/latex/scontents/scontents.dtx @@ -1,4 +1,24 @@ % \iffalse meta-comment +% +% Copyright (C) 2019 by Pablo González L <pablgonz@educarchile.cl> +% +% 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 +% 2005/12/01 or later. +% +% This work is "maintained" (as per the LPPL maintenance status) +% by Pablo González Luengo. +% +% This work consists of the file scontents.dtx +% and the derived files scontents.ins, +% scontents.pdf and +% scontents.sty. +% %<*internal> \def\nameofplainTeX{plain} \ifx\fmtname\nameofplainTeX\else @@ -9,7 +29,28 @@ \input l3docstrip.tex \keepsilent \askforoverwritefalse -\nopreamble\nopostamble +\preamble + +Copyright (C) 2019 by Pablo González L <pablgonz@educarchile.cl> + +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 +2005/12/01 or later. + +This work is "maintained" (as per the LPPL maintenance status) +by Pablo González Luengo. + +This work consists of the file scontents.dtx +and the derived files scontents.ins, + scontents.pdf and + scontents.sty. + +\endpreamble \usedir{tex/latex/scontents} \generate{% \file{\jobname.sty}{\from{\jobname.dtx}{package}}% @@ -36,7 +77,7 @@ \makeatother % and later we will copy the write stream opened by imakeidx into \@indexfile % so that entries written to both streams end up in the same file. -\usepackage[top=0.5in,bottom=0.5in,left=2.0in,right=1in,footskip=0.2in,headsep=10pt]{geometry} +\usepackage[top=0.5in,bottom=0.5in,left=2in,right=0.7in,footskip=0.2in,headsep=10pt]{geometry} \usepackage[osf,mono=false,scale=0.95,llscaled=0.95]{libertine} \usepackage{unicode-math} \setmathfont[Scale = 0.95]{latinmodern-math.otf} @@ -58,6 +99,7 @@ \usepackage{hyperxmp,lastpage,imakeidx,microtype,attachfile2} \usepackage{adjustbox,multicol,listings,accsupp,titletoc} \usepackage{scontents} % main +\usepackage[osf,scale=0.80,semibold]{sourcecodepro} \usepackage[contents]{colordoc} % Patching colordoc.sty to work with l3doc.cls @@ -129,15 +171,15 @@ type .choice:, type / tt .code:n = \tl_set:Nn \l_userdoc_meta_font_tl { \ttfamily }, type / rm .code:n = \tl_set:Nn \l_userdoc_meta_font_tl { \rmfamily }, - type .initial:n = tt, + type .initial:n = rm, cf .tl_set:N = \l_userdoc_meta_color_tl, - cf .initial:n = black, + cf .initial:n = optcolor, ac .tl_set:N = \l_userdoc_meta_anglecolor_tl, - ac .initial:n = black, + ac .initial:n = lightgray, sbc .tl_set:N = \l_userdoc_meta_brackcolor_tl, - sbc .initial:n = black, + sbc .initial:n = gray, cbc .tl_set:N = \l_userdoc_meta_bracecolor_tl, - cbc .initial:n = black, + cbc .initial:n = gray, } % Internal commands \cs_new_protected:Npn \userdoc_meta_generic:Nnn #1 #2 #3 @@ -197,30 +239,30 @@ \begin{lrbox}{\boxexaenv}% \begin{minipage}[t]{\marginparwidth}% \raggedright\ttfamily\small - \textcolor{gray}{\textbackslash begin\{\textcolor{mypkgcolor}{\bfseries{#1}}\}\myoarg - [type=tt,sbc=gray,ac=NavyBlue,cf=optcolor]{key=val}}\par% - \hspace{0.5cm}\mymeta[ac=gray,cf=gray]{env ~ contents}\par% - \textcolor{gray}{\textbackslash end\{{\textcolor{mypkgcolor}{\bfseries{#1}}}\}}\par + \textcolor{gray}{\textbackslash begin\{\textcolor{mypkgcolor}{{#1}}\}\myoarg + [type=tt,sbc=gray,ac=lightgray,cf=optcolor]{keyval ~ list}}\par% + \hspace{0.5cm}\mymeta[type=tt,ac=lightgray,cf=gray]{env ~ contents}\par% + \textcolor{gray}{\textbackslash end\{{\textcolor{mypkgcolor}{{#1}}}\}}\par \end{minipage}% \end{lrbox}% \usebox{\boxexaenv} } % \cmdexamp{s m o m o} -\DeclareDocumentCommand{\cmdexamp}{s m o m o} +\DeclareDocumentCommand{\cmdexamp}{o m o m o} { \group_begin: \small\ttfamily \textcolor{mypkgcolor}{\textbackslash#2} - \IfBooleanTF{#1}{ \textcolor{red}{*} }{ \hphantom{*} } - \IfValueT{#3}{ \myoarg[type=tt,sbc=gray,ac=NavyBlue,cf=optcolor]{#3} } + \IfValueT{#1}{ \textcolor{red}{#1} } + \IfValueT{#3}{ \myoarg[type=tt,sbc=gray,ac=lightgray,cf=optcolor]{#3} } \IfValueTF{#5} { - \mymeta[ac=OrangeRed,type=tt,cf=MediumOrchid]{#5}% - \mymeta[type=tt,cbc=OrangeRed,ac=NavyBlue,cf=MediumOrchid]{#4} - \mymeta[ac=OrangeRed,type=tt,cf=MediumOrchid]{#5}% + \mymeta[ac=gray,type=tt,cf=MediumOrchid]{#5}% + \mymeta[type=tt,ac=gray,cf=optcolor]{#4} + \mymeta[ac=gray,type=tt,cf=MediumOrchid]{#5}% } - { \mymarg[type=tt,cbc=OrangeRed,ac=NavyBlue,cf=MediumOrchid]{#4} } + { \mymarg[type=tt,cbc=gray,ac=lightgray,cf=optcolor]{#4} } \par \group_end: \MYSortIndex{Commands}{Commands ~ provide ~ by ~ \textcolor{gray}{scontents}>\texttt{\textbackslash#2}}% @@ -229,41 +271,43 @@ % \keyexamp{mmm} \DeclareDocumentCommand{\keyexamp}{ m m m } { - \par - \adjustbox{outer=-\marginparsep}{\textcolor{black}{\small\ttfamily{#1}}} - \textcolor{gray}{\,\bfseries\texttt{=}}\,{} - \mymarg[type=tt,cbc=OrangeRed,ac=NavyBlue,cf=MediumOrchid]{\small{#2}} - \hfill\textcolor{gray}{\small\textsf{(default: ~ \texttt{#3})}} - \par - \MYSortIndex{Keys}{Keys>\texttt{#1}}% + \par + \adjustbox{outer=-\marginparsep}{\textcolor{black}{\small\ttfamily{#1}}} + \textcolor{gray}{\,\bfseries\texttt{=}}\,{} + \mymarg[type=tt,cbc=gray,ac=lightgray,cf=optcolor]{\small{#2}} + \hfill\textcolor{gray}{ \small (\textsf{default}:~\emph{#3})} + \par + \MYSortIndex{Keys}{Keys>\texttt{#1}}% } % \mypkg{sm} \NewDocumentCommand{\mypkg}{sm} { - \IfBooleanTF{#1} - { - \normalsize{\sffamily\textcolor{mypkgcolor}{s}\textcolor{OrangeRed}{content}\textcolor{mypkgcolor}{s}} - \MYSortIndex{packages}{Packages>\texttt{#2}} - } - { - \textcolor{gray}{\textsf{#2}} - \MYSortIndex{packages}{Packages>\texttt{#2}}% - } + \group_begin: + \IfBooleanTF{#1} + { + \textsf{\textcolor{mypkgcolor}{s}\textcolor{OrangeRed}{content}\textcolor{mypkgcolor}{s}} + \MYSortIndex{packages}{Packages>\texttt{#2}} + } + { + \textcolor{darkgray}{\textsf{#2}} + \MYSortIndex{packages}{Packages>\texttt{#2}}% + } + \group_end: } % \myenv{sm} \DeclareDocumentCommand{\myenv}{sm} { - \IfBooleanTF{#1} - { - \textcolor{mypkgcolor}{\ttfamily{#2}}% - \MYSortIndex{environment}{Environment ~ provide ~ by ~ \textcolor{gray}{scontents}:>\texttt{#2}} - } - { - \textcolor{gray}{\ttfamily{#2}}% - \MYSortIndex{environment}{Environments>\texttt{#2}} - } + \IfBooleanTF{#1} + { + \textcolor{mypkgcolor}{\ttfamily{#2}}% + \MYSortIndex{environment}{Environment ~ provide ~ by ~ \textcolor{gray}{scontents}:>\texttt{#2}} + } + { + \textcolor{darkgray}{\ttfamily{#2}}% + \MYSortIndex{environment}{Environments>\texttt{#2}} + } } % \ics{sm} @@ -271,11 +315,13 @@ { \IfBooleanTF{#1} { - \textcolor{mypkgcolor}{\ttfamily\textbackslash{#2}} + \tl_set:Nn \l_tmpa_tl { #2 } + \regex_replace_once:nnN { (\*) } { \c{textcolor}\cB\{red\cE\}\cB\{\1\cE\} } \l_tmpa_tl + \textcolor{mypkgcolor}{\ttfamily\textbackslash{\tl_use:N \l_tmpa_tl}} \MYSortIndex{Commands}{Commands ~ provide ~ by ~ \textcolor{gray}{scontents}>\texttt{\textbackslash#2}} } { - \textcolor{gray}{\ttfamily\textbackslash{#2}} + \textcolor{darkgray}{\ttfamily\textbackslash{#2}} \MYSortIndex{#2}{\texttt{\textbackslash#2}} } } @@ -302,6 +348,23 @@ } \makeatother +% Custom vertamimsc +\makeatletter +\let\verbatimsc\@undefined +\let\endverbatimsc\@undefined +\makeatother +\usepackage{listings} +\lstnewenvironment{verbatimsc} + { + \lstset{ + language=,% + basicstyle= \ttfamily, + columns = fullflexible, + gobble = 2,% + } + }{} +\makeatother + % Don't copy numbers in code example \newcommand*{\noaccsupp}[1]{\BeginAccSupp{ActualText={}}#1\EndAccSupp{}} @@ -311,46 +374,53 @@ escapechar=`,% showstringspaces=false,% extendedchars=true, % - stringstyle = {\color{red}},% + stringstyle= {\color{red}},% basicstyle=\ttfamily\small,% + alsoletter=-,% % comments morecomment=[l]{\%},% commentstyle=\lmmitalic\small\itshape\color{lightgray},% % Important words 1 - keywordstyle=[1]{\bfseries\color{NavyBlue}},% - keywords=[1]{begin,end,documentclass},% + keywordstyle=[1]{\color{gray}},% + keywords=[1]{begin,end},% % Other words 2 keywordstyle=[2]{\color{blue!75}},% - keywords=[2]{usepackage,section},% + keywords=[2]{usepackage,section,documentclass},% % Other words 3 keywordstyle=[3]{\color{optcolor!85}},% keywords=[3]{document,article},% -% Reserved words 4(inputfile options) - keywordstyle=[4]{\bfseries\color{mypkgcolor}},% - keywords=[4]{scontents,Scontents,getstored,typestored,verbatimsc,endverbatimsc,countsc},% +% Reserved words 4 (scontents pkg) + keywordstyle=[4]{\color{mypkgcolor}},% + keywords=[4]{scontents,Scontents,getstored,typestored,verbatimsc,% + endverbatimsc,countsc,meaningsc},% +% Reserved in red + keywordstyle=[5]{\color{red}},% + keywords=[5]{makeatletter,makeatother,let},% % Reserved in orange - keywordstyle=[5]{\color{OrangeRed}},% - keywords=[5]{makeatletter,makeatother,foreach,DefineVerbatimEnvironment,lstnewenvironment,newminted},% + keywordstyle=[6]{\color{optcolor}},% + keywords=[6]{verb,myverb,store-cmd,store-env,print-env,write-env,% + write-out,width-tab,force-eol,inner,outer,I,J,M,L,Ascheol},% % Reserved in orange - keywordstyle=[6]{\color{red}},% - keywords=[6]{verb,myverb,store-cmd,store-env},% + keywordstyle=[7]{\color{OrangeRed}},% + keywords=[7]{foreach,DefineVerbatimEnvironment,lstnewenvironment,newminted},% % literateee - literate=*{\{}{{\bfseries\textcolor{gray}{\{}}}{1} - {\}}{{\bfseries\textcolor{gray}{\}}}}{1} - {[}{{\bfseries\textcolor{optcolor}{[}}}{1} - {]}{{\bfseries\textcolor{optcolor}{]}}}{1} + literate=*{\{}{{\textcolor{gray}{\{}}}{1} + {\}}{{\textcolor{gray}{\}}}}{1} + {[}{{\textcolor{gray}{[}}}{1} + {]}{{\textcolor{gray}{]}}}{1} {,}{{\textcolor{gray}{,}}}{1} - {\$}{{\textcolor{blue}{\$}}}{1} - {*}{{\bfseries\textcolor{red}{*}}}{1} + {>}{{\textcolor{OrangeRed}{\guillemotright}}}{1} + {*}{{\textcolor{red}{*}}}{1} {@}{{\textcolor{red}{@}}}{1} - {=}{{\textcolor{red}{=}}}{1},% + {\^}{{\textcolor{optcolor}{\textasciicircum}}}{1} + {=}{{\textcolor{gray}{=}}}{1},% }[keywords,tex,comments,strings]% end languaje % \begin{examplecode}[key=val]...\end{examplecode} \lstnewenvironment{examplecode}[1][]{% \lstset{ language=scontents-doc,% - stringstyle = {\color{red}},% + stringstyle= {\color{red}},% basicstyle=\ttfamily\small,% numbersep=1em,% numberstyle=\tiny\color{lightgray}\noaccsupp,% @@ -367,16 +437,16 @@ \lstdefinestyle{inline} { language=scontents-doc,% - numbersep=1em,% - numberstyle=\tiny\color{lightgray}\noaccsupp,% - basicstyle=\ttfamily\small\color{gray},% escapechar=`,% upquote=true,% + numbersep=1em,% + numberstyle=\tiny\color{lightgray}\noaccsupp,% literate=*{\%}{{\bfseries\textcolor{gray}{\%}}}{1} } % Set default \lstinline style \lstset{style=inline} +\lstMakeShortInline[language=scontents-doc,basicstyle=\ttfamily]§ % Get file info \GetFileInfo{\jobname.sty} @@ -467,12 +537,15 @@ % \date{} % \maketitle % +% \begin{scontents}[store-env=abstract,print-env=true] % \begin{abstract} -% The \mypkg*{scontents} package stores valid \hologo{LaTeX} code in memory -% (sequences) using the \mypkg{l3seq} module of \mypkg{expl3}. The stored -% content, including \emph{verbatim} material, can be used as many times -% as desired in the document, additionally can be written to external files. +% The \mypkg*{scontents} package stores valid \hologo{(La)TeX} code in +% \mymeta{sequences} using the \mypkg{l3seq} module of \mypkg{expl3}. +% The \mymeta{stored content}, including \emph{verbatim}, can be used +% as many times as desired in the document, additionally can be written +% to \mymeta{external files}. % \end{abstract} +% \end{scontents} % % \tableofcontents % @@ -480,8 +553,8 @@ % % \section{Motivation and Acknowledgments} % -% In \hologo{LaTeX} there is no direct way to record content for later use, although -% you can do this using \verb|\macros|, recording \meta{verbatim content} is a +% In \hologo{(La)TeX} there is no direct way to record content for later use, although +% you can do this using "\macros", recording \mymeta{verbatim content} is a % problem, usually you can avoid this by creating external files or boxes. The % general idea of this package is to try to imitate this implementation % \emph{buffers} that has \hologo{ConTeXt} which allows you to save content in @@ -517,9 +590,11 @@ % (\url{http://www.latex-project.org/lppl.txt}). The software has the status % \enquote{maintained}. % +% \medskip +% % The \mypkg*{scontents} package loads \mypkg{expl3}, \mypkg{xparse} and -% \mypkg{l3keys2e}. This package can be used with |xelatex|, |lualatex| -% , |pdflatex| and the classical workflow |latex|-|dvips|-|ps2pdf|. +% \mypkg{l3keys2e}. This package can be used with "xelatex", "lualatex" +% , "pdflatex" and the classical workflow §latex>dvips>ps2pdf§. % % \thispagestyle{plain} % @@ -530,16 +605,19 @@ % \section{The \texttt{scontents} package} % \label{sec:pkgscontents} % -% \subsection{Description} +% \subsection{Description of the package and load} % -% The \mypkg*{scontents} package allows to store contents in memory (sequence) -% or external files, provides a user interface style \myoarg{key = val} -% along with the ability to store contents in sequences for later use in -% different parts of the document. In some ways it works very much like -% the \mypkg{filecontentsdef} package, with the difference that it preserves -% the |TAB|s characters in the output files (see \ref{sec:tabcharacter}). +% \begin{scontents}[store-env=description, print-env=true] +% The \mypkg*{scontents} package allows to \mymeta{store contents} in +% \mymeta{sequences} or \mymeta{external files}. In some ways it is +% similar to the \mypkg{filecontentsdef} package, with the difference +% in which the \mymeta{content} is stored. The idea behind this package +% is to get an approach to \hologo{ConTeXt} \enquote{\emph{buffers}} +% by making use \mymeta{sequences}. +% \end{scontents} % -% The package is loaded in the usual way: +% The package uses a \myoarg{key \textnormal{\textcolor{gray}{=}} val} +% system for the options and is loaded in the usual way: % % \iffalse %<*example> @@ -550,12 +628,13 @@ % \iffalse %</example> % \fi +% \vspace*{-5pt} % or % \iffalse %<*example> % \fi \begin{examplecode}[frame=single] -\usepackage`\myoarg[type=tt,cbc=OrangeRed,ac=NavyBlue,cf=optcolor]{key=val}`{scontents} +\usepackage`\small\myoarg{key \textnormal{\textcolor{gray}{=}} val}`{scontents} \end{examplecode} % \iffalse %</example> @@ -564,62 +643,89 @@ % \subsection{The TAB character} % \label{sec:tabcharacter} % -% In a standard \hologo{LaTeX} document, horizontal |TAB|s (\LKeyTab) typed -% from the keyboard are treated as explicit spaces in most contexts. Some -% users use this character to indented the source code of the document and -% depending on the text editor used, some will use real |TAB|s (sometimes -% called \enquote{hard tabs}), others with \enquote{soft tabs} -% (\textvisiblespace\textvisiblespace or \textvisiblespace -% \textvisiblespace\textvisiblespace\textvisiblespace) or both. +% Some users use horizontal "TAB"s \enquote{\LKeyTab} from keyboard to indented the source +% code of the document and depending on the text editor used, some will use real "TAB"s +% (\enquote{hard tabs}), others with \enquote{soft tabs}(\verbvisiblespace\verbvisiblespace{} +% or \verbvisiblespace\verbvisiblespace\verbvisiblespace\verbvisiblespace) or both. % -% At first glance it may seem the same, but the way in which |TAB|s (\enquote{hard tabs}) +% At first glance it may seem the same, but the way in which "TAB"s (\enquote{hard tabs}) % are processed according to the context in which they are found within -% a file, both in reading\footnote{Check the answer given by Ulrich Diez +% a file, both in \mymeta{reading}\footnote{Check the answer given by Ulrich Diez % in \href{https://tex.stackexchange.com/a/508103/7832}{Keyboard TAB -% character in argument v (xparse)}.} and writing\footnote{Check the answer +% character in argument v (xparse)}.} and \mymeta{writing}\footnote{Check the answer % given by Enrico Gregorio in \href{https://tex.stackexchange.com/a/58740/7832}{How to output a -% tabulation into a file}.}, are different and may have adverse consequences. +% tabulation into a file}.} are different and may have adverse consequences. % -% The behavior of this character for the \emph{stored} content can be -% configured with the |widht-tab| key, but, these will be preserved by -% writing an output file, unfortunately, dependent on the \hologo{TeX} -% distribution you have and how the formats were initialized. +% In a standard \hologo{LaTeX} document, the character "TAB" \enquote{\LKeyTab} +% are treated as explicit spaces (in most contexts) and is the behavior when +% \mymeta{stored contents}, but when \mymeta{writing files} these are preserved. % -% With a \hologo{TeX}Live distribution, the formats for |latex|, |pdflatex| -% and |lualatex| are prepared feeding the option |-translate-file=cp227.tcx|, -% that makes the |TAB| character \enquote{printable}. To write a literal -% |TAB| character using |xelatex| you must add the |-8bit| option on command -% line, otherwise you will get \hologo{TeX}-|TAB|s (|^^I|) in the \mymeta{output file}. +% With a \hologo{TeX}Live distribution, the "TAB" character is \enquote{printable} +% for "latex", "pdflatex" and "lualatex", but if you use "xelatex" you +% must add the \texttt{\textcolor{optcolor}{-8bit}} option on the command +% line, otherwise you will get \hologo{TeX}-"TAB" (§^^I§) in the \mymeta{output file}. % -% As a general recommendation \enquote{Do not use |TAB|s unless strictly -% necessary}, for example within a verbatim environment that supports -% this character such as |Verbatim| or |lstlisting| or when you want to -% generate a |MakeFile| file. +% As a general recommendation \enquote{Do not use "TAB" character unless strictly +% necessary}, for example within a \emph{verbatim} environment that supports +% this character such as §Verbatim§ of the package \mypkg{fancyvrb} or §lstlisting§ +% of the package \mypkg{listings} or when you want to generate a §MakeFile§ file. % % \subsection{Configuration of the options} % \label{sec:confopt} % % Most of the options can be passed directly to the package or using the -% command the command \ics*{setupsc}. +% command \ics*{setupsc}. All boolean keys can be passed using the +% equal sign \enquote{\textnormal{\textcolor{optcolor}{=}}} or just the +% name of the key, all unknown keys will return an error. In this section +% are described some of the options, a summary of all options is shown in +% section \ref{sec:optover}. % % \vspace*{-10pt} % % \begin{function}{\setupsc} % \begin{syntax} -% \cmdexamp{setupsc}{key=val} +% \cmdexamp{setupsc}{keyval list} % \end{syntax} % -% The command \ics*{setupsc} configures the options in a global way, +% The command \ics*{setupsc} sets the \mymeta{keys} in a global way, % it can be used both in the preamble and in the body of the document % as many times as desired. % \end{function} % +% \keyexamp{verb-font}{font family}{\textnormal{\ttfamily\textbackslash{}ttfamily}} +% Sets the \mymeta{font family} used to display the \mymeta{stored content} for the +% commands \ics*{typestored} and \ics*{meaningsc}. This key is only available +% as a package option or using \ics*{setupsc}. +% +% \medskip +% +% \keyexamp{store-all}{seq name}{not used} +% It is a \mymeta{meta-key} that sets the §store-env§ key of the \myenv*{scontents} +% environment and the §store-cmd§ key of the \ics*{Scontents} command. This key is +% only available as a package option or using \ics*{setupsc}. +% % \medskip % -% \keyexamp{verb-font}{number}{ \textbackslash{}ttfamily } -% Sets the font type used to display the stored content for the commands -% \ics*{typestored} and \ics*{meaningsc}. This key is only available as -% a package option or using \ics*{setupsc}. +% \keyexamp{print-all}{true \textnormal{\textcolor{lightgray}{\textbar}} false}{false} +% It is a \mymeta{meta-key} that sets the §print-env§ key of the \myenv*{scontents} +% environment and the §print-cmd§ key of the \ics*{Scontents} command. This key is +% only available as a package option or using \ics*{setupsc}. +% +% \medskip +% +% \keyexamp{force-eol}{true \textnormal{\textcolor{lightgray}{\textbar}} false}{false} +% Sets if the end of line for the \mymeta{stored content} is hidden or not. +% This key is necessary only if the last line is the closing of some +% environment defined by the \mypkg{fancyvrb} package as §\end{Verbatim}§ +% or another environment that does not support a comments \enquote{\textcolor{gray}{\%}} +% after closing §\end{...}%§. This key is available for the \myenv*{scontents} +% environment and the \ics*{Scontents} command. +% +% \keyexamp{width-tab}{integer}{1} +% Sets the equivalence in \mymeta{spaces} for the character "TAB" +% used when displaying stored content in \emph{verbatim style}. The value +% must be a \mymeta{positive integer}. This key is available for the \ics*{typestored} +% and the \ics*{meaningsc} commands. % % \subsection{Options Overview} % \label{sec:optover} @@ -627,18 +733,21 @@ % \newcommand*{\xmark}{\textcolor{red}{✘}}% % \newcommand*{\cmark}{\textcolor{green}{✔}}% % -% Summary table of available options. +% Summary of available options. % % \setlength{\tabcolsep}{0.25em} +% \begin{center} +% \small % \begin{tabular}{cccccccc} % \toprule -% \texttt{key} &package &\ics{setupsc} &\myenv*{scontents} &\ics*{Scontents} &\ics*{Scontents*} &\ics*{typestored} &\ics*{meaningsc}\\ +% \texttt{key} &package &\ics{setupsc} &\myenv*{scontents} &\ics*{Scontents} &\ics*{Scontents*} &\ics*{typestored} &\ics*{meaningsc}\\ % \midrule % \texttt{store-env} & \cmark & \cmark & \cmark & \xmark & \xmark & \xmark & \xmark \\ % \texttt{store-cmd} & \cmark & \cmark & \xmark & \cmark & \cmark & \xmark & \xmark \\ % \texttt{print-env} & \cmark & \cmark & \cmark & \xmark & \xmark & \xmark & \xmark \\ % \texttt{print-cmd} & \cmark & \cmark & \xmark & \cmark & \cmark & \xmark & \xmark \\ -% \texttt{print-all} & \cmark & \cmark & \cmark & \xmark & \xmark & \xmark & \xmark \\ +% \texttt{print-all} & \cmark & \cmark & \xmark & \xmark & \xmark & \xmark & \xmark \\ +% \texttt{store-all} & \cmark & \cmark & \xmark & \xmark & \xmark & \xmark & \xmark \\ % \texttt{write-env} & \xmark & \xmark & \cmark & \xmark & \xmark & \xmark & \xmark \\ % \texttt{write-out} & \xmark & \xmark & \cmark & \xmark & \xmark & \xmark & \xmark \\ % \texttt{width-tab} & \cmark & \cmark & \xmark & \xmark & \xmark & \cmark & \cmark \\ @@ -646,14 +755,15 @@ % \texttt{verb-font} & \cmark & \cmark & \xmark & \xmark & \xmark & \xmark & \xmark \\ % \bottomrule % \end{tabular} +% \end{center} % % \section{User interface} % \label{sec:interface} % -% The \emph{user interface} provided by this package consists in \myenv*{scontents} -% environment, \ics*{Scontents} and \ics*{Scontents*} commands to stored -% contents and \ics*{getstored} command to get the \meta{stored content} -% along with other utilities described in this documentation. +% The user interface consists in \myenv*{scontents} environment, \ics*{Scontents} +% and \ics*{Scontents*} commands to \mymeta{stored content} and \ics*{getstored} +% command to get the \mymeta{stored content} along with other utilities described +% in this documentation. % % \subsection{The environment \env{scontents}} % \label{sec:scontents} @@ -665,91 +775,92 @@ % \envexamp{scontents} % \end{syntax} % -% The \myenv*{scontents} environment allows you to save the content to memory -% or external files in a similar way to the package \mypkg{filecontentsdef}. -% This allows you to record content, including \emph{verbatim}, for later reuse. +% The \myenv*{scontents} environment allows you to \mymeta{store} and \mymeta{write} +% content, including \emph{verbatim} material. After the package has been loaded, +% the environment can be used both in the preamble and in the body of the document. % -% Some considerations to keep in mind, |\begin{scontents}| and |\end{scontents}| -% must be on different lines, the \myoarg{key=val} options must be passed on -% \mymeta{one line} right after starting the environment and |TAB|s characters -% are preserved when writing an \mymeta{external file}. +% For the correct operation §\begin{scontents}§ and §\end{scontents}§ must be in +% different lines, all \mymeta{keys} must be passed in a \mymeta{single line} separated +% by commas \enquote{without vertical spaces} and \enquote{without separation} of +% the start of the environment. % \end{function} % -% The environment can be nested complying with the above considerations -% and bearing in mind that within it should not be written literally, as a -% comment or within verbatim environments |\begin{scontents}| and |\end{scontents}|. -% For example: +% Comments \enquote{\textcolor{gray}{\%}} or \enquote{any character} after +% §\begin{scontents}§ or \myoarg{keyval list} on the same line are not +% supported, the package will return an \enquote{error} message if this happens. +% In a similar way comments \enquote{\textcolor{gray}{\%}} or \enquote{any character} after +% §\end{scontents}§ on the same line the package will return a \enquote{warning} message. +% +% The environment can be \mymeta{nested} if it is properly balanced and +% does not appear \enquote{literally} in commented lines or in some \emph{verbatim} +% environment or command. As an example: % % \iffalse %<*example> % \fi \begin{examplecode}[frame=single] \begin{scontents}[store-env=outer] -This text is in the outermost environment. +This text is in the outer environment (before nested). \begin{scontents}[store-env=inner] -This text is found in the most inner environment. +This text is found in the inner environment (inside of nested). \end{scontents} -This text is in the outermost environment. +This text is in the outer environment (after nested). \end{scontents} \end{examplecode} % \iffalse %</example> % \fi % +% Of course, content stored in the \mymeta{inner} sequence is only available +% after content stored in the \mymeta{outer} sequence one has been retrieved, +% either by using the key §print-env§ or §\getstored§ command. +% +% It is advisable to store content within sequences with different names, +% so as not to get lost in the order in which content is stored. +% % \subsection*{Options for environment} % % The environment options can be configured globally using option -% in package or the \ics*{setupsc} command and locally -% using \myoarg{key=val} in the environment. -% -% \medskip +% in package or the \ics*{setupsc} command and locally using +% \myoarg{key \textnormal{\textcolor{gray}{=}} val} in the environment. +% The key §force-eol§ is available for this environment. % % \keyexamp{store-env}{seq name}{contents} -% The name of the \mymeta{sequence} in which the content recorded by the -% environment was stored. -% -% \medskip -% -% \keyexamp{print-env}{true\textbar false}{false} -% It will show the current content of the environment. +% Sets the name of the \mymeta{sequence} in which the contents will be +% stored. If the sequence does not exist, it will be created globally. % % \medskip % -% \keyexamp{force-eol}{true\textbar false}{false} -% This key is only necessary if the last line inside the environment is -% |\end{Verbatim}| or the |\end{...}| of some environment created with -% the package \mypkg{fancyvrb}. This adds an extra line to the \ics*{typestored} -% output. +% \keyexamp{print-env}{true \textnormal{\textcolor{lightgray}{\textbar}} false}{false} +% Sets if the \mymeta{stored content} is displayed or not at the time of +% running the environment. The content is extracted from the \mymeta{sequence} +% in which it is stored. % -% \medskip +% \newpage % % \keyexamp{write-env}{file.ext}{not used} -% In addition to storing the content of the environment will write this -% in an external \mymeta{file.ext}, if \mymeta{file.ext} exists it will -% be overwritten. The \mymeta{file.ext} will be created in the working -% directory, relative or absolute paths are not supported, the way the -% external \mymeta{file.ext} is recorded is similar to that produced by -% \myenv{filecontents*} environment. If the content within the environment -% has literal |TAB|s they will be recorded in \mymeta{file.ext}. -% -% To write a literal |TAB| character using |xelatex| you must add the |-8bit| -% option on command line, otherwise you will get \hologo{TeX}-|TAB|s (|^^I|) in -% the \mymeta{output file}. +% Sets the name of the \mymeta{external file} in which the \mymeta{contents} of +% the environment will be written. The \mymeta{file.ext} will be created +% in the working directory, if \mymeta{file.ext} exists it will be overwritten, +% relative or absolute paths are not supported. +% The characters "TAB"s will be written in \mymeta{file.ext} and the \mymeta{contents} +% will be stored in the sequence established at that time. \hologo{XeLaTeX} users +% using the "TAB" character must add \texttt{\textcolor{optcolor}{-8bit}} +% at the command line, otherwise you will get \hologo{TeX}-"TAB" (§^^I§) +% in \mymeta{file.ext}. % % \medskip % % \keyexamp{write-out}{file.ext}{not used} -% It will write the contents in an external \mymeta{file.ext}, but, it -% will not store the contents of this one. The \mymeta{file.ext} will be -% created in the working directory, relative or absolute paths are not -% supported. The way the external \mymeta{file.ext} is recorded is similar -% to that produced by \myenv{filecontents*} environment. If the content -% within the environment has literal |TAB|s they will be recorded in -% \mymeta{file.ext}. -% -% To write a literal |TAB| character using |xelatex| you must add the |-8bit| -% option on command line, otherwise you will get \hologo{TeX}-|TAB|s (|^^I|) in -% the \mymeta{output file}. +% Sets the name of the \mymeta{external file} in which the \mymeta{contents} of +% the environment will be written. The \mymeta{file.ext} will be created +% in the working directory, if \mymeta{file.ext} exists it will be overwritten, +% relative or absolute paths are not supported. +% The characters "TAB"s will be written in \mymeta{file.ext}, the rest of the +% \mymeta{keys} will not be available and the \mymeta{contents} will NOT +% be stored in any sequence. \hologo{XeLaTeX} users using the "TAB" character +% must add \texttt{\textcolor{optcolor}{-8bit}} at the command line, +% otherwise you will get \hologo{TeX}-"TAB" (§^^I§) in \mymeta{file.ext}. % % \subsection{The command \cs{Scontents}} % \label{sec:Scontents} @@ -758,27 +869,29 @@ This text is in the outermost environment. % % \begin{function}{\Scontents} % \begin{syntax} -% \cmdexamp{Scontents}[key=val]{argument} -% \cmdexamp*{Scontents}[key=val]{argument} -% \cmdexamp*{Scontents}[key=val]{argument}[del] +% \cmdexamp{Scontents}[key \textnormal{\textcolor{gray}{=}} val]{argument} +% \cmdexamp[*]{Scontents}[key \textnormal{\textcolor{gray}{=}} val]{argument} +% \cmdexamp[*]{Scontents}[key \textnormal{\textcolor{gray}{=}} val]{argument}[del] % \end{syntax} % \end{function} % -% The \ics*{Scontents} command reads the \mymeta{argument} in standard -% mode. It is not possible to pass environments such as \meta{verbatim}, +% The \ics*{Scontents} command reads the \mymarg{argument} in standard +% mode. It is not possible to pass environments such as \emph{verbatim}, % but it is possible to use the implementation of \ics{Verb} provided by % the \mypkg{fvextra} package for contents on one line and \ics{lstinline} % from \mypkg{listings} package, but it is preferable to use the starred % version. % -% The \ics*{Scontents*} command reads the \mymeta{argument} under verbatim +% The \ics*{Scontents*} command reads the \mymarg{argument} under \emph{verbatim} % category code regimen. If its first delimiter is a brace, it will be -% assumed that the \mymeta{argument} is nested into braces. Otherwise it -% will be assumed that the ending of that argument is delimited by that -% first delimiter-like the argument of \ics{verb}. Blank lines are preserved, -% escaped |\{| and |\}| must also be balanced if the argument is used -% with braces and |TAB|s characters typed from the keyboard are converted -% into spaces. +% assumed that the \mymarg{argument} is nested into braces. Otherwise it +% will be assumed that the ending of that \mymeta{argument} is delimited by that +% first delimiter \mymeta[cf=MediumOrchid]{del} like command \ics{verb}. +% +% Blank lines are preserved, escaped braces \enquote{\texttt{\textcolor{gray}{\textbackslash\hspace{-1pt}\{}}} and +% \enquote{\texttt{\textcolor{gray}{\textbackslash\}}}} must also be +% balanced if the argument is used with braces and "TAB"s characters typed +% from the keyboard are converted into spaces. % % Both versions can be used anywhere in the document and cannot be used % as an \mymeta{argument} for other command. @@ -786,27 +899,20 @@ This text is in the outermost environment. % \subsection*{Options for command} % \label{sec:optcmdsc} % -% The command options (including starred version) can be configured globally -% using option in package or the \ics*{setupsc} command and locally -% using \myoarg{key=val}. -% \medskip +% The command options can be configured globally using option in package +% or the \ics*{setupsc} command and locally using \myoarg{key \textnormal{\textcolor{gray}{=}} val}. +% The key §force-eol§ is available for this command. % % \keyexamp{store-cmd}{seq name}{contents} -% The name of the sequence in which the content recorded by \ics*{Scontents} -% was stored. +% Sets the name of the \mymeta{sequence} in which the contents will be stored. +% If the sequence does not exist, it will be created globally. % % \medskip % -% \keyexamp{print-cmd}{true\textbar{}false}{false} -% It will show the current content of \ics*{Scontents}. -% -% \medskip -% -% \keyexamp{force-eol}{true\textbar{}false}{false} -% This key is only necessary if the last line inside the command is -% |\end{Verbatim}| or the |\end{...}| of some environment created with -% the package \mypkg{fancyvrb}. This adds an extra line to the \ics*{typestored} -% output. +% \keyexamp{print-cmd}{true \textnormal{\textcolor{lightgray}{\textbar}} false}{false} +% Sets if the \mymeta{stored content} is displayed or not at the time of +% running the command. The content is extracted from the \mymeta{sequence} +% in which it is stored. % % \subsection{The command \cs{getstored}} % \label{sec:getstored} @@ -819,11 +925,11 @@ This text is in the outermost environment. % \end{syntax} % \end{function} % -% The command \ics*{getstored} gets the content stored in \meta{seq name} +% The command \ics*{getstored} gets the content stored in \mymeta{seq name} % according to the \mymeta{index} in which it was stored. The command is -% robust and can be used as an \meta{argument} for another command. If the -% optional argument is not passed it defaults to the last element saved -% in the \meta{seq name}. +% robust and can be used as an \mymeta{argument} for another command. If the +% optional argument is not passed it defaults to the first element stored +% in the \mymeta{seq name}. % % \subsection{The command \cs{typestored}} % \label{sec:typestored} @@ -832,22 +938,24 @@ This text is in the outermost environment. % % \begin{function}{\typestored} % \begin{syntax} -% \cmdexamp{typestored}[index, width-tab=number]{seq name} +% \cmdexamp{typestored}[index\textnormal{\textcolor{gray}{,}} width-tab \textnormal{\textcolor{gray}{=}} number]{seq name} % \end{syntax} -% \end{function} -% % The command \ics*{typestored} internally places the content stored in -% the \meta{seq name} into the \myenv*{verbatimsc} environment. The \mymeta{index} +% the \mymeta{seq name} into the \myenv*{verbatimsc} environment. The \mymeta{index} % number corresponds to the position in which the content is stored in -% the \meta{seq name}. +% the \mymeta{seq name}. +% \end{function} % -% If the optional argument is not passed it defaults to the last element -% saved in the \meta{seq name}. -% \medskip +% If the optional argument is not passed it defaults to the first element +% stored in the \mymeta{seq name}. The key §width-tab§ is available for +% this command. % -% \keyexamp{width-tab}{number}{ 1 } -% Establishes the equivalence in \mymeta{spaces} for the character |TAB| -% typed from the keyboard. The value must be a \mymeta{positive integer}. +% The \mypkg{verbatim} package is not compatible with the implementation +% of the \myenv*{verbatimsc} environment used by this command, if you are +% a user of that package consider customizing the \myenv*{verbatimsc} +% environment. +% +% \newpage % % \subsection{The environment \env{verbatimsc}} % \label{sec:verbatimsc} @@ -855,13 +963,16 @@ This text is in the outermost environment. % \vspace*{-10pt} % % \begin{function}{verbatimsc} -% Internal environment used by \cs{typestored} to display \meta{verbatim style} +% Internal environment used by \ics*{typestored} to display \mymeta{verbatim style} % contents. % \end{function} % % One consideration to keep in mind is that this is a \emph{representation} -% of the content in a \meta{verbatim} environment and not a real \meta{verbatim} -% environment. The \myenv*{verbatimsc} environment can be customized in the +% of the \mymeta{stored content} in a \emph{verbatim} environment and not +% a real \emph{verbatim} environment. +% +% +% The \myenv*{verbatimsc} environment can be customized in the % following ways: % % Using the package \mypkg{fancyvrb}: @@ -929,19 +1040,16 @@ This text is in the outermost environment. % % \begin{function}{\meaningsc} % \begin{syntax} -% \cmdexamp{meaningsc}[index, width-tab=number]{seq name} +% \cmdexamp{meaningsc}[index\textnormal{\textcolor{gray}{,}} width-tab \textnormal{\textcolor{gray}{=}} number]{seq name} % \end{syntax} % The command \ics*{meaningsc} executes \ics{meaning} on the content stored -% in \meta{seq name}. The \mymeta{index} number corresponds to the position -% in which the content is stored in the \meta{seq name}. If the optional -% argument is not passed it defaults to the last element saved in the \meta{seq name}. +% in \mymeta{seq name}. The \mymeta{index} number corresponds to the position +% in which the content is stored in the \mymeta{seq name}. % \end{function} % -% \medskip -% -% \keyexamp{width-tab}{number}{ 1 } -% Establishes the equivalence in \mymeta{spaces} for the character |TAB| -% typed from the keyboard. The value must be a \mymeta{positive integer}. +% If the optional argument is not passed it defaults to the first element +% stored in the \mymeta{seq name}. The key §width-tab§ is available for +% this command. % % \subsection{The command \cs{countsc}} % \label{sec:countsc} @@ -952,23 +1060,89 @@ This text is in the outermost environment. % \begin{syntax} % \cmdexamp{countsc}{seq name} % \end{syntax} -% The command \ics*{countsc} count a number of contents stored in \meta{seq name}. +% The command \ics*{countsc} count a number of contents stored in \mymeta{seq name}. % \end{function} % -% \subsection{The command \cs{cleansc}} +% \subsection{The command \cs{cleanseqsc}} % \label{sec:cleansc} % % \vspace*{-10pt} % % \begin{function}{\cleanseqsc} % \begin{syntax} -% \cmdexamp{cleansc}{seq name} +% \cmdexamp{cleanseqsc}{seq name} % \end{syntax} -% The command \ics*{cleansc} remove all contents stored in \meta{seq name}. +% The command \ics*{cleanseqsc} remove all contents stored in \mymeta{seq name}. % \end{function} % % \newpage % +% \pdfstringdefDisableCommands{% +% \RenewExpandableDocumentCommand{\mypkg}{sm}{#2}% +% } +% \section{The \mypkg*{scontents} package in action} +% Remember the abstract on the first page?, this is it: +% +% \getstored{abstract} +% +% And the description of the package? +% +% \getstored{description} +% +% \medskip +% +% I've only written: +% +% \typestored{abstract} +% +% and +% +% \typestored{description} +% +% Of course, I didn't copy and paste. The real code they were written with is: +% +% \iffalse +%<*example> +% \fi +\begin{examplecode}[numbers=left] +\begin{scontents}[store-env=abstract,print-env=true] +\begin{abstract} +The \mypkg*{scontents} package stores valid \hologo{(La)TeX} code in +\mymeta{sequences} using the \mypkg{l3seq} module of \mypkg{expl3}. +The \mymeta{stored content}, including \emph{verbatim}, can be used +as many times as desired in the document, additionally can be written +to \mymeta{external files}. +\end{abstract} +\end{scontents} +\end{examplecode} +% \iffalse +%</example> +% \fi +% +% and +% +% \iffalse +%<*example> +% \fi +\begin{examplecode}[numbers=left] +\begin{scontents}[store-env=description, print-env=true] +The \mypkg*{scontents} package allows to \mymeta{store contents} in +\mymeta{sequences} or \mymeta{external files}. In some ways it is +similar to the \mypkg{filecontentsdef} package, with the difference +in which the \mymeta{content} is stored. The idea behind this package +is to get an approach to \hologo{ConTeXt} \enquote{\emph{buffers}} +by making use \mymeta{sequences}. +\end{scontents} +\end{examplecode} +% \iffalse +%</example> +% \fi +% +% I stored the content in memory and then ran §\getstored§ and +% §\typestored§. This is one of the ways you can use \mypkg*{scontents}. +% +% \newpage +% % \section{Examples} % % These are some (adapted) examples that have served as inspiration for @@ -988,7 +1162,6 @@ This text is in the outermost environment. \newtheorem{ex}{Exercise} \begin{document} \section{Problems} - \begin{ex} First exercise \Scontents{ @@ -1004,7 +1177,6 @@ Second exercise \end{ex} \section{Solutions} - \foreach \i in {1,...,\countsc{solutions}} { \noindent\textbf{\i} \getstored[\i]{solutions}\par } @@ -1031,27 +1203,27 @@ Second exercise \usepackage{pgffor} \pagestyle{empty} \begin{document} - +% not starred \Scontents{ Prove that \[x^n+y^n=z^n\] is not solvable in positive integers if $n$ is at most $-3$.\par } - -\Scontents*{Refute the existence of black holes in less than $140$ characters.} - -\begin{scontents}[write-env=\jobname-3.txt] +% starred +\Scontents*|Refute the existence of black holes in less than $140$ characters.| +% write environment to \jobname.txt +\begin{scontents}[write-env=\jobname.txt] \def\NSA{NSA}% Prove that factorization is easily done via probabilistic algorithms and advance evidence from knowledge of the names of its employees in the seventies that the \NSA\ has known that for 40 years.\par \end{scontents} - +% see all stored \foreach \i in {1,...,3} { \begin{itemize} \item \getstored[\i]{defexercise} \end{itemize}} - -\section{\getstored[2]{defexercise}} % \getstored are robust :) +% \getstored are robust :) +\section{\getstored[2]{defexercise}} \end{document} \end{scontents} % \iffalse @@ -1131,8 +1303,7 @@ Something with no label \textbf{Let's print them} -This is a: \getstored[1]{a} - +This is a: \getstored[1]{a}\par This is b: \getstored[2]{a} \textbf{Print all of them} @@ -1226,21 +1397,17 @@ Prove new \Verb*{ fancyvrb whit braces } and environment \verb+Verbatim*+ \end{scontents} \section{Test \texttt{\textbackslash Scontents} whit \texttt{fancyvrb}} - \Scontents{ We have coded this in \LaTeX: $E=mc^2$.} \section{Test \texttt{\textbackslash getstored}} - \getstored[1]{contents}\par \getstored[2]{contents} \section{Test \texttt{\textbackslash meaningsc}} - \meaningsc[1]{contents}\par \meaningsc[2]{contents} \section{Test \texttt{\textbackslash typestored}} - \typestored[1]{contents} \typestored[2]{contents} \end{document} @@ -1249,7 +1416,8 @@ Prove new \Verb*{ fancyvrb whit braces } and environment \verb+Verbatim*+ %</example> % \fi % -% Customization of \myenv*{verbatimsc} using the \mypkg{fancyvrb} and \mypkg{tcolorbox} package +% Customization of \myenv*{verbatimsc} using the \mypkg{fancyvrb} and +% \mypkg{tcolorbox} package % \textattachfile[color=0 0 1]{scexamp6.ltx}{\faFile*[regular]}. % \lstinputlisting[language=scontents-doc,numbers=left]{scexamp6.ltx} % @@ -1283,7 +1451,6 @@ Prove new \Verb*{ fancyvrb whit braces } and environment \verb+Verbatim*+ \setlength{\parindent}{0pt} \pagestyle{empty} \begin{document} - \section{Test \texttt{\textbackslash begin\{scontents\}} whit \texttt{listings}} Test \verb+{scontents}+ \par @@ -1302,12 +1469,10 @@ Prove \lstinline[basicstyle=\ttfamily]| lstinline | and environment \verb+Verbat and more.+ \section{Test \texttt{\textbackslash getstored}} - \getstored[2]{contents}\par \getstored[1]{contents} \section{Test \texttt{\textbackslash typestored}} - \typestored[1]{contents} \typestored[2]{contents} \end{document} @@ -1326,7 +1491,8 @@ and more.+ %<*example> % \fi \begin{scontents}[write-out=scexamp8.ltx] -\documentclass{article} % need --shell-escape +% need --shell-escape +\documentclass{article} \usepackage{scontents} \makeatletter \let\verbatimsc\@undefined @@ -1381,13 +1547,21 @@ No tab % development, from the first public implementation using the \mypkg{filecontentsdef} % package to the current version with only \mypkg{expl3}. % -% \setlist[itemize,1]{label=\textendash, wide=0.5em, nosep, noitemsep, leftmargin=10pt} +% \setlist[itemize,1]{label=\textendash,wide=0.5em,nosep,noitemsep,leftmargin=10pt} % \newlength\descrwidth % \settowidth{\descrwidth}{\textsf{v1.0, (ctan), 2019/07/30} } % -% \begin{description}[font=\small\sffamily, wide=0pt, style=multiline, leftmargin=\descrwidth, nosep, noitemsep] +% \begin{description}[font=\small\sffamily,wide=0pt,style=multiline,leftmargin=\descrwidth,nosep,noitemsep] % \item [\fileversion{} (ctan), \filedate] % \begin{itemize} +% \item Add |store-all| key. +% \item Messages and keys were separated. +% \item Restructuring of documentation. +% \item Now the version of |expl3| is checked instead of |xparse|. +% \item The internal behavior of \verb+force-eol+ has been modified. +% \end{itemize} +% \item [v1.3 (ctan), 2019/09/24] +% \begin{itemize} % \item The environment can now nest. % \item Added \verb+force-eol+, \verb+verb-font+ and \verb+width-tab+ keys. % \item The extra space has been removed when you run \verb+\getstored+. @@ -1419,7 +1593,7 @@ No tab % \newpage % % \StopEventually{^^A -% \newgeometry{top=0.5in,bottom=0.5in,left=1.0in,right=1in,footskip=0.2in,headsep=10pt} +% \newgeometry{top=0.5in,bottom=0.5in,left=1.0in,right=0.5in,footskip=0.2in,headsep=10pt} % \addtocontents{toc}{\protect\setcounter{tocdepth}{2}} % \cleardoublepage % \phantomsection @@ -1444,22 +1618,20 @@ No tab % Then, we can give the traditional declaration of a package written with % \pkg{expl3} and the necessary packages for its operation. % -%%^^A Initial declaration of the package % \begin{macrocode} \RequirePackage{l3keys2e} \RequirePackage{xparse}[2019/05/28] -\ProvidesExplPackage{scontents}{2019/09/24}{1.3} +\ProvidesExplPackage{scontents}{2019/10/03}{1.4} {Stores LaTeX contents in memory or files} % \end{macrocode} % -% A check to make sure that \pkg{xparse} is not too old +% A check to make sure that \pkg{expl3} is not too old % -%%^^A Checking the version of xparse % \begin{macrocode} -\@ifpackagelater { xparse } { 2019/05/03 } +\@ifpackagelater { expl3 } { 2019/09/19 } { } { - \PackageError { scontents } { Support~package~xparse~too~old } + \PackageError { scontents } { Support~package~expl3~too~old } { You~need~to~update~your~installation~of~the~bundles~ 'l3kernel'~and~'l3packages'.\MessageBreak @@ -1471,10 +1643,9 @@ No tab % % \subsection{Definition of common keys} % -% We create some common keys that will be used by the options passed to +% We create some common \mymeta{keys} that will be used by the options passed to % the package as well as by the environments and commands defined. % -%%^^A Common keys available as package options % \begin{macrocode} \keys_define:nn { scontents } { @@ -1501,13 +1672,15 @@ No tab width-tab .value_required:n = true, print-all .meta:n = { print-env = #1 , print-cmd = #1 }, print-all .default:n = true, - unknown .code:n = { \@@_parse_unknown_key:n {#1} } + store-all .meta:n = { store-env = #1 , store-cmd = #1 }, + store-all .value_required:n = true } % \end{macrocode} % -% We process the keys as options passed on to the package. +% We process the \mymeta{keys} as options passed on to the package, the +% package \pkg{l3keys2e} will verify the \mymeta{keys} and will return +% an error when they are \emph{unknown}. % -%%^^A Process options for package % \begin{macrocode} \ProcessKeysOptions { scontents } % \end{macrocode} @@ -1524,7 +1697,6 @@ No tab % of an environment as it's being read, and \cs{l_@@_temp_tl} and % \cs{g_@@_temp_tl} are generic temporary token lists. % -%%^^A Internal token list vars % \begin{macrocode} \tl_new:N \l_@@_macro_tmp_tl \tl_new:N \l_@@_fname_out_tl @@ -1539,7 +1711,6 @@ No tab % requested to \cs{typestored} or \cs{meaningsc}. \cs{l_@@_env_nesting_int} % stores the current nesting level of the \env{scontents} environment. % -%%^^A Internal int vars % \begin{macrocode} \int_new:N \l_@@_seq_item_int \int_new:N \l_@@_env_nesting_int @@ -1550,9 +1721,8 @@ No tab % \begin{macro}{\l_@@_writing_bool,\l_@@_storing_bool} % The boolean \cs{l_@@_writing_bool} keeps track of whether we should write % to a file, and \cs{l_@@_storing_bool} determines whether it is in write-only -% mode when the |write-out| option is used. +% mode when the §write-out§ option is used. % -%%^^A Internal bool vars % \begin{macrocode} \bool_new:N \l_@@_writing_bool \bool_set_false:N \l_@@_writing_bool @@ -1565,7 +1735,6 @@ No tab % A token list to match when ending \env{verbatimsc} and \env{scontents} % environments. % -%%^^A A token list to match \env{verbatimsc} and \env{scontents} % \begin{macrocode} \tl_new:N \g_@@_end_verbatimsc_tl \tl_gset_rescan:Nnn @@ -1581,11 +1750,22 @@ No tab % \end{macrocode} % \end{macro} % +% \begin{macro}{\c_@@_hidden_space_str} +% \cs{c_@@_hidden_space_str} is a constant \emph{string} to used to hide +% the \mymeta{forced space} added by \hologo{TeX} when recording content +% in a macro. This \emph{string} contains the \emph{reserved phrase} +% ``§%§§^^Ascheol%§'' which is added to the end of the argument stored +% in |seq| when the key §force-eol§ is false. +% +% \begin{macrocode} +\str_const:Nx \c_@@_hidden_space_str + { \c_percent_str \c_circumflex_str \c_circumflex_str A scheol \c_percent_str } +% \end{macrocode} +% \end{macro} % % \begin{macro}{\q_@@_stop,\q_@@_mark} % Some quarks used along the code as macro delimiters. % -%%^^A Internal quarks % \begin{macrocode} \quark_new:N \q_@@_stop \quark_new:N \q_@@_mark @@ -1595,7 +1775,6 @@ No tab % \begin{macro}{\l_@@_file_iow} % An output stream for saving the contents of an environment to a file. % -%%^^A Stream for saving the contents % \begin{macrocode} \iow_new:N \l_@@_file_iow % \end{macrocode} @@ -1608,7 +1787,6 @@ No tab % will not work. Here we create a private copy of \cs{tex_scantokens:D} % which will serve our purposes. % -%%^^A Copy of scantokens in expl3 % \begin{macrocode} \cs_new_protected:Npn \@@_rescan_tokens:n #1 { \tex_scantokens:D {#1} } \cs_generate_variant:Nn \@@_rescan_tokens:n { V, x } @@ -1616,20 +1794,18 @@ No tab % \end{macro} % % \begin{macro}{\@@_tab:,\@@_par:} -% Control sequences to replace tab (|^^I|) and form feed (|^^L|) characters. +% Control sequences to replace tab (§^^I§) and form feed (§^^L§) characters. % -%%^^A Internal \tab and \par % \begin{macrocode} \cs_new:Npx \@@_tab: { \c_space_tl } \cs_new:Npn \@@_par: { ^^J ^^J } % \end{macrocode} % \end{macro} % -% \begin{macro}{\tl_remove_once:NV,\tl_replace_all:Nxx, +% \begin{macro}[int]{\tl_remove_once:NV,\tl_replace_all:Nxx, % \tl_replace_all:Nxn,\tl_replace_all:Nnx,\tl_if_empty:fTF} % Some nonstandard variants. % -%%^^A Some nonstandard variants % \begin{macrocode} \cs_generate_variant:Nn \tl_remove_once:Nn { NV } \cs_generate_variant:Nn \tl_replace_all:Nnn { Nx, Nxx, Nnx } @@ -1637,13 +1813,17 @@ No tab % \end{macrocode} % \end{macro} % -% \subsection{Add keys for environment} +% \subsection{Defining keys for the environment and commands} +% +% We add the \mymeta{keys} divided into subgroups to handle errors and +% \emph{unknown} \mymeta{keys} separately. % -% We define a set of keys for environment \env{scontents}. +% \subsubsection{Keys for environment \env{scontents}} +% +% We define a set of \mymeta{keys} for environment §scontents§. % -%%^^A Add keys to scontents environnment % \begin{macrocode} -\keys_define:nn { scontents } +\keys_define:nn { scontents / scontents } { write-env .code:n = { \bool_set_true:N \l_@@_writing_bool @@ -1655,61 +1835,129 @@ No tab \tl_set:Nn \l_@@_fname_out_tl {#1} }, write-env .value_required:n = true, - write-out .value_required:n = true + write-out .value_required:n = true, + print-env .meta:nn = { scontents } { print-env = #1 }, + print-env .default:n = true, + store-env .meta:nn = { scontents } { store-env = #1 }, + force-eol .meta:nn = { scontents } { force-eol = #1 }, + force-eol .default:n = true, + unknown .code:n = { \@@_parse_environment_keys:n {#1} } } % \end{macrocode} % -% \subsection{Define keys for command} +% \subsubsection{Keys for command \cs{Scontents}} % -% A sub/keys for command |\Scontents| and |\Scontents*| +% We define a set of \mymeta{keys} for commands §\Scontents§ and +% §\Scontents*§. % -%%^^A A sub/keys for command \Scontents % \begin{macrocode} \keys_define:nn { scontents / Scontents } { - print-cmd .meta:nn = { scontents } { print-cmd = #1 }, - store-cmd .meta:nn = { scontents } { store-cmd = #1 }, - force-eol .meta:nn = { scontents } { force-eol = #1 } + print-cmd .meta:nn = { scontents } { print-cmd = #1 }, + print-cmd .default:n = true, + store-cmd .meta:nn = { scontents } { store-cmd = #1 }, + force-eol .meta:nn = { scontents } { force-eol = #1 }, + force-eol .default:n = true, + unknown .code:n = { \@@_parse_command_keys:n {#1} } + } +% \end{macrocode} +% +% \subsubsection{Key for commands \cs{typestored} and \cs{meaningsc}} +% +% We define a \mymeta{key} for command §\typestored§ and §\meaningsc§. +% Both commands accept the same type of optional arguments, just define +% a common \mymeta{key}. +% +% \begin{macrocode} +\keys_define:nn { scontents / typemeaning } + { + width-tab .meta:nn = { scontents } { width-tab = #1 }, + unknown .code:n = { \@@_parse_type_meaning_key:n {#1} } } % \end{macrocode} % % \subsection{Handling undefined keys} % -% \begin{macro}{\@@_parse_unknown_key:n,\@@_parse_unknown_key:nn} -% The commands \cs{typestored} and \cs{meaningsc} accept an optional -% argument for setting the \texttt{width-tab} to print the stored +% The \mymeta{keys} are stored in the token list variable \cs{l_keys_key_tl}, +% and the value (if any) is passed as an argument to each \mymeta{function}. +% +% \subsubsection{Undefined keys for environment \env{scontents}} +% +% \begin{macro}{\@@_parse_environment_keys:n, +% \@@_parse_environment_keys:nn} +% +% We check the \mymeta{keys} passed to the environment +% §scontents§ and process it with \cs{@@_parse_environment_keys:n} +% if the \mymeta{key} is \emph{unknown} we return an error message. +% +% \begin{macrocode} +\cs_new_protected:Npn \@@_parse_environment_keys:n #1 + { \exp_args:NV \@@_parse_environment_keys:nn \l_keys_key_tl {#1} } +\cs_new_protected:Npn \@@_parse_environment_keys:nn #1#2 + { + \tl_if_blank:nTF {#2} + { \msg_error:nnn { scontents } { env-key-unknown } {#1} } + { \msg_error:nnnn { scontents } { env-key-value-unknown } {#1} {#2} } + } +% \end{macrocode} +% \end{macro} +% +% \subsubsection{Undefined keys for \cs{Scontents} and \cs{Scontents*}} +% +% \begin{macro}{\@@_parse_command_keys:n, +% \@@_parse_command_keys:nn} +% +% We check the \meta{keys} passed to commands §\Scontents§ or +% §\Scontents*§ and process it with \cs{@@_parse_command_keys:n} +% if the \mymeta{key} is \emph{unknown} we return an error message. +% +% \begin{macrocode} +\cs_new_protected:Npn \@@_parse_command_keys:n #1 + { \exp_args:NV \@@_parse_command_keys:nn \l_keys_key_tl {#1} } +\cs_new_protected:Npn \@@_parse_command_keys:nn #1#2 + { + \tl_if_blank:nTF {#2} + { \msg_error:nnn { scontents } { cmd-key-unknown } {#1} } + { \msg_error:nnnn { scontents } { cmd-key-value-unknown } {#1} {#2} } + } +% \end{macrocode} +% \end{macro} +% +% \subsubsection{Undefined keys for \cs{typestored} and \cs{meaningsc}} +% +% \begin{macro}{\@@_parse_type_meaning_key:n, +% \@@_parse_type_meaning_key:nn} +% +% The commands §\typestored§ and §\meaningsc§ accept an optional +% argument for setting the §width-tab§ to print the stored % contents. However their optional argument also contains the number % of the item to retrieve from the stored sequence. To avoid the -% awkward \verb|\typestored[][<options>]{...}| syntax, we'll make the +% awkward §\typestored[]§\myoarg[type=tt]{options}§{...}§ syntax, we'll make the % commands have a single optional argument which is processed by % \pkg{l3keys}, and the unknown keys are brought here to -% \cs{@@_parse_unknown_key:n} to process. -% -% The key is stored in the token list variable \cs{l_keys_key_tl}, and -% the value (if any) is passed as argument to this function. +% \cs{@@_parse_typemeaning_key:n} to process. % -% First we check if the key is an integer using \cs{int_to_roman:n}. +% First we check if the \mymeta{key} is an integer using \cs{int_to_roman:n}. % If it is, we check that the value passed to the key is blank % (otherwise something odd as |1=1| might have been used). If everything -% is correct, then set the value of the integer which holds the index. -% Otherwise raise an error about an unknown option. +% is correct, then set the value of the integer which holds the \mymeta{index}. +% Otherwise raise an error about an \emph{unknown} option. % -%%^^A Parse unknown keys % \begin{macrocode} -\cs_new_protected:Npn \@@_parse_unknown_key:n #1 - { \exp_args:NV \@@_parse_unknown_key:nn \l_keys_key_tl {#1} } -\cs_new_protected:Npn \@@_parse_unknown_key:nn #1 #2 +\cs_new_protected:Npn \@@_parse_type_meaning_key:n #1 + { \exp_args:NV \@@_parse_type_meaning_key:nn \l_keys_key_tl {#1} } +\cs_new_protected:Npn \@@_parse_type_meaning_key:nn #1#2 { \tl_if_empty:fTF { \int_to_roman:n { -0 #1 } } { \tl_if_blank:nTF {#2} { \int_set:Nn \l_@@_seq_item_int {#1} } - { \msg_error:nnnn { scontents } { key-value-unknown } {#1} {#2} } + { \msg_error:nnnn { scontents } { type-key-value-unknown } {#1} {#2} } } { \tl_if_blank:nTF {#2} - { \msg_error:nnn { scontents } { key-unknown } {#1} } - { \msg_error:nnnn { scontents } { key-value-unknown } {#1} {#2} } + { \msg_error:nnn { scontents } { type-key-unknown } {#1} } + { \msg_error:nnnn { scontents } { type-key-value-unknown } {#1} {#2} } } } % \end{macrocode} @@ -1717,43 +1965,65 @@ No tab % % \subsection{Programming of the sequences} % -% \begin{macro}{\@@_append_contents:nn,\@@_getfrom_seq:nn,\@@_getfrom_seq:nnn} % The storage of the package is done using |seq| variables. Here we % set up the macros that will manage the variables. -% +% \begin{macro}{\@@_append_contents:nn} % \cs{@@_append_contents:nn} creates a seq variable if one didn't % exist and appends the contents in the argument to the right of the -% sequence. \cs{@@_getfrom_seq:nn} retrieves the saved item from the % sequence. % -%%^^A Programming of the sequences % \begin{macrocode} \cs_new_protected:Npn \@@_append_contents:nn #1#2 { \tl_if_blank:nT {#1} { \msg_error:nn { scontents } { empty-store-cmd } } - \seq_if_exist:cF { g_@@_seq_name_#1_seq } - { \seq_new:c { g_@@_seq_name_#1_seq } } - \seq_gput_right:cn { g_@@_seq_name_#1_seq } {#2} + \seq_if_exist:cF { g_@@_name_#1_seq } + { \seq_new:c { g_@@_name_#1_seq } } + \seq_gput_right:cn { g_@@_name_#1_seq } {#2} } \cs_generate_variant:Nn \@@_append_contents:nn { Vx } +% \end{macrocode} +% \end{macro} +% +% \begin{macro}{\@@_getfrom_seq:nn,\@@_getfrom_seq:nnn} +% \cs{@@_getfrom_seq:nn} retrieves the saved item from the +% sequence. +% +% \begin{macrocode} \cs_new:Npn \@@_getfrom_seq:nn #1#2 { - \seq_if_exist:cTF { g_@@_seq_name_#2_seq } + \seq_if_exist:cTF { g_@@_name_#2_seq } { \exp_args:Nf \@@_getfrom_seq:nnn - { \seq_count:c { g_@@_seq_name_#2_seq } } + { \seq_count:c { g_@@_name_#2_seq } } {#1} {#2} } { \msg_expandable_error:nnn { scontents } { undefined-storage } {#2} } } -\cs_new:Npn \@@_getfrom_seq:nnn #1 #2 #3 +\cs_new:Npn \@@_getfrom_seq:nnn #1#2#3 { \bool_lazy_or:nnTF { \int_compare_p:nNn {#2} = { 0 } } { \int_compare_p:nNn { \int_abs:n {#2} } > {#1} } { \msg_expandable_error:nnnnn { scontents } { index-out-of-range } {#2} {#3} {#1} } - { \seq_item:cn { g_@@_seq_name_#3_seq } {#2} } + { \seq_item:cn { g_@@_name_#3_seq } {#2} } + } +% \end{macrocode} +% \end{macro} +% +% \begin{macro}{\@@_lastfrom_seq:n} +% \cs{@@_lastfrom_seq:n} retrieves the last saved item from the +% sequence when \cs{l_@@__print_env_bool} or \cs{l_@@__print_cmd_bool} +% is true. +% +% \begin{macrocode} +\cs_new_protected:Npn \@@_lastfrom_seq:n #1 + { + \tl_gset:Nx \g_@@_temp_tl { \seq_item:cn { g_@@_name_#1_seq } {-1} } + \group_insert_after:N \@@_rescan_tokens:V + \group_insert_after:N \g_@@_temp_tl + \group_insert_after:N \tl_gclear:N + \group_insert_after:N \g_@@_temp_tl } % \end{macrocode} % \end{macro} @@ -1762,9 +2032,8 @@ No tab % The \cs{@@_store_to_seq:NN} writes the recorded contents % in |#1| to the log and stores it in |#2|. % -%%^^A Storing content in sequences % \begin{macrocode} -\cs_new_protected:Npn \@@_store_to_seq:NN #1 #2 +\cs_new_protected:Npn \@@_store_to_seq:NN #1#2 { \tl_log:N #1 \@@_append_contents:Vx #2 { \exp_not:V #1 } @@ -1772,17 +2041,16 @@ No tab % \end{macrocode} % \end{macro} % -% \subsection{Construction of environment scontents} -% -% We define the environment \env{scontents}, next to the system |key=val|. -% The environment is divided into three parts. This implementation is taken -% from answer by Enrico Gregorio in \url{https://tex.stackexchange.com/a/487746/7832}. +% \subsection{Construction of environment \env{scontents}} % +% We define the environment \env{scontents}, next to the system +% \myoarg{key \textnormal{\textcolor{gray}{=}} val}. The environment +% is divided into three parts. This implementation is taken from answer +% by Enrico Gregorio in \url{https://tex.stackexchange.com/a/487746/7832}. % % \begin{macro}{scontents} % This is the main environment used in the document. % -%%^^A Definition of {scontents}[key=val] env % \begin{macrocode} \NewDocumentEnvironment { scontents } { } { @@ -1798,18 +2066,18 @@ No tab % % \subsubsection{key val for environment} % -% Define a |key=val| for environment \env{scontents} +% Define a \myoarg{key \textnormal{\textcolor{gray}{=}} val} for +% environment \env{scontents} % % \begin{macro}{\@@_environment_inline:w,\@@_environment_keys:w, % \@@_environment_junk:nw,\@@_environment_junk:xw} % The macro \cs{@@_environment_inline:w} is called from the % \env{scontents} environment with the tokens following the -% |\begin{scontents}|. If the immediate next token (ignoring spaces) -% is a |[|, then we look for an optional argument delimited by a |]|. +% §\begin{scontents}§. If the immediate next token (ignoring spaces) +% is a §[§, then we look for an optional argument delimited by a §]§. % All the remaining tokens are treated as junk and an error is raised % if they are non-blank. % -%%^^A Test [key=val] for environment scontents % \begin{macrocode} \cs_new_protected:Npn \@@_environment_inline:w { @@ -1822,7 +2090,7 @@ No tab } \cs_new_protected:Npn \@@_environment_keys:w [ #1 ] { - \keys_set_known:nn { scontents } {#1} + \keys_set:nn { scontents / scontents } {#1} \@@_environment_junk:xw { after~optional~argument~to~\c_backslash_str begin{scontents} } } @@ -1838,11 +2106,11 @@ No tab % \subsubsection{The environment itself} % % \begin{macro}{\@@_start_environment:w,\@@_stop_environment:} -% Here we make |^^I|, |^^L|, and |^^M| active characters so that the end of -% line can be ``seen'' to be used as a delimiter, and TeX doesn't try to +% Here we make §^^I§, §^^L§ and §^^M§ active characters so that the end of +% line can be \enquote{seen} to be used as a delimiter, and \hologo{TeX} doesn't try to % eliminate space-like characters. First we check if the line -% directly after |\begin{scontents}| contains an optional argument -% enclosed in |[...]|, or other tokens. The trailing tokens are +% directly after §\begin{scontents}§ contains an optional argument +% enclosed in §[...]§ or other tokens. The trailing tokens are % treated as junk and an error is raised. The % \cs{@@_environment_inline:w} macro checks for those cases. % @@ -1857,10 +2125,8 @@ No tab % %^^A Hm... Apparently this is not the verbatim group, but one level above. Is %^^A this group really necessary? -%^^A Reply : Maybe the groups aren't in the right places, but when you remove -%^^A them it just gives you errors...(test-pkg-current.tex) +%^^A Reply : I've checked it several times, it seems to be correct. % -%%^^A First start_environment/stop_environment % \begin{macrocode} \group_begin: \char_set_catcode_active:N \^^I @@ -1893,17 +2159,16 @@ No tab % } % This is the main macro to collect the contents of a verbatim environment. % The macro starts a group, opens the output file, if necessary, sets verbatim -% catcodes, and then issues |^^M| (set equal to \cs{@@_ret:w}) to read the +% catcodes, and then issues §^^M§ (set equal to \cs{@@_ret:w}) to read the % environment line by line until reaching its end. The output token list will -% be appended with an active |^^J| character and the line just read, and this +% be appended with an active §^^J§ character and the line just read, and this % line is written to the output file, if any. At the end of the environment % the output file is closed (if it was open), and the output token list is -% smuggled out of the verbatim group. A leading |^^M| is removed from the -% token list using \cs{@@_remove_leading_nl:n} (which expects an active |^^M| -% token at the head of the token list; a low level TeX error is raised +% smuggled out of the verbatim group. A leading §^^J§ is removed from the +% token list using \cs{@@_remove_leading_nl:n} (which expects an active §^^J§ +% token at the head of the token list; a low level \hologo{TeX} error is raised % otherwise). % -%%^^A File write start/File write stop % \begin{macrocode} \cs_new_protected:Npn \@@_file_tl_write_start:n #1 { @@ -1976,10 +2241,7 @@ No tab \bool_if:NT \l_@@_storing_bool { \tl_set:Nn \exp_not:N #1 - { - \exp_args:NV \@@_remove_leading_nl:n \l_@@_file_tl - \bool_if:NT \l_@@_forced_eol_bool { \exp_not:N ^^J } - } + { \exp_args:NV \@@_remove_leading_nl:n \l_@@_file_tl } } } } @@ -2002,13 +2264,13 @@ No tab % to a token list and to a file, depending on the booleans % \cs{l_@@_writing_bool} and \cs{l_@@_storing_bool}. % -% \cs{@@_analyse_nesting:n} looks for nested \cs{begin}|{scontents}| +% \cs{@@_analyse_nesting:n} looks for nested §\begin{scontents}§ % and adds to a \cs{l_@@_env_nesting_int} counter. The \cs{@@_if_nested:} % conditional tests if we're in a nested environment, and -% \cs{@@_nesting_decr:} reduces the nesting level, if an \cs{end}|{scontents}| +% \cs{@@_nesting_decr:} reduces the nesting level, if an §\end{scontents}§ % is found. % -% Multiple \cs{end}|{scontents}| in the same line are not supported... +% Multiple §\end{scontents}§ in the same line are not supported... % \begin{macrocode} \cs_new_protected:Npn \@@_verb_processor_output:n #1 { @@ -2070,35 +2332,30 @@ No tab % Finishes the environment by optionally calling \cs{@@_store_to_seq:} % and then clearing the temporary token list. % -%%^^A Second atend_environment/stored_to_seq % \begin{macrocode} \cs_new_protected:Npn \@@_atend_environment: { \bool_if:NT \l_@@_storing_bool { + \bool_if:NF \l_@@_forced_eol_bool + { \tl_put_right:Nx \l_@@_macro_tmp_tl { \c_@@_hidden_space_str } } \@@_store_to_seq:NN \l_@@_macro_tmp_tl \l_@@_name_seq_env_tl + \bool_if:NT \l_@@_print_env_bool + { \@@_lastfrom_seq:n \l_@@_name_seq_env_tl } } - \bool_if:NT \l_@@_print_env_bool - { - \tl_gset_eq:NN \g_@@_temp_tl \l_@@_macro_tmp_tl - \tl_gput_right:NV \g_@@_temp_tl \c_percent_str - \group_insert_after:N \@@_rescan_tokens:V - \group_insert_after:N \g_@@_temp_tl - } - \tl_clear:N \l_@@_macro_tmp_tl } % \end{macrocode} % \end{macro} % % \subsection{The \cs{Scontents} command} % -% User command to stored content, adapted from +% User command to \mymeta{stored content}, adapted from % \url{https://tex.stackexchange.com/a/500281/7832}. % % \begin{macro}{\Scontents,\@@_norm_arg:n,\@@_verb_arg:w} -% The \cs{Scontents} macro starts by parsing an optional argument and +% The §\Scontents§ macro starts by parsing an optional argument and % then delegates to \cs{@@_verb_arg:w} or \cs{@@_norm_arg:n} depending whether -% a star argument is present. +% a star (§*§) argument is present. % % \cs{@@_norm_arg:n} grabs a normal argument, adds it to the |seq| varaible, % and optionally prints it. @@ -2106,18 +2363,12 @@ No tab % \cs{@@_verb_arg:w} grabs a verbatim argument using \pkg{xparse}'s |+v| % argument parser. % -%^^A NOTE: Any particular reason why \keys_set_known:nn instead of just -%^^A \keys_set:nn? The latter reports if an unknown key is used... -%^^A Reply: The redirection of error messages has never worked well for me -%^^A perhaps it would be better to implement it. -% -%%^^A User command \Scontents to stored content % \begin{macrocode} \NewDocumentCommand { \Scontents }{ !s !O{} } { \group_begin: \IfNoValueF {#2} - { \keys_set_known:nn { scontents / Scontents } {#2} } + { \keys_set:nn { scontents / Scontents } {#2} } \char_set_catcode_active:n { 9 } \IfBooleanTF {#1} { \@@_verb_arg:w } @@ -2125,21 +2376,22 @@ No tab } \cs_new_protected:Npn \@@_norm_arg:n #1 { - \exp_args:NV \@@_append_contents:nn \l_@@_name_seq_cmd_tl {#1} - \bool_if:NT \l_@@_print_cmd_bool { \@@_rescan_tokens:n {#1} } + \tl_set:Nx \l_@@_temp_tl { \exp_not:n {#1} } + \tl_put_right:Nx \l_@@_temp_tl { \c_@@_hidden_space_str } + \@@_store_to_seq:NN \l_@@_temp_tl \l_@@_name_seq_cmd_tl + \bool_if:NT \l_@@_print_cmd_bool + { \@@_lastfrom_seq:n \l_@@_name_seq_cmd_tl } \group_end: } \NewDocumentCommand { \@@_verb_arg:w } { +v } { - \tl_set:Nx \l_@@_temp_tl - { - \exp_not:n {#1} - \bool_if:NT \l_@@_forced_eol_bool { \exp_not:N ^^J } - } + \tl_set:Nx \l_@@_temp_tl { \exp_not:n {#1} } \tl_replace_all:Nxx \l_@@_temp_tl { \iow_char:N \^^M } { \iow_char:N \^^J } + \bool_if:NF \l_@@_forced_eol_bool + { \tl_put_right:Nx \l_@@_temp_tl { \c_@@_hidden_space_str } } \@@_store_to_seq:NN \l_@@_temp_tl \l_@@_name_seq_cmd_tl \bool_if:NT \l_@@_print_cmd_bool - { \@@_rescan_tokens:V \l_@@_temp_tl } + { \@@_lastfrom_seq:n \l_@@_name_seq_cmd_tl } \group_end: } % \end{macrocode} @@ -2147,21 +2399,16 @@ No tab % % \subsection{The command \cs{getstored}} % -% % \begin{macro}{\getstored} -% User command \cs{getstored} to extract stored content in |seq| +% User command §\getstored§ to extract \mymeta{stored content} in |seq| % (robust). % -%%^^A User command \getstored to get content % \begin{macrocode} \NewDocumentCommand { \getstored } { O{1} m } { \group_begin: \@@_rescan_tokens:x - { - \@@_getfrom_seq:nn {#1} {#2} - \c_percent_str - } + { \@@_getfrom_seq:nn {#1} {#2} } \group_end: } % \end{macrocode} @@ -2173,29 +2420,32 @@ No tab % in (\url{https://tex.stackexchange.com/a/497651/7832}). % % \begin{macro}{\typestored,\@@_verb_print:N,\@@_xverb:w,verbatimsc} -% The \cs{typestored} commands fetches a buffer from memory, prints it +% The §\typestored§ commands fetches a buffer from memory, prints it % to the log file, and then calls \cs{@@_verb_print:N}. % -%%^^A User command \typestored to verbatimized content % \begin{macrocode} \NewDocumentCommand { \typestored } { o m } { \group_begin: \int_set:Nn \l_@@_seq_item_int { 1 } - \IfValueT {#1} { \keys_set:nn { scontents } {#1} } - \tl_set:Nx \l_@@_temp_tl { \exp_args:NV \@@_getfrom_seq:nn \l_@@_seq_item_int {#2} } + \IfValueT {#1} { \keys_set:nn { scontents / typemeaning } {#1} } + \tl_set:Nx \l_@@_temp_tl + { + \exp_args:NV \@@_getfrom_seq:nn \l_@@_seq_item_int {#2} + } + \tl_remove_once:NV \l_@@_temp_tl \c_@@_hidden_space_str \tl_log:N \l_@@_temp_tl \tl_if_empty:NF \l_@@_temp_tl { \@@_verb_print:N \l_@@_temp_tl } \group_end: } % \end{macrocode} +% % The \cs{@@_verb_print:N} macro is defined with active carriage return % (\textsc{ascii} 13) characters to mimick an actual verbatim environment % \enquote{on the loose}. The contents of the environment are placed in a -% \env{verbatimsc} environment and rescanned using \cs{@@_rescan_tokens:x}. +% §verbatimsc§ environment and rescanned using \cs{@@_rescan_tokens:x}. % -%%^^A Internal verb_print:N, need to verbatimized content % \begin{macrocode} \group_begin: \char_set_catcode_active:N \^^M @@ -2217,9 +2467,8 @@ No tab \group_end: % \end{macrocode} % -% Finally, the \env{verbatimsc} environment is defined. +% Finally, the §verbatimsc§ environment is defined. % -%%^^A Definition of verbatimsc environment % \begin{macrocode} \cs_new_protected:Npn \@@_xverb: { @@ -2245,11 +2494,10 @@ No tab % \subsection{Some auxiliaries} % % \begin{macro}{\@@_tabs_to_spaces:} -% In a verbatim context the |tab| character is made active and set +% In a verbatim context the |TAB| character is made active and set % equal to \cs{@@_tabs_to_spaces:}, to produce as many spaces as -% the |width-tab| key was set to. +% the §width-tab§ key was set to. % -%%^^A Tab to space % \begin{macrocode} \cs_new:Npn \@@_tabs_to_spaces: { \prg_replicate:nn { \l_@@_tab_width_int } { ~ } } @@ -2260,11 +2508,10 @@ No tab % \cs{@@_do_noligs:N} is an alternative definition for \LaTeXe's % \cs{do@noligs} which makes sure to not consume following space % tokens. The \LaTeXe{} version ends with \cs{char}|`#1|, which -% leaves \TeX{} still looking for an \meta{optional~space}. +% leaves \TeX{} still looking for an \mymeta{optional~space}. % This version uses \cs{char_generate:nn} to ensure that doesn't % happen. % -%%^^A Patch do_noligs for ligatures % \begin{macrocode} \cs_new:Npn \@@_do_noligs:N #1 { @@ -2286,7 +2533,6 @@ No tab % } % Shortcut definitions for common catcode changes. % -%%^^A Common catcode changes % \begin{macrocode} \cs_new_protected:Npn \@@_set_active_eq:NN #1 { @@ -2304,31 +2550,28 @@ No tab % % \subsection{The command \cs{setupsc}} % -% User command \cs{setupsc} to setup module. +% User command §\setupsc§ to setup module. % % \begin{macro}{\setupsc} -% A user-level wrapper for \cs{keys_set:nn}|{ scontents }|. +% A user-level wrapper for \cs{keys_set:nn}§{ scontents }§. % -%%^^A User command \setupsc % \begin{macrocode} -\NewDocumentCommand { \setupsc } { m } +\NewDocumentCommand { \setupsc } { +m } { \keys_set:nn { scontents } {#1} } % \end{macrocode} % \end{macro} % % \subsection{The command meaningsc} % -% % \begin{macro}{\meaningsc} -% User command \cs{meaningsc} to see content stored in |seq|. +% User command §\meaningsc§ to see content stored in |seq|. % -%%^^A User command \meaningsc % \begin{macrocode} \NewDocumentCommand { \meaningsc } { o m } { \group_begin: \int_set:Nn \l_@@_seq_item_int { 1 } - \IfValueT {#1} { \keys_set:nn { scontents } {#1} } + \IfValueT {#1} { \keys_set:nn { scontents / typemeaning } {#1} } \@@_meaningsc:n {#2} \group_end: } @@ -2336,8 +2579,12 @@ No tab \char_set_catcode_active:N \^^I \cs_new_protected:Npn \@@_meaningsc:n #1 { - \tl_set:Nx \l_@@_temp_tl { \exp_args:NV \@@_getfrom_seq:nn \l_@@_seq_item_int {#1} } + \tl_set:Nx \l_@@_temp_tl + { + \exp_args:NV \@@_getfrom_seq:nn \l_@@_seq_item_int {#1} + } \tl_replace_all:Nxn \l_@@_temp_tl { \iow_char:N \^^J } { ~ } + \tl_remove_once:NV \l_@@_temp_tl \c_@@_hidden_space_str \tl_log:N \l_@@_temp_tl \tl_use:N \l_@@_verb_font_tl \tl_replace_all:Nnx \l_@@_temp_tl { ^^I } { \@@_tabs_to_spaces: } @@ -2351,12 +2598,11 @@ No tab % % % \begin{macro}{\countsc} -% User command \cs{countsc} to count number of contents stored in |seq|. +% User command §\countsc§ to count number of contents stored in |seq|. % -%%^^A User command \countsc % \begin{macrocode} \NewExpandableDocumentCommand { \countsc } { m } - { \seq_count:c { g_@@_seq_name_#1_seq } } + { \seq_count:c { g_@@_name_#1_seq } } % \end{macrocode} % \end{macro} % @@ -2364,20 +2610,18 @@ No tab % % % \begin{macro}{\cleanseqsc} -% A user command \cs{cleanseqsc} to clear (remove) a defined |seq|. +% A user command §\cleanseqsc§ to clear (remove) a defined |seq|. % -%%^^A User command \cleanseqsc % \begin{macrocode} \NewDocumentCommand { \cleanseqsc } { m } - { \seq_clear_new:c { g_@@_seq_name_#1_seq } } + { \seq_clear_new:c { g_@@_name_#1_seq } } % \end{macrocode} % \end{macro} % -% \subsection{Messages} +% \subsection{Warning and error messages} % -% Messages used throughout the package. +% Warning and error messages used throughout the package. % -%%^^A Messages used throughout the package % \begin{macrocode} \msg_new:nnn { scontents } { junk-after-begin } { @@ -2386,33 +2630,17 @@ No tab #2 } \msg_new:nnn { scontents } { empty-stored-content } - { Empty~value~for~key~`getstored'~\msg_line_context:. } + { Empty~value~for~key~'getstored'~\msg_line_context:. } \msg_new:nnn { scontents } { empty-variable } - { Variable~`#1'~empty~\msg_line_context:. } + { Variable~'#1'~empty~\msg_line_context:. } \msg_new:nnn { scontents } { rewriting-file } - { Overwriting ~ file ~ `#1' } + { Overwriting ~ file ~ '#1' } \msg_new:nnn { scontents } { writing-file } - { Writing ~ file ~ `#1' } + { Writing ~ file ~ '#1' } \msg_new:nnn { scontents } { rescanning-text } - { Rescanning~text~`#1'~after~\c_backslash_str end{scontents}~\msg_line_context:.} + { Rescanning~text~'#1'~after~\c_backslash_str end{scontents}~\msg_line_context:.} \msg_new:nnn { scontents } { multiple-begin } { Multiple~\c_backslash_str begin{scontents}~\msg_line_context:.} -\msg_new:nnn { scontents } { tab-to-space } - { Tab~has~been~converted~to~Blank~Space } -\msg_new:nnn { scontents } { feed-to-space } - { Form~Feed~has~been~converted~to~Blank~Space } -\msg_new:nnnn { scontents } { key-unknown } - { The~key~'#1'~is~unknown~and~is~being~ignored. } - { - The~module~'scontents'~does~not~have~a~key~called~'#1'.\\ - Check~that~you~have~spelled~the~key~name~correctly. - } -\msg_new:nnnn { scontents } { key-value-unknown } - { The~key~'#1'~to~which~you~passed~'#2'~is~unknown~and~is~being~ignored. } - { - The~module~'scontents'~does~not~have~a~key~called~'#1'.\\ - Check~that~you~have~spelled~the~key~name~correctly. - } \msg_new:nnn { scontents } { undefined-storage } { Storage~named~'#1'~is~not~defined. } \msg_new:nnn { scontents } { index-out-of-range } @@ -2425,13 +2653,48 @@ No tab { Max = } { Min = -} #3. } } +\msg_new:nnnn { scontents } { env-key-unknown } + { The~key~'#1'~is~unknown~by~environment~'scontents'~and~is~being~ignored.} + { + The~environment~'scontents'~does~not~have~a~key~called~'#1'.\\ + Check~that~you~have~spelled~the~key~name~correctly. + } +\msg_new:nnnn { scontents } { env-key-value-unknown } + { The~key~'#1=#2'~is~unknown~by~environment~'scontents'~and~is~being~ignored. } + { + The~environment~'scontents'~does~not~have~a~key~called~'#1'.\\ + Check~that~you~have~spelled~the~key~name~correctly. + } +\msg_new:nnnn { scontents } { cmd-key-unknown } + { The~key~'#1'~is~unknown~by~'\c_backslash_str Scontents'~and~is~being~ignored.} + { + The~command~'\c_backslash_str Scontents'~does~not~have~a~key~called~'#1'.\\ + Check~that~you~have~spelled~the~key~name~correctly. + } +\msg_new:nnnn { scontents } { cmd-key-value-unknown } + { The~key~'#1=#2'~is~unknown~by~'\c_backslash_str Scontents'~and~is~being~ignored. } + { + The~command~'\c_backslash_str Scontents'~does~not~have~a~key~called~'#1'.\\ + Check~that~you~have~spelled~the~key~name~correctly. + } +\msg_new:nnnn { scontents } { type-key-unknown } + { The~key~'#1'~is~unknown~and~is~being~ignored. } + { + This~command~does~not~have~a~key~called~'#1'.\\ + This~command~only~accepts~the~key~'width-tab'. + } +\msg_new:nnnn { scontents } { type-key-value-unknown } + { The~key~'#1'~to~which~you~passed~'#2'~is~unknown~and~is~being~ignored. } + { + This~command~does~not~have~a~key~called~'#1'.\\ + This~command~only~accepts~the~key~'width-tab'. + } % \end{macrocode} % % \subsection{Finish package} % -% Finish package +% Finish package implementation. % -%%^^A Finish package :) % \begin{macrocode} \file_input_stop: % \end{macrocode} diff --git a/Master/texmf-dist/source/latex/scontents/scontents.ins b/Master/texmf-dist/source/latex/scontents/scontents.ins index ee59a97dcf3..df12528bbd2 100644 --- a/Master/texmf-dist/source/latex/scontents/scontents.ins +++ b/Master/texmf-dist/source/latex/scontents/scontents.ins @@ -1,9 +1,60 @@ +%% +%% This is file `scontents.ins', +%% generated with the docstrip utility. +%% +%% The original source files were: +%% +%% scontents.dtx (with options: `install') +%% +%% Copyright (C) 2019 by Pablo González L <pablgonz@educarchile.cl> +%% +%% 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 +%% 2005/12/01 or later. +%% +%% This work is "maintained" (as per the LPPL maintenance status) +%% by Pablo González Luengo. +%% +%% This work consists of the file scontents.dtx +%% and the derived files scontents.ins, +%% scontents.pdf and +%% scontents.sty. +%% \input l3docstrip.tex \keepsilent \askforoverwritefalse -\nopreamble\nopostamble +\preamble + +Copyright (C) 2019 by Pablo González L <pablgonz@educarchile.cl> + +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 +2005/12/01 or later. + +This work is "maintained" (as per the LPPL maintenance status) +by Pablo González Luengo. + +This work consists of the file scontents.dtx +and the derived files scontents.ins, + scontents.pdf and + scontents.sty. + +\endpreamble \usedir{tex/latex/scontents} \generate{% \file{\jobname.sty}{\from{\jobname.dtx}{package}}% }% \endbatchfile +\endinput +%% +%% End of file `scontents.ins'. diff --git a/Master/texmf-dist/tex/latex/scontents/scontents.sty b/Master/texmf-dist/tex/latex/scontents/scontents.sty index 6983b4517d5..48aba087349 100644 --- a/Master/texmf-dist/tex/latex/scontents/scontents.sty +++ b/Master/texmf-dist/tex/latex/scontents/scontents.sty @@ -1,13 +1,38 @@ -%%^^A Initial declaration of the package +%% +%% This is file `scontents.sty', +%% generated with the docstrip utility. +%% +%% The original source files were: +%% +%% scontents.dtx (with options: `package') +%% +%% Copyright (C) 2019 by Pablo González L <pablgonz@educarchile.cl> +%% +%% 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 +%% 2005/12/01 or later. +%% +%% This work is "maintained" (as per the LPPL maintenance status) +%% by Pablo González Luengo. +%% +%% This work consists of the file scontents.dtx +%% and the derived files scontents.ins, +%% scontents.pdf and +%% scontents.sty. +%% \RequirePackage{l3keys2e} \RequirePackage{xparse}[2019/05/28] -\ProvidesExplPackage{scontents}{2019/09/24}{1.3} +\ProvidesExplPackage{scontents}{2019/10/03}{1.4} {Stores LaTeX contents in memory or files} -%%^^A Checking the version of xparse -\@ifpackagelater { xparse } { 2019/05/03 } +\@ifpackagelater { expl3 } { 2019/09/19 } { } { - \PackageError { scontents } { Support~package~xparse~too~old } + \PackageError { scontents } { Support~package~expl3~too~old } { You~need~to~update~your~installation~of~the~bundles~ 'l3kernel'~and~'l3packages'.\MessageBreak @@ -15,7 +40,6 @@ } \file_input_stop: } -%%^^A Common keys available as package options \keys_define:nn { scontents } { store-env .tl_set:N = \l__scontents_name_seq_env_tl, @@ -41,26 +65,22 @@ width-tab .value_required:n = true, print-all .meta:n = { print-env = #1 , print-cmd = #1 }, print-all .default:n = true, - unknown .code:n = { \__scontents_parse_unknown_key:n {#1} } + store-all .meta:n = { store-env = #1 , store-cmd = #1 }, + store-all .value_required:n = true } -%%^^A Process options for package \ProcessKeysOptions { scontents } -%%^^A Internal token list vars \tl_new:N \l__scontents_macro_tmp_tl \tl_new:N \l__scontents_fname_out_tl \tl_new:N \l__scontents_temp_tl \tl_new:N \l__scontents_file_tl \tl_new:N \g__scontents_temp_tl -%%^^A Internal int vars \int_new:N \l__scontents_seq_item_int \int_new:N \l__scontents_env_nesting_int \int_new:N \l__scontents_tmpa_int -%%^^A Internal bool vars \bool_new:N \l__scontents_writing_bool \bool_set_false:N \l__scontents_writing_bool \bool_new:N \l__scontents_storing_bool \bool_set_true:N \l__scontents_storing_bool -%%^^A A token list to match \env{verbatimsc} and \env{scontents} \tl_new:N \g__scontents_end_verbatimsc_tl \tl_gset_rescan:Nnn \g__scontents_end_verbatimsc_tl @@ -72,23 +92,19 @@ { \end{verbatimsc} } \tl_const:Nx \c__scontents_end_env_tl { \c_backslash_str end \c_left_brace_str scontents \c_right_brace_str } -%%^^A Internal quarks +\str_const:Nx \c__scontents_hidden_space_str + { \c_percent_str \c_circumflex_str \c_circumflex_str A scheol \c_percent_str } \quark_new:N \q__scontents_stop \quark_new:N \q__scontents_mark -%%^^A Stream for saving the contents \iow_new:N \l__scontents_file_iow -%%^^A Copy of scantokens in expl3 \cs_new_protected:Npn \__scontents_rescan_tokens:n #1 { \tex_scantokens:D {#1} } \cs_generate_variant:Nn \__scontents_rescan_tokens:n { V, x } -%%^^A Internal \tab and \par \cs_new:Npx \__scontents_tab: { \c_space_tl } \cs_new:Npn \__scontents_par: { ^^J ^^J } -%%^^A Some nonstandard variants \cs_generate_variant:Nn \tl_remove_once:Nn { NV } \cs_generate_variant:Nn \tl_replace_all:Nnn { Nx, Nxx, Nnx } \prg_generate_conditional_variant:Nnn \tl_if_empty:n { f } { TF } -%%^^A Add keys to scontents environnment -\keys_define:nn { scontents } +\keys_define:nn { scontents / scontents } { write-env .code:n = { \bool_set_true:N \l__scontents_writing_bool @@ -100,67 +116,100 @@ \tl_set:Nn \l__scontents_fname_out_tl {#1} }, write-env .value_required:n = true, - write-out .value_required:n = true + write-out .value_required:n = true, + print-env .meta:nn = { scontents } { print-env = #1 }, + print-env .default:n = true, + store-env .meta:nn = { scontents } { store-env = #1 }, + force-eol .meta:nn = { scontents } { force-eol = #1 }, + force-eol .default:n = true, + unknown .code:n = { \__scontents_parse_environment_keys:n {#1} } } -%%^^A A sub/keys for command \Scontents \keys_define:nn { scontents / Scontents } { - print-cmd .meta:nn = { scontents } { print-cmd = #1 }, - store-cmd .meta:nn = { scontents } { store-cmd = #1 }, - force-eol .meta:nn = { scontents } { force-eol = #1 } + print-cmd .meta:nn = { scontents } { print-cmd = #1 }, + print-cmd .default:n = true, + store-cmd .meta:nn = { scontents } { store-cmd = #1 }, + force-eol .meta:nn = { scontents } { force-eol = #1 }, + force-eol .default:n = true, + unknown .code:n = { \__scontents_parse_command_keys:n {#1} } + } +\keys_define:nn { scontents / typemeaning } + { + width-tab .meta:nn = { scontents } { width-tab = #1 }, + unknown .code:n = { \__scontents_parse_type_meaning_key:n {#1} } + } +\cs_new_protected:Npn \__scontents_parse_environment_keys:n #1 + { \exp_args:NV \__scontents_parse_environment_keys:nn \l_keys_key_tl {#1} } +\cs_new_protected:Npn \__scontents_parse_environment_keys:nn #1#2 + { + \tl_if_blank:nTF {#2} + { \msg_error:nnn { scontents } { env-key-unknown } {#1} } + { \msg_error:nnnn { scontents } { env-key-value-unknown } {#1} {#2} } } -%%^^A Parse unknown keys -\cs_new_protected:Npn \__scontents_parse_unknown_key:n #1 - { \exp_args:NV \__scontents_parse_unknown_key:nn \l_keys_key_tl {#1} } -\cs_new_protected:Npn \__scontents_parse_unknown_key:nn #1 #2 +\cs_new_protected:Npn \__scontents_parse_command_keys:n #1 + { \exp_args:NV \__scontents_parse_command_keys:nn \l_keys_key_tl {#1} } +\cs_new_protected:Npn \__scontents_parse_command_keys:nn #1#2 + { + \tl_if_blank:nTF {#2} + { \msg_error:nnn { scontents } { cmd-key-unknown } {#1} } + { \msg_error:nnnn { scontents } { cmd-key-value-unknown } {#1} {#2} } + } +\cs_new_protected:Npn \__scontents_parse_type_meaning_key:n #1 + { \exp_args:NV \__scontents_parse_type_meaning_key:nn \l_keys_key_tl {#1} } +\cs_new_protected:Npn \__scontents_parse_type_meaning_key:nn #1#2 { \tl_if_empty:fTF { \int_to_roman:n { -0 #1 } } { \tl_if_blank:nTF {#2} { \int_set:Nn \l__scontents_seq_item_int {#1} } - { \msg_error:nnnn { scontents } { key-value-unknown } {#1} {#2} } + { \msg_error:nnnn { scontents } { type-key-value-unknown } {#1} {#2} } } { \tl_if_blank:nTF {#2} - { \msg_error:nnn { scontents } { key-unknown } {#1} } - { \msg_error:nnnn { scontents } { key-value-unknown } {#1} {#2} } + { \msg_error:nnn { scontents } { type-key-unknown } {#1} } + { \msg_error:nnnn { scontents } { type-key-value-unknown } {#1} {#2} } } } -%%^^A Programming of the sequences \cs_new_protected:Npn \__scontents_append_contents:nn #1#2 { \tl_if_blank:nT {#1} { \msg_error:nn { scontents } { empty-store-cmd } } - \seq_if_exist:cF { g__scontents_seq_name_#1_seq } - { \seq_new:c { g__scontents_seq_name_#1_seq } } - \seq_gput_right:cn { g__scontents_seq_name_#1_seq } {#2} + \seq_if_exist:cF { g__scontents_name_#1_seq } + { \seq_new:c { g__scontents_name_#1_seq } } + \seq_gput_right:cn { g__scontents_name_#1_seq } {#2} } \cs_generate_variant:Nn \__scontents_append_contents:nn { Vx } \cs_new:Npn \__scontents_getfrom_seq:nn #1#2 { - \seq_if_exist:cTF { g__scontents_seq_name_#2_seq } + \seq_if_exist:cTF { g__scontents_name_#2_seq } { \exp_args:Nf \__scontents_getfrom_seq:nnn - { \seq_count:c { g__scontents_seq_name_#2_seq } } + { \seq_count:c { g__scontents_name_#2_seq } } {#1} {#2} } { \msg_expandable_error:nnn { scontents } { undefined-storage } {#2} } } -\cs_new:Npn \__scontents_getfrom_seq:nnn #1 #2 #3 +\cs_new:Npn \__scontents_getfrom_seq:nnn #1#2#3 { \bool_lazy_or:nnTF { \int_compare_p:nNn {#2} = { 0 } } { \int_compare_p:nNn { \int_abs:n {#2} } > {#1} } { \msg_expandable_error:nnnnn { scontents } { index-out-of-range } {#2} {#3} {#1} } - { \seq_item:cn { g__scontents_seq_name_#3_seq } {#2} } + { \seq_item:cn { g__scontents_name_#3_seq } {#2} } + } +\cs_new_protected:Npn \__scontents_lastfrom_seq:n #1 + { + \tl_gset:Nx \g__scontents_temp_tl { \seq_item:cn { g__scontents_name_#1_seq } {-1} } + \group_insert_after:N \__scontents_rescan_tokens:V + \group_insert_after:N \g__scontents_temp_tl + \group_insert_after:N \tl_gclear:N + \group_insert_after:N \g__scontents_temp_tl } -%%^^A Storing content in sequences -\cs_new_protected:Npn \__scontents_store_to_seq:NN #1 #2 +\cs_new_protected:Npn \__scontents_store_to_seq:NN #1#2 { \tl_log:N #1 \__scontents_append_contents:Vx #2 { \exp_not:V #1 } } -%%^^A Definition of {scontents}[key=val] env \NewDocumentEnvironment { scontents } { } { \char_set_catcode_active:N \^^M @@ -170,7 +219,6 @@ \__scontents_stop_environment: \__scontents_atend_environment: } -%%^^A Test [key=val] for environment scontents \cs_new_protected:Npn \__scontents_environment_inline:w { \peek_charcode_ignore_spaces:NTF [ % ] @@ -182,7 +230,7 @@ } \cs_new_protected:Npn \__scontents_environment_keys:w [ #1 ] { - \keys_set_known:nn { scontents } {#1} + \keys_set:nn { scontents / scontents } {#1} \__scontents_environment_junk:xw { after~optional~argument~to~\c_backslash_str begin{scontents} } } @@ -192,7 +240,6 @@ { \msg_error:nnnn { scontents } { junk-after-begin } {#1} {#2} } } \cs_generate_variant:Nn \__scontents_environment_junk:nw { x } -%%^^A First start_environment/stop_environment \group_begin: \char_set_catcode_active:N \^^I \char_set_catcode_active:N \^^L @@ -211,7 +258,6 @@ \group_end: \tl_set:Nn \l__scontents_macro_tmp_tl \l__scontents_macro_tmp_tl } -%%^^A File write start/File write stop \cs_new_protected:Npn \__scontents_file_tl_write_start:n #1 { \group_begin: @@ -283,10 +329,7 @@ \bool_if:NT \l__scontents_storing_bool { \tl_set:Nn \exp_not:N #1 - { - \exp_args:NV \__scontents_remove_leading_nl:n \l__scontents_file_tl - \bool_if:NT \l__scontents_forced_eol_bool { \exp_not:N ^^J } - } + { \exp_args:NV \__scontents_remove_leading_nl:n \l__scontents_file_tl } } } } @@ -343,28 +386,22 @@ \cs_new:Npn \__scontents_use_none_delimit_by_q_stop:w #1 \q__scontents_stop { } \group_end: \cs_generate_variant:Nn \__scontents_file_tl_write_start:n { V } -%%^^A Second atend_environment/stored_to_seq \cs_new_protected:Npn \__scontents_atend_environment: { \bool_if:NT \l__scontents_storing_bool { + \bool_if:NF \l__scontents_forced_eol_bool + { \tl_put_right:Nx \l__scontents_macro_tmp_tl { \c__scontents_hidden_space_str } } \__scontents_store_to_seq:NN \l__scontents_macro_tmp_tl \l__scontents_name_seq_env_tl + \bool_if:NT \l__scontents_print_env_bool + { \__scontents_lastfrom_seq:n \l__scontents_name_seq_env_tl } } - \bool_if:NT \l__scontents_print_env_bool - { - \tl_gset_eq:NN \g__scontents_temp_tl \l__scontents_macro_tmp_tl - \tl_gput_right:NV \g__scontents_temp_tl \c_percent_str - \group_insert_after:N \__scontents_rescan_tokens:V - \group_insert_after:N \g__scontents_temp_tl - } - \tl_clear:N \l__scontents_macro_tmp_tl } -%%^^A User command \Scontents to stored content \NewDocumentCommand { \Scontents }{ !s !O{} } { \group_begin: \IfNoValueF {#2} - { \keys_set_known:nn { scontents / Scontents } {#2} } + { \keys_set:nn { scontents / Scontents } {#2} } \char_set_catcode_active:n { 9 } \IfBooleanTF {#1} { \__scontents_verb_arg:w } @@ -372,47 +409,46 @@ } \cs_new_protected:Npn \__scontents_norm_arg:n #1 { - \exp_args:NV \__scontents_append_contents:nn \l__scontents_name_seq_cmd_tl {#1} - \bool_if:NT \l__scontents_print_cmd_bool { \__scontents_rescan_tokens:n {#1} } + \tl_set:Nx \l__scontents_temp_tl { \exp_not:n {#1} } + \tl_put_right:Nx \l__scontents_temp_tl { \c__scontents_hidden_space_str } + \__scontents_store_to_seq:NN \l__scontents_temp_tl \l__scontents_name_seq_cmd_tl + \bool_if:NT \l__scontents_print_cmd_bool + { \__scontents_lastfrom_seq:n \l__scontents_name_seq_cmd_tl } \group_end: } \NewDocumentCommand { \__scontents_verb_arg:w } { +v } { - \tl_set:Nx \l__scontents_temp_tl - { - \exp_not:n {#1} - \bool_if:NT \l__scontents_forced_eol_bool { \exp_not:N ^^J } - } + \tl_set:Nx \l__scontents_temp_tl { \exp_not:n {#1} } \tl_replace_all:Nxx \l__scontents_temp_tl { \iow_char:N \^^M } { \iow_char:N \^^J } + \bool_if:NF \l__scontents_forced_eol_bool + { \tl_put_right:Nx \l__scontents_temp_tl { \c__scontents_hidden_space_str } } \__scontents_store_to_seq:NN \l__scontents_temp_tl \l__scontents_name_seq_cmd_tl \bool_if:NT \l__scontents_print_cmd_bool - { \__scontents_rescan_tokens:V \l__scontents_temp_tl } + { \__scontents_lastfrom_seq:n \l__scontents_name_seq_cmd_tl } \group_end: } -%%^^A User command \getstored to get content \NewDocumentCommand { \getstored } { O{1} m } { \group_begin: \__scontents_rescan_tokens:x - { - \__scontents_getfrom_seq:nn {#1} {#2} - \c_percent_str - } + { \__scontents_getfrom_seq:nn {#1} {#2} } \group_end: } -%%^^A User command \typestored to verbatimized content \NewDocumentCommand { \typestored } { o m } { \group_begin: \int_set:Nn \l__scontents_seq_item_int { 1 } - \IfValueT {#1} { \keys_set:nn { scontents } {#1} } - \tl_set:Nx \l__scontents_temp_tl { \exp_args:NV \__scontents_getfrom_seq:nn \l__scontents_seq_item_int {#2} } + \IfValueT {#1} { \keys_set:nn { scontents / typemeaning } {#1} } + \tl_set:Nx \l__scontents_temp_tl + { + \exp_args:NV \__scontents_getfrom_seq:nn \l__scontents_seq_item_int {#2} + } + \tl_remove_once:NV \l__scontents_temp_tl \c__scontents_hidden_space_str \tl_log:N \l__scontents_temp_tl \tl_if_empty:NF \l__scontents_temp_tl { \__scontents_verb_print:N \l__scontents_temp_tl } \group_end: } -%%^^A Internal verb_print:N, need to verbatimized content \group_begin: \char_set_catcode_active:N \^^M \cs_new_protected:Npn \__scontents_verb_print:N #1 @@ -431,7 +467,6 @@ \cs_set_eq:NN ^^M \__scontents_verb_print_EOL: } \group_end: -%%^^A Definition of verbatimsc environment \cs_new_protected:Npn \__scontents_xverb: { \char_set_catcode_active:n { 9 } @@ -450,10 +485,8 @@ \verbatim } { } -%%^^A Tab to space \cs_new:Npn \__scontents_tabs_to_spaces: { \prg_replicate:nn { \l__scontents_tab_width_int } { ~ } } -%%^^A Patch do_noligs for ligatures \cs_new:Npn \__scontents_do_noligs:N #1 { \char_set_catcode_active:N #1 @@ -465,7 +498,6 @@ \char_generate:nn { `#1 } { 12 } } } -%%^^A Common catcode changes \cs_new_protected:Npn \__scontents_set_active_eq:NN #1 { \char_set_catcode_active:N #1 @@ -477,15 +509,13 @@ \__scontents_set_active_eq:NN \^^L \__scontents_par: \__scontents_set_active_eq:NN \^^M \__scontents_ret:w } -%%^^A User command \setupsc -\NewDocumentCommand { \setupsc } { m } +\NewDocumentCommand { \setupsc } { +m } { \keys_set:nn { scontents } {#1} } -%%^^A User command \meaningsc \NewDocumentCommand { \meaningsc } { o m } { \group_begin: \int_set:Nn \l__scontents_seq_item_int { 1 } - \IfValueT {#1} { \keys_set:nn { scontents } {#1} } + \IfValueT {#1} { \keys_set:nn { scontents / typemeaning } {#1} } \__scontents_meaningsc:n {#2} \group_end: } @@ -493,21 +523,22 @@ \char_set_catcode_active:N \^^I \cs_new_protected:Npn \__scontents_meaningsc:n #1 { - \tl_set:Nx \l__scontents_temp_tl { \exp_args:NV \__scontents_getfrom_seq:nn \l__scontents_seq_item_int {#1} } + \tl_set:Nx \l__scontents_temp_tl + { + \exp_args:NV \__scontents_getfrom_seq:nn \l__scontents_seq_item_int {#1} + } \tl_replace_all:Nxn \l__scontents_temp_tl { \iow_char:N \^^J } { ~ } + \tl_remove_once:NV \l__scontents_temp_tl \c__scontents_hidden_space_str \tl_log:N \l__scontents_temp_tl \tl_use:N \l__scontents_verb_font_tl \tl_replace_all:Nnx \l__scontents_temp_tl { ^^I } { \__scontents_tabs_to_spaces: } \cs_replacement_spec:N \l__scontents_temp_tl } \group_end: -%%^^A User command \countsc \NewExpandableDocumentCommand { \countsc } { m } - { \seq_count:c { g__scontents_seq_name_#1_seq } } -%%^^A User command \cleanseqsc + { \seq_count:c { g__scontents_name_#1_seq } } \NewDocumentCommand { \cleanseqsc } { m } - { \seq_clear_new:c { g__scontents_seq_name_#1_seq } } -%%^^A Messages used throughout the package + { \seq_clear_new:c { g__scontents_name_#1_seq } } \msg_new:nnn { scontents } { junk-after-begin } { Junk~characters~#1~\msg_line_context: : @@ -515,33 +546,17 @@ #2 } \msg_new:nnn { scontents } { empty-stored-content } - { Empty~value~for~key~`getstored'~\msg_line_context:. } + { Empty~value~for~key~'getstored'~\msg_line_context:. } \msg_new:nnn { scontents } { empty-variable } - { Variable~`#1'~empty~\msg_line_context:. } + { Variable~'#1'~empty~\msg_line_context:. } \msg_new:nnn { scontents } { rewriting-file } - { Overwriting ~ file ~ `#1' } + { Overwriting ~ file ~ '#1' } \msg_new:nnn { scontents } { writing-file } - { Writing ~ file ~ `#1' } + { Writing ~ file ~ '#1' } \msg_new:nnn { scontents } { rescanning-text } - { Rescanning~text~`#1'~after~\c_backslash_str end{scontents}~\msg_line_context:.} + { Rescanning~text~'#1'~after~\c_backslash_str end{scontents}~\msg_line_context:.} \msg_new:nnn { scontents } { multiple-begin } { Multiple~\c_backslash_str begin{scontents}~\msg_line_context:.} -\msg_new:nnn { scontents } { tab-to-space } - { Tab~has~been~converted~to~Blank~Space } -\msg_new:nnn { scontents } { feed-to-space } - { Form~Feed~has~been~converted~to~Blank~Space } -\msg_new:nnnn { scontents } { key-unknown } - { The~key~'#1'~is~unknown~and~is~being~ignored. } - { - The~module~'scontents'~does~not~have~a~key~called~'#1'.\\ - Check~that~you~have~spelled~the~key~name~correctly. - } -\msg_new:nnnn { scontents } { key-value-unknown } - { The~key~'#1'~to~which~you~passed~'#2'~is~unknown~and~is~being~ignored. } - { - The~module~'scontents'~does~not~have~a~key~called~'#1'.\\ - Check~that~you~have~spelled~the~key~name~correctly. - } \msg_new:nnn { scontents } { undefined-storage } { Storage~named~'#1'~is~not~defined. } \msg_new:nnn { scontents } { index-out-of-range } @@ -554,5 +569,43 @@ { Max = } { Min = -} #3. } } -%%^^A Finish package :) +\msg_new:nnnn { scontents } { env-key-unknown } + { The~key~'#1'~is~unknown~by~environment~'scontents'~and~is~being~ignored.} + { + The~environment~'scontents'~does~not~have~a~key~called~'#1'.\\ + Check~that~you~have~spelled~the~key~name~correctly. + } +\msg_new:nnnn { scontents } { env-key-value-unknown } + { The~key~'#1=#2'~is~unknown~by~environment~'scontents'~and~is~being~ignored. } + { + The~environment~'scontents'~does~not~have~a~key~called~'#1'.\\ + Check~that~you~have~spelled~the~key~name~correctly. + } +\msg_new:nnnn { scontents } { cmd-key-unknown } + { The~key~'#1'~is~unknown~by~'\c_backslash_str Scontents'~and~is~being~ignored.} + { + The~command~'\c_backslash_str Scontents'~does~not~have~a~key~called~'#1'.\\ + Check~that~you~have~spelled~the~key~name~correctly. + } +\msg_new:nnnn { scontents } { cmd-key-value-unknown } + { The~key~'#1=#2'~is~unknown~by~'\c_backslash_str Scontents'~and~is~being~ignored. } + { + The~command~'\c_backslash_str Scontents'~does~not~have~a~key~called~'#1'.\\ + Check~that~you~have~spelled~the~key~name~correctly. + } +\msg_new:nnnn { scontents } { type-key-unknown } + { The~key~'#1'~is~unknown~and~is~being~ignored. } + { + This~command~does~not~have~a~key~called~'#1'.\\ + This~command~only~accepts~the~key~'width-tab'. + } +\msg_new:nnnn { scontents } { type-key-value-unknown } + { The~key~'#1'~to~which~you~passed~'#2'~is~unknown~and~is~being~ignored. } + { + This~command~does~not~have~a~key~called~'#1'.\\ + This~command~only~accepts~the~key~'width-tab'. + } \file_input_stop: +\endinput +%% +%% End of file `scontents.sty'. |