texlive[63720] Master: cprotectinside (25jun22)
commits+karl at tug.org
commits+karl at tug.org
Sat Jun 25 22:22:11 CEST 2022
Revision: 63720
http://tug.org/svn/texlive?view=revision&revision=63720
Author: karl
Date: 2022-06-25 22:22:10 +0200 (Sat, 25 Jun 2022)
Log Message:
-----------
cprotectinside (25jun22)
Modified Paths:
--------------
trunk/Master/tlpkg/bin/tlpkg-ctan-check
trunk/Master/tlpkg/tlpsrc/collection-latexextra.tlpsrc
Added Paths:
-----------
trunk/Master/texmf-dist/doc/latex/cprotectinside/
trunk/Master/texmf-dist/doc/latex/cprotectinside/README
trunk/Master/texmf-dist/doc/latex/cprotectinside/cprotectinside.pdf
trunk/Master/texmf-dist/doc/latex/cprotectinside/cprotectinside.tex
trunk/Master/texmf-dist/tex/latex/cprotectinside/
trunk/Master/texmf-dist/tex/latex/cprotectinside/cprotectinside.sty
trunk/Master/tlpkg/tlpsrc/cprotectinside.tlpsrc
Added: trunk/Master/texmf-dist/doc/latex/cprotectinside/README
===================================================================
--- trunk/Master/texmf-dist/doc/latex/cprotectinside/README (rev 0)
+++ trunk/Master/texmf-dist/doc/latex/cprotectinside/README 2022-06-25 20:22:10 UTC (rev 63720)
@@ -0,0 +1,26 @@
+cprotectinside -- Use cprotect arbitrarily deeply nested
+ Extends on `cprotect` package to allow users to use verbatim-like commands inside arbitrary
+ parameters.
+
+
+Released under the LaTeX Project Public License v1.3c or later
+See http://www.latex-project.org/lppl.txt
+
+Report bugs at https://github.com/user202729/TeXlib
+
+========
+
+Copyright 2022 user202729
+
+This work may be distributed and/or modified under the conditions of the
+LaTeX Project Public License (LPPL), either version 1.3c of this license or
+(at your option) any later version. The latest version of this license is in
+the file:
+
+ http://www.latex-project.org/lppl.txt
+
+This work has the LPPL maintenance status `maintained'.
+
+The Current Maintainer of this work is user202729.
+
+This work consists of the files cprotectinside.sty.
Property changes on: trunk/Master/texmf-dist/doc/latex/cprotectinside/README
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: trunk/Master/texmf-dist/doc/latex/cprotectinside/cprotectinside.pdf
===================================================================
(Binary files differ)
Index: trunk/Master/texmf-dist/doc/latex/cprotectinside/cprotectinside.pdf
===================================================================
--- trunk/Master/texmf-dist/doc/latex/cprotectinside/cprotectinside.pdf 2022-06-25 13:30:46 UTC (rev 63719)
+++ trunk/Master/texmf-dist/doc/latex/cprotectinside/cprotectinside.pdf 2022-06-25 20:22:10 UTC (rev 63720)
Property changes on: trunk/Master/texmf-dist/doc/latex/cprotectinside/cprotectinside.pdf
___________________________________________________________________
Added: svn:mime-type
## -0,0 +1 ##
+application/pdf
\ No newline at end of property
Added: trunk/Master/texmf-dist/doc/latex/cprotectinside/cprotectinside.tex
===================================================================
--- trunk/Master/texmf-dist/doc/latex/cprotectinside/cprotectinside.tex (rev 0)
+++ trunk/Master/texmf-dist/doc/latex/cprotectinside/cprotectinside.tex 2022-06-25 20:22:10 UTC (rev 63720)
@@ -0,0 +1,167 @@
+%%! TEX program = lualatex
+\ProvidesFile{cprotectinside.tex} [2022/06/25 v0.0.0 Use cprotect arbitrarily deeply nested]
+\documentclass{l3doc}
+\EnableCrossrefs
+\CodelineIndex
+\RecordChanges
+\usepackage{hyperref}
+\usepackage{csquotes}
+%\MakeOuterQuote{"}
+\begin{document}
+\GetFileInfo{\jobname.tex}
+
+\title{\textsf{cprotectinside} --- Use cprotect arbitrarily deeply nested
+\thanks{This file describes version \fileversion, last revised \filedate.}
+}
+\author{user202729%
+%\thanks{E-mail: (not set)}
+}
+\date{Released \filedate}
+
+\maketitle
+
+\changes{v0.0.0}{2022/05/18}{First public release}
+
+\let\backtick=`
+\MakeShortVerb{`}
+
+\begin{abstract}
+ Extends on `cprotect` package to allow users to use verbatim-like commands inside arbitrary
+ parameters.
+
+\end{abstract}
+
+\section{Usage}
+
+
+\subsection{Main function}
+\begin{function}{\cprotectinside}
+ \begin{syntax}
+ \cs{cprotectinside} \meta{delimiter} \meta{content} \\
+ \end{syntax}
+ Execute \meta{content} that possibly contains verbatim content.
+
+ This is a bit hard to explain. To give an example:
+
+ Take an example from \url{https://tex.stackexchange.com/q/24574},
+ you want to write \verb+\textbf{using \verb|-i| as}+. Unfortunately, `\textbf` does not accept
+ `\verb` %` %workaround for syntax highlighter
+ in input.
+
+ Then you need to
+
+ \begin{itemize}
+ \item Wrap the whole code inside `\cprotectinside{!}{ ... }`
+ \item Wrap each `\verb` %`
+ command (and its arguments) inside `!...!`.
+ \end{itemize}
+
+The resulting code would be:
+
+ \begin{verbatim}
+ \cprotectinside{!}{\textbf{\using !\verb|-i|! as}}}
+ \end{verbatim}
+
+The first argument `!` is the delimiter, it can be changed as long as it's changed correspondingly in the \meta{content} part.
+
+In this simple case, it's possible to simply use `cprotect`. Nevertheless this package is useful in some cases, for example...
+
+\begin{itemize}
+ \item Value of keyval argument:
+
+ \begin{verbatim}
+ \cprotectinside{*}{
+ \begin{lstlisting}[language=Perl,
+ caption={text *\verb+myverb+* some more text}]
+ code code
+ code code
+ \end{lstlisting}
+ }
+ \end{verbatim}
+
+ \item Pseudo-environments (contrived example):
+
+ \begin{verbatim}
+ \cprotectinside{*}{
+ \begin{align}
+ 1 &= 2+\text{text *\verb+text+* text}
+ \end{align}
+ }
+ \end{verbatim}
+\end{itemize}
+
+
+
+\end{function}
+
+
+\subsection{Common issues}
+
+\begin{itemize}
+
+ \item If you get the error message
+
+ \begin{quote}
+ LaTeX cmd Error: Verbatim-like command \backtick `\cprotectinside`' illegal in argument.
+ \end{quote}
+
+ You can't use a literal TAB character inside \meta{content}
+ because of a known bug: \url{https://tex.stackexchange.com/q/508001}
+
+ (when the tab character is at the begin of a line -- which is the most common case, it will give no error message but they will be removed from the code. Which might matter for `verbatim` environments, for example.)
+
+ \item Note that the following code will not work as desired
+ \begin{verbatim}
+ \cprotectinside{!}{
+ some content
+ %}
+ some other content
+ }
+ \end{verbatim}
+ because of the unbalanced brace in the comment. It's possible to use characters different from braces to delimit the second argument
+ \begin{verbatim}
+ \cprotectinside{!}|
+ some content
+ %}
+ some other content
+ |
+ \end{verbatim}
+ or use the workarounds described in the documentation of \texttt{cprotect} package.
+
+ \item Contents that is intended to be passed as
+ \enquote{text}
+ to the outer command must not be `cprotect`ed.
+
+ As a general rule of thumb, if the content inside can be replaced with a `\includegraphics` with no compilation error,
+ it can be `cprotect`ed.
+
+
+\end{itemize}
+
+\subsection{Implementation note}
+
+The working of the code is similar to how \texttt{cprotect} package works. Described in more details
+in \url{https://tex.stackexchange.com/q/622512} (post by the package author).
+
+In particular, given the code
+\verb+\textbf{using \verb|-i| as}+
+the command might transform it to become
+\verb+\textbf{using \cpiContentAi/ as}+
+then execute the resulting code.
+Where `\cpiContentAi/` is defined to be something similar to `\input{inner.tex}`, with the (imaginary) file
+`inner.tex` has the content `\verb|-i|\empty`.
+
+The string to be appended inside each inner chunk defaults to `\empty`, used to remove the space generated at the
+end of each file (similar in purpose to `^^E^^L` used by `cprotect` package), but it can be configured:
+
+\begin{variable}{\cprotectinsideAppend}
+ The content to be appended to every inner macro. Should already be detokenized. Defaults to the detokenized string \texttt{\textbackslash empty}.
+\end{variable}
+
+
+\StopEventually{%
+ \PrintChanges
+ \PrintIndex
+}
+\Finale
+\end{document}
Property changes on: trunk/Master/texmf-dist/doc/latex/cprotectinside/cprotectinside.tex
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: trunk/Master/texmf-dist/tex/latex/cprotectinside/cprotectinside.sty
===================================================================
--- trunk/Master/texmf-dist/tex/latex/cprotectinside/cprotectinside.sty (rev 0)
+++ trunk/Master/texmf-dist/tex/latex/cprotectinside/cprotectinside.sty 2022-06-25 20:22:10 UTC (rev 63720)
@@ -0,0 +1,78 @@
+% File: cprotectinside.sty
+% Copyright 2022 user202729
+%
+% This work may be distributed and/or modified under the conditions of the
+% LaTeX Project Public License (LPPL), either version 1.3c of this license or
+% (at your option) any later version. The latest version of this license is in
+% the file:
+%
+% http://www.latex-project.org/lppl.txt
+%
+% This work has the LPPL maintenance status `maintained'.
+%
+% The Current Maintainer of this work is user202729.
+
+\ProvidesExplPackage{cprotectinside}{2022/06/25}{0.0.0}{Use cprotect arbitrarily deeply nested}
+
+% '__' ↔ '_cpi_'
+
+\msg_new:nnn {cprotectinside} {delimiter-not-match} {Delimiters~does~not~match!}
+
+\int_new:N \_cpi_used
+
+\edef \cprotectinsideAppend { \c_backslash_str empty }
+% 12 is other catcode
+
+\cs_generate_variant:Nn \tl_replace_all:Nnn {Nnx}
+
+% #1: single character for the delimiter e.g. '+'
+% #2: the body
+
+
+\NewDocumentCommand\cprotectinside{v +v}{
+
+ %\seq_set_split_keep_spaces:Nnn \_cpi_entries {#1} {#2}
+ % cannot do this in old version
+
+ \tl_set:Nn \_cpi_entries {#2}
+ \tl_replace_all:Nnx \_cpi_entries {~} { \char_generate:nn {`\ } {12} } % replace space <space> with other <space>
+ \seq_set_split:NnV \_cpi_entries {#1} \_cpi_entries % so that they're not lost here. Support older versions without \seq_set_split_keep_spaces
+
+ \int_if_even:nT {\seq_count:N \_cpi_entries} {
+ \msg_error:nn {cprotectinside} {delimiter-not-match}
+ }
+ \tl_build_gbegin:N \_cpi_result
+ \seq_map_indexed_inline:Nn \_cpi_entries {
+ % ##1 is index, ##2 is item
+ \int_if_even:nTF {##1} {
+ % index 2, 4, 6...: content to be cprotect-ed
+ \int_incr:N \_cpi_used
+ \exp_args:NV \_cpi_aux:nn \cprotectinsideAppend {##2}
+ \tl_build_gput_right:Nx \_cpi_result { \c_backslash_str cpiContentA \romannumeral \_cpi_used / }
+
+ } {
+ % index 1, 3, 5...: normal text
+ \tl_build_gput_right:Nn \_cpi_result {##2}
+ }
+ }
+ %\tl_build_gput_right:Nn \_cpi_result {##2}
+ \tl_build_gend:N \_cpi_result
+ \begingroup
+ \newlinechar=13~ % have to setup like this because +v collect newline as char 13
+ \exp_args:NNNV \expandafter \endgroup \scantokens \_cpi_result
+}
+
+\def \_cpi_aux:nn #1 #2 {
+ \protected \cs_set_protected:cpn {cpiContentA \romannumeral \_cpi_used} / {\cprotectinsideReexec{#2 #1}}
+}
+
+\def \cprotectinsideReexec #1 {
+ \begingroup
+ \newlinechar=13~
+ \expandafter % expand the \scantokens once when newlinechar=13
+ \endgroup
+ \scantokens {#1} % then execute the code with original newlinechar value
+}
+
+\cs_generate_variant:Nn \_cpi_aux:n {V}
+\cs_generate_variant:Nn \tl_gset_rescan:Nnn {NnV}
Property changes on: trunk/Master/texmf-dist/tex/latex/cprotectinside/cprotectinside.sty
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Modified: trunk/Master/tlpkg/bin/tlpkg-ctan-check
===================================================================
--- trunk/Master/tlpkg/bin/tlpkg-ctan-check 2022-06-25 13:30:46 UTC (rev 63719)
+++ trunk/Master/tlpkg/bin/tlpkg-ctan-check 2022-06-25 20:22:10 UTC (rev 63720)
@@ -219,7 +219,7 @@
countriesofeurope counttexruns courier courier-scaled courierten
courseoutline coursepaper
coverpage covington
- cprotect cqubeamer cquthesis
+ cprotect cprotectinside cqubeamer cquthesis
crbox create-theorem crefthe crimson crimsonpro crop
crossreference crossreftools crossrefware crossword crosswrd
crumbs cryptocode cryst
Modified: trunk/Master/tlpkg/tlpsrc/collection-latexextra.tlpsrc
===================================================================
--- trunk/Master/tlpkg/tlpsrc/collection-latexextra.tlpsrc 2022-06-25 13:30:46 UTC (rev 63719)
+++ trunk/Master/tlpkg/tlpsrc/collection-latexextra.tlpsrc 2022-06-25 20:22:10 UTC (rev 63720)
@@ -256,6 +256,7 @@
depend coursepaper
depend coverpage
depend cprotect
+depend cprotectinside
depend crbox
depend create-theorem
depend crefthe
Added: trunk/Master/tlpkg/tlpsrc/cprotectinside.tlpsrc
===================================================================
More information about the tex-live-commits
mailing list.