%%%==============================================================================
% WinEdt pragmas
% !Mode:: "TeX:EN"
% Default Compile engines:
% !TEX program = pdflatex
% !PDFTeXify ext =  --enable-etex  --restrict-write18
% !PDFLaTeX ext  =  --enable-etex  --restrict-write18
% !BIB program = biber
%%%==============================================================================
%% Copyright 2026-present by Alceu Frigeri
%%
%% This work may be distributed and/or modified under the conditions of
%%
%% * The [LaTeX Project Public License](http://www.latex-project.org/lppl.txt),
%%   version 1.3c (or later), and/or
%% * The [GNU Affero General Public License](https://www.gnu.org/licenses/agpl-3.0.html),
%%   version 3 (or later)
%%
%% This work has the LPPL maintenance status *maintained*.
%%
%% The Current Maintainer of this work is Alceu Frigeri
%%
%% This is version {1.0} {2026/11/27}
%%
%% The list of files that compose this work can be found in the README.md file at
%% https://ctan.org/pkg/codeverbatim
%%
%%%==============================================================================
\documentclass[10pt]{article}
\RequirePackage[verbose,a4paper,marginparwidth=27.5mm,top=2.5cm,bottom=1.5cm,hmargin={40mm,20mm},marginparsep=2.5mm,columnsep=10mm,asymmetric]{geometry}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{lmodern}
\usepackage[infograb,silence]{codedescribe}
\RequirePackage[inline]{enumitem}
\SetEnumitemKey{miditemsep}{parsep=0ex,itemsep=0.4ex}

\usepackage { longtable,multirow,hhline}

\usepackage{codeverbatim}
\usepackage{codehighlight}

\usepackage{newfloat}

\newcodekey{codehl}
  {
    codeprefix={},
    resultprefix={},
    letter={_ : -},
    texcs=[2]{hlKeysetDef,hlSettings,cvNewEnvironment,hlDisplayV,hlLangDef,hlHLsetDef,
    hlBasefmtDef,hlSettingsDef,cvSVerbNew,cvSVerbSet,cvSVerbOn,cvSVerbOff,cvHideSpc,cvRetokenEnvNewCommand,codeverb_new_environment:nnnnn},
    texcs=[3]{ExplSyntaxOn,ExplSyntaxOff},
    emph=[1]{nestable,tagged,based,on,keywd,string,in,on,case,sensitive,
    alphanumeric,digits,oletter,identifier,area,comment,line,at,discard,
    active,delimited,replace,suppress,emph,info,note,
    gobble,inline,add,endmark,base,format,show,spaces,text,width,wrap,indent,
    background,numbers,sep,rule,width,color,frame,left,right,top,bottom,
    hl,set,registered,defined,settings,basefmt,hlset,keyset,lang,show,all
    settings,language,drop,first,other }  
  } 

\ExplSyntaxOn
\NewDocumentCommand \citepkg { sO{}m } 
  {
    \seq_set_from_clist:Nn \l__codehl_doctmp_seq { #2 }
    \seq_pop_left:NNTF \l__codehl_doctmp_seq
      \l__codehl_doctmpa_tl
      { 
        \emph { `` \l__codehl_doctmpa_tl '' }
        \seq_pop_right:NNTF \l__codehl_doctmp_seq
          \l__codehl_doctmpb_tl
          {
            \seq_map_inline:Nn \l__codehl_doctmp_seq
              {
               , ~ \emph { `` ##1 '' }
              }
            \use:n { ~ } and ~ \emph { `` \l__codehl_doctmpb_tl '' }
          }
          { }
         \use:n { ~ }  from ~ 
      }
      {  }
  
    \bool_if:NTF #1
      { \citetitle { #3 } \, \cite { #3 }  }
      { \tsobj [pkg]  { #3 } \, \cite { #3 } }
  }
\ExplSyntaxOff

\begin{codestore}[demofloat]
  %% This must be declared in the preamble
  \DeclareFloatingEnvironment
    [fileext={lov},listname={List of C code},name={C code},placement=htb]
    {floatenv}
\end{codestore}

\tsexec{demofloat}

\begin{codestore}[demoLoad]
% only in the preamble
\hlLangLoad{ C , php , TeX }
\end{codestore}

\tsexec{demoLoad}[1]


\begin{codestore}[demo00]
% if the file definition were already loaded, the following can be anywhere
\hlSettings
  {
    keywd set = { C }
  }

\cvNewEnvironment[verb tl=\DemoV]{DemoEnv}{}
  {}
  { 
  \hlDisplayV \DemoV 
%  \myShow \DemoV
  }
\end{codestore}

\begin{codestore}[demo00]
\hlSettings
  {
    language = C ,
    keywd set = C
  }
\end{codestore}

\tsexec{demo00}[1]


%% if needed
\RequirePackage[backend=biber]{biblatex}
\addbibresource{codeverbatim.bib}

\RequirePackage[hidelinks,hypertexnames=false]{hyperref}

\begin{document}
\tstitle{
  author={Alceu Frigeri\footnote{\tsfmt{\url{https://github.com/alceu-frigeri/codeverbatim}}}},
  date={\tsdate},
  title={The codeverbatim Package\break Version \PkgInfo{codeverbatim}{version}}
  }
  

\begin{typesetabstract}
 
This package enables the construction of custom verbatim commands/environments, allowing the customization of the desired behaviour, including (pre/post) processing of the grabbed code before typesetting it.
\end{typesetabstract}

\tableofcontents

\section{Introduction}

The aim of this package (and its companion \citepkg{codehighlight}) is to allow the creation of fully customizable verbatim environments. To achieve that, unlike other packages of the kind as \citepkg{fancyvrb}, \citepkg{scontents} or \citepkg{listings}, which have a fixed set of ways to collect/display a verbatim environment, \tsobj[pkg]{codeverbatim,codehighlight}  split the action of grabbing some text in verbatim mode (this package, \tsobj[pkg]{codeverbatim}) from typesetting it with or without syntax highlight (package \citepkg{codehighlight}).

\tsobj[pkg]{codeverbatim} package offers a mechanism to create custom verbatim environments whereas the grabbed text will be stored either in a \citepkg{expl3} token list or sequence variables with hooks allowing the customization of the entire process.
\begin{tsremark}
  A great deal of the functionality of this package is inspired on the \citepkg{scontents} package.
\end{tsremark}

\begin{tsremark}
  Although the two packages are though to be used together, they can be used separately. It's perfectly possible to use \tsobj[pkg]{codeverbatim} together with \citepkg{listings} package, or  \citepkg{codehighlight} with other verbatim package, like \citepkg{fancyvrb} (using the macros \tsobj{\SaveVerb,\UseVerb}) or \citepkg{scontents} (redefining the \tsobj[env]{verbatimsc} environment).
\end{tsremark}
Lastly, this package is fully written in \citepkg{expl3}, but given that one might want to use it in a \LaTeXe{} context (either at package or document level), all public commands have a \LaTeXe{} alias, and, for simplicity, they are listed together.


\section{The codeverbatim Package}\label{pkg:codeverb}
The aim of this package is to allow to construction of custom environments and commands to capture verbatim content. Among others, one can customize:
\begin{itemize}
  \item which characters should be captured with category code other.
%  \item if an environment, can it be nested?
  \item how to handle the text after the environment begin and the first end of line.
  \item how to process the captured code.
\end{itemize}
Another point is that this package only offers ways to capture content in verbatim mode, leaving it to the user to define how to pre/postprocess and display it, for instance, using \citepkg{codehighlight} package (see section \emph{Display commands}).


\subsection{Characters Category Code and Common Keys}\label{codeverb:commonkeys}
When capturing content in verbatim mode, many characters have their usual category code changed to other (12), but not all. In particular \tsfmt[verb]{\^{}\^{}M }  (char: 13, End Of Line character) always has its category code changed to other. 
\begin{center}
\begin{tabular}{clclcl}
  \hline

\tsverb[verb]{\ } & (char: 92) &   
\tsfmt[verb]{\$}  & (char: 36)&
\tsfmt[verb]{\^{}\^{}A }  & (char: 1) 
\\  
\tsfmt[verb]{\{}  & (char: 123) &
\tsfmt[verb]{\^{}}  & (char: 94)&
\tsfmt[verb]{\^{}\^{}I }  & (char: 9)
\\
\tsfmt[verb]{\}}  & (char: 125) &
\tsfmt[verb]{\_{}}  & (char: 95) &
\tsfmt[verb]{\^{}\^{}J }  & (char: 10)
\\
\tsfmt[verb]{\#}  & (char: 35) &
\tsfmt[verb]{\&}  & (char: 38) &
\tsfmt[verb]{\^{}\^{}K }  & (char: 11)
\\
\tsfmt[verb]{\%{}}  & (char: 37) &
\tsfmt[verb]{\~{}}  & (char: 126) &
\tsfmt[verb]{\ }  & (char: 32, space) 
\\
  \hline
\end{tabular}
\end{center}
\begin{tsremark}
  This list is named ``other characters list'' in the following (for simplicity).
\end{tsremark}
\begin{tsremark}
  As noted above, \tsfmt[verb]{\^{}\^{}M } will always have its category code changed to other (12). Moreover, following the \tsobj{\tl_retokenize:n} convention, lines will be terminated by \tsfmt[verb]{\^{}\^{}J} (and not \tsfmt[verb]{\^{}\^{}M}), also with category code other. See the chapter ``Reassigning category codes'' (under ``Manipulating tokens in token lists'') from \citepkg*{expl3}, for details.
\end{tsremark}

By default no other character has its category code changed. This can be changed with the keys below, in which there are two cases: 
\begin{itemize} %[nosep]
  \item[(i)] List of characters set to other: keys \tsobj[key]{set other, other},
  \item[(ii)] List of characters set to letter: key \tsobj[key]{letter},
%  \item[(iii)] Fully dedicated \tsobj[pkg]{expl3} ``category code table'': key \tsobj[key]{cctab}.
\end{itemize}
   

These keys are common to all main code verbatim commands and expect a comma separated list of characters:
%, except \tsobj[key]{cctab} which expects the name of a cctab variable (without the escape character):
\begin{describelist*}{keys}
  \describe{set other}{ This will reset and fully replace the ``other characters list''.  If used more than once, only the last attribution remains.
  
  The default is the ``other characters list'' above. Don't forget to escape the characters as needed, for instance, like \tsverb**[verb]{\^ ^K}
  }
  \describe{other}{(default: empty list) This will add  characters to the ``other characters list'' and can be called multiple times. }
  \describe{letter}{(default: empty list) The characters on the list (cumulative list) will be made letter. }
\begin{tsremark}
  These character lists shall contain a single char per item! and they will raise an error if more than one character (per item) is found.
\end{tsremark}
%  \describe{cctab}{a cctab, ``category code table'' variable as described in  the chapter ``The l3cctab module'' from \citetitle{expl3} \cite{expl3}. Note, this key expects a variable name without the escape character.}
%\begin{tsremark}
%  Regardless of the \tsobj[key]{cctab} used, \tsfmt[verb]{\^{}\^{}M } will always have its category code changed to other (12), and lines will be terminated with a \tsfmt[verb]{\^{}\^{}J} (category code other, 12).
%\end{tsremark}
\begin{tsremark}[\color{red}Attention]
  If all keys are given, first \tsobj[keys]{other} then \tsobj[key]{letter} will be applied.
  % Remember to \tsobj[key]{set other = \{\}} (empty list) for \tsobj[key]{cctab} be the sole definition.
\end{tsremark}
\end{describelist*}
%   
%\ExplSyntaxOn
%\seq_set_from_clist:Nn \l__codeverb_set_other_seq
%  { ~,\ , \^^A,\^^I,\^^J,\^^K }
%
%  \seq_map_inline:Nn \l__codeverb_set_other_seq
%    {
%      \tsverb[verb]{#1}
%    }
%\ExplSyntaxOff  

\subsection{New Verbatim Environment}\label{codeverb:newenv}

\begin{codedescribe}{\cvNewEnvironment,\codeverb_new_environment:nnnnn}
\begin{codesyntax}%
\tsmacro{\cvNewEnvironment}[keys]{env-name,arg spec,begin-code,end-code}
\tsmacro{\codeverb_new_environment:nnnnn}{keys,env-name,signature,begin-code,end-code}
\end{codesyntax}
This will create a new document environment \tsobj[marg]{env-name}, following the \tsobj{\NewDocumentEnvironment}  structure. \tsobj[marg]{arg spec} is the desired \tsobj[marg]{env-name} parameter specification list (\tsobj{\NewDocumentEnvironment} 1st parameter, see \citepkg*{usrguide}). The \tsobj[marg]{begin-code} code will be executed before the verbatim code gets grabbed. The \tsobj[marg]{end-code} will be executed right after, see the keys \tsobj[key]{inline,verb tl} below for details on how to further handle the verbatim content.
\end{codedescribe}
\begin{tsremark}
  If short verbatim commands are on (\tsobj[code,or]{\cvSVerbOn,\codeverb_sverb_on:}) those active characters will be made other (see \ref{codeverb:caveats}) after applying the characters category code defined here (with the common keys from \ref{codeverb:commonkeys}) and before applying the characters category code defined with \tsobj[code,or]{\cvSetEnvCC,\codeverb_set_env_catcode:n} (see \ref{codeverb:auxiliary-commands} below).
\end{tsremark}
\tsobj[marg]{keys} can be any combination of (besides the ones from \ref{codeverb:commonkeys}):
\begin{describelist*}{keys}

  \describe{drop first}{(default: true) If the character following the environment begin until the line end shall be processed or discarded. The default behaviour is similar to other packages of the kind, like \tsobj[pkg,or]{listings,fancyvrb}}
  \describe{drop blanks}{(default: false) If set to true, and the initial lines are blank, those lines will be discarded.}
  \describe{line proc}{(default: -nothing-) The given command shall grab 2 parameters. It will receive a single line (verbatim material) as the 2nd parameter and a temporary token list as the 1st parameter. The simplest command would be \tsobj{\tl_set:Nn} (no pre-processing at all). This can be used to pre-process the verbatim content, one line at a time. }
  \describe{inline}{(default: false) If set, \tsobj[marg]{end-code} will receive the verbatim material as \tsfmt{\#1}. This has precedence over the key \tsobj[key]{verb tl}.}
  \describe{verb tl}{(default: \tsobj{\g_codeverb_verb_body_tl}) If \tsobj[key]{inline} is set to false, the verbatim material will be stored in the given token list variable, before \tsobj[marg]{end-code} is executed. The assignment is global.
  
  Off course, the default is ok to be used in an \citepkg{expl3} code régime, you may want to change that.}
\end{describelist*}

\subsubsection{catcode commands}\label{codeverb:auxiliary-commands}

\begin{codedescribe}{\cvSetEnvCC , \codeverb_set_env_catcode:n}
\begin{codesyntax}%
\tsmacro{\cvSetEnvCC}{keys}
\tsmacro{\codeverb_set_env_catcode:n}{keys}
\end{codesyntax}
These can only be used in the declaration of a new verbatim environment, and are meant to be used in the \tsobj[marg]{begin-code}, allowing for further (local) customization of characters category code. \tsobj[marg]{keys} can be any combination of the common keys (see \ref{codeverb:commonkeys}). For example:
\end{codedescribe}
\begin{codestore}[env-cctab]
  \cvNewEnvironment[drop first]{myEnv}{O{}}
    { \cvEnvCCset {#1} }
    { }
  ...
  
  \begin{myEnv}[letter = { @ , \_ }]
    some text
  \end{myEnv}
\end{codestore}

\tscode*[codeprefix={}]{env-cctab}

Note that the environment \tsobj[env]{myEnv} was defined with the default verbatim setup (category codes as in \ref{codeverb:commonkeys}). The single optional parameter allows the end user to change the category code of characters.
\begin{tsremark}
  It won't replace the environment defaults, but will be applied after the environment setup.
\end{tsremark}
\begin{tsremark}[\color{red}Attention]
  Unlike in all other cases, the default ``other characters list'' for these commands is an empty list. That way, it will only change the catcode (to other or letter) of the given characters.
   %Of course, if the end user gives a \tsobj[key]{cctab}, everything changes.
\end{tsremark}

\subsection{Store commands}\label{codeverb:auxiliary}

Besides just storing the verbatim content in a token list variable (key \tsobj[key]{verb tl} above) one has a few other options:
\begin{itemize}[nosep]
  \item[(i)] store the verbatim content in dedicated sequence variables (similar to \citepkg{scontents} package), 
  \item[(ii)] display them using another package (like \citepkg{listings}) or
  \item[(iii)] use them as latex code right away. The following commands aim at exactly that.
\end{itemize} 

\begin{codedescribe}{\cvNewStoreCommands , \codeverb_new_store_cmds:nn}
\begin{codesyntax}%
\tsmacro{\cvNewStoreCommands}[key]{cs-base}
\tsmacro{\codeverb_new_store_cmds:nn}{key,cs-base}
\end{codesyntax}
These will create a set of commands prefixed with \tsobj[marg]{cs-base}, using a set of dedicated \citepkg{expl3} sequence variables to help handle verbatim code in a way similar to how the package \citepkg{scontents} does.  By default, two \citepkg{expl3} commands  and two \LaTeXe{} aliases will be created. This can be changed with the following key:

\begin{describelist*}{key}
  \describe{expl3}{(default: false) If set, only the \citepkg{expl3} variants will be created and no \LaTeXe{} aliases will be defined.}
\end{describelist*}
\end{codedescribe}

\begin{codedescribe}{\<cs-base>PutRight ,  \<cs-base>PutRightnV , \<cs-base>Merge , \<cs-base>_gput_right:nn ,  \<cs-base>_gput_right:nV , \<cs-base>_merge:Nnn }
\begin{codesyntax}%
\tsmacro{\<cs-base>PutRight}{st-name,verb-content}
\tsmacro{\<cs-base>PutRight}{st-name,tl-var}
\tsmacro{\<cs-base>Merge}{var,base-list,index-list}
\tsmacro{\<cs-base>_gput_right:nn}{st-name,verb-content}
\tsmacro{\<cs-base>_gput_right:nn}{st-name,tl-var}
\tsmacro{\<cs-base>_merge:Nnn}{var,base-list,index-list}
\end{codesyntax}
The \tsobj{\<cs-base>PutRight} (or \tsobj{\<cs-base>_gput_right:nn}) will create (as needed) an internal sequence variable associated with \tsobj[marg]{st-name} and store \tsobj[marg]{verb-content} in it. The \tsobj{\<cs-base>PutRightnV,\<cs-base>_gput_right:nV} variants will store the content of a token list var, \tsobj[marg]{tl-var}.

The \tsobj{\<cs-base>Merge} (or \tsobj{\<cs-base>_merge:Nnn}) will merge items of one, or more, of those sequences.
\end{codedescribe}
 The syntax choosen resembles the one from the command \tsobj{\mergesc} from package \citepkg{scontents}, and there are two main (proper) cases:
 \begin{itemize}
   \item \tsobj[marg]{index-list} is an empty list. 
   
   In this case \tsobj[marg]{base-list} is expected to be a list of the kind \tsobj[marg]{st-name}\tsargs[oarg]{index-ref}, where \tsobj[marg]{index-ref} can be a single number (the sequence index) or a range like \tsobj[marg]{index}-\tsobj[marg]{index}. $1$ is the index of the first item, while $end$ can be used to reference the last item of a sequence, so that, \tsobj[marg]{st-name}\tsverb[oarg]{[2-end]} will refer all items starting from the 2nd. If no \tsargs[oarg]{index-ref} is given, then the last item of \tsobj[marg]{st-name} will be used.
   
   \item \tsobj[marg]{index-list} isn't empty. 
   
   In this case \tsobj[marg]{base-list} is expected to be a list of \tsobj[marg]{st-name}s (no indexes given), while \tsobj[marg]{index-list} is expected to be a list of just indexes, then all indexes from \tsobj[marg]{index-list} will be applied to each \tsobj[marg]{st-name} from \tsobj[marg]{base-list}.
 \end{itemize}
For example:
\begin{codestore}[store-cmd]
  \cvNewStoreCommands {myStore}
  ...
  ... many calls to \myStorePutRight { case-A } { -content- }
  ...
  ... many calls to \myStorePutRight { case-B } { -content- }
  
  \myStoreMerge { \tempA } { case-A[1] , case-B[2] , case-A[2-end] , case-B }

  \myStoreMerge { \tempB } { case-A , case-B } { 1 , 3-end }
\end{codestore}

\tscode*[codeprefix={}]{store-cmd}

\tsobj{\tempA} will end up with the 1st item from \tsobj[marg]{case-A}, then the  2nd item from \tsobj[marg]{case-B}, followed by all items from the 2nd to the last one from \tsobj[marg]{case-A}, and finally the last one from \tsobj[marg]{case-B}.

\tsobj{\tempB} will end up with the 1st item from \tsobj[marg]{case-A} followed by all items from the 3rd to the last one from  \tsobj[marg]{case-A}, then the 1st item from \tsobj[marg]{case-B} followed by all items from the 3rd to the last one from  \tsobj[marg]{case-B}.


\subsection{Retokenizing}
\begin{codedescribe}{\cvRetokenEnvNewCommand , \codeverb_retoken_env_newcs:nnn }
\begin{codesyntax}%
\tsmacro{\cvRetokenEnvNewCommand}[key]{env-cmd,env-name}
\tsmacro{\codeverb_retoken_env_newcs:nnn}{key,env-cmd,env-name}
\end{codesyntax}
These will create a set of commands (see below) tailored at retokenizing  some (verbatim) content inside the given   environment \tsobj[marg]{env-name}.
 By default, two \citepkg{expl3} commands  and two \LaTeXe{} aliases will br created. This can be changed with the following key:

\begin{describelist*}{key}
  \describe{expl3}{(default: false) If set, only the \tsobj[pkg]{expl3} variants will be created and no \LaTeXe{} aliases will be defined.}
\end{describelist*}
\end{codedescribe}

\begin{codedescribe}{ \<env-cmd> , \<env-cmd>V , \<env-cmd>:n , \<env-cmd>:V }
\begin{codesyntax}%
\tsmacro{\<env-cmd>}{verb-content}
\tsmacro{\<env-cmd>V}{tl-var}
\tsmacro{\<env-cmd>:n}{verb-content}
\tsmacro{\<env-cmd>:V}{tl-var}
\end{codesyntax}
\tsobj{\<env-cmd>} (viz-à-viz \tsobj{\<env-cmd>:n}) will re-scan (retokenize)  \tsobj[marg]{verb-content} inside an \tsobj[marg]{env-name} environment. Similarly, \tsobj{\<env-cmd>V} (viz-à-viz \tsobj{\<env-cmd>:V}) will re-scan the contents (single expansion) of the \tsobj[marg]{tl-var} inside the \tsobj[marg]{env-name} environment. So that, for example:
\end{codedescribe}

\begin{codestore}[new-env]
  \lstnewenvironment{lstenv}
    {
      % listings setup
    }
    {}
  
  \cvRetokenEnvNewCommand 
    {VerbListing} {lstenv}
\end{codestore}

\tscode*[codeprefix={},emph={lstenv}]{new-env}

once defined, \tsobj{\VerbListingV} \tsobj{\g_codeverb_verb_body_tl} (err, the variable defined with the \tsobj[key]{verb tl}) could be called in the \tsobj[marg]{end-code} of a verbatim environment (see \ref{codeverb:newenv}), which would result in the verbatim content just grabbed (into \tsobj{\g_codeverb_verb_body_tl}) being displayed using the \tsobj[env]{lstenv} environment (set up with the \citepkg{listings} package). This will be, effectively, equivalent to
\begin{codestore}[new-envb]
  \begin{lstenv}
    ... content of \g_codeverb_verb_body_tl 'retokenized' ...
  \end{lstenv}
\end{codestore}

\tscode*[codeprefix={},emph={lstenv}]{new-envb}

\begin{tsremark}[\color{red}Important:]
  The verbatim code will be re-scanned (retokenized) in the process with the current category code régime.
\end{tsremark}

\begin{codedescribe}{ \cvRetokenNewCommand , \cvRetokenNewCommandV , \codeverb_retoken_newcs:N , \codeverb_retoken_newcsV:N  }
\begin{codesyntax}%
\tsmacro{\cvRetokenNewCommand}{cmd}
\tsmacro{\cvRetokenNewCommandV}{cmd}
\tsmacro{\codeverb_retoken_newcs:N}{cmd}
\tsmacro{\codeverb_retoken_newcsV:N}{cmd}
\end{codesyntax}
\tsobj{\cvRetokenNewCommand,\codeverb_retoken_newcs:N} will make \tsobj[marg]{cmd} an alias to \tsobj{\tl_retokenize:n} (from \citepkg{expl3}), while \tsobj{\cvRetokenNewCommandV,\codeverb_retoken_newcsV:N}  will make \tsobj[marg]{cmd} an alias to \tsobj{\tl_retokenize:V}. These commands are just for completeness (with the previous set of commands, which retokenize some verbatim content inside a given environment). Moreover, their main aim is to allow  the code, grabbed as verbatim content, to be (re)used as \LaTeX{} commands/text, the same overall idea from the commands \tsobj{\getstored} (package \citepkg{scontents}) or \tsobj{\tsexec} (package \citepkg{codedescribe}).
\end{codedescribe}

\subsection{Display commands}\label{codeverb:aux:display}

\ExplSyntaxOn
\cvSVerbNew{|*}{*|}
  { \tl_trim_left_spaces:n { #1 } }
\ExplSyntaxOff
\cvSVerbOn

\begin{codedescribe}{\cvHideSpc , \codeverb_hide_spc:n}
\begin{codesyntax}%
\tsmacro{\cvHideSpc}{text}
\tsmacro{\codeverb_hide_spc:n}{text}
\end{codesyntax}
These will just replace every occurrence of a space (character code 32) by \tsobj{\space}. They are the default commands used by \tsobj{\cvSVerb,\codeverb_sverb:Nw} and are needed because (by default) spaces also have their category code changed to other (see \ref{codeverb:commonkeys}), resulting that spaces are visible as in ``|* example of visible spaces*|''.
\end{codedescribe}

\subsection{Short Verbatim}\label{codeverb:sverb}

The following commands aims at defining ``short cuts'' (active characters, as in other verbatim packages) allowing to grab short verbatim content and use it ``right away'', for instance, inside a paragraph. Unlike other verbatim packages, the following commands allow to customize the used characters category code, per command, as well to customize the action taken with the just grabbed verbatim content.

\begin{codedescribe}{\cvSVerbSet,\cvSVerb,\codeverb_sverb_setcs:nn,\codeverb_sverb:Nw}
\begin{codesyntax}%
\tsmacro{\cvSVerbSet}[keys]{code}
\tsmacro{\cvSVerb}{char} \ldots \tsmeta{verbatim content}\ldots\tsobj[marg]{char}
\tsmacro{\codeverb_sverb_setcs:nn}{keys,code}
\tsmacro{\codeverb_sverb:Nw}{char} \ldots \tsmeta{verbatim content}\ldots\tsobj[marg]{char}
\end{codesyntax}
Both, \tsobj{\cvSVerb,\codeverb_sverb:Nw}, are the immediate commands. They will use the character, \tsobj[marg]{char}, following them, as a marker and grab everything between it and its next appearance as verbatim content. \tsobj[marg]{code} (set with \tsobj[code,or]{\csSVerbSet,\codeverb_sverb_setcs:nn}) will receive the verbatim content as \tsfmt[verb]{\#1}. The default \tsobj[marg]{code} is \tsobj{\codeverb_hide_spc:n} \tsfmt[code]{\{\#1\}} ``hidden'' spaces.
\begin{tsremark}
  The category code of \tsobj[marg]{char} itself will be made other, regardless of the actual underlying category code in use whilst grabbing the content, the category code change being local.
\end{tsremark}
With \tsobj{\csSVerbSet,\codeverb_sverb_setcs:nn} one can customize the commands  \tsobj{\cvSVerb,\codeverb_sverb:Nw}.
 \tsobj[marg]{keys} can be any of the common keys (see \ref{codeverb:commonkeys}) and the following:
 
 \begin{describelist*}{key}
   \describe{no endmark}{This will suppress the ending mark, \tsobj{^ ^ J}, which is introduced by default  (following the \tsobj{\tl_retokenize:n} convention, see \citepkg[Reassigning category code]{expl3}) }
 \end{describelist*}
 
 \tsobj[marg]{code} will receive the grabbed content as \tsfmt[verb]{\#1}. For instance, with \tsfmt[code]{\tsobj{\cvSVerbSet}[no endmark]\{\#1\}} the content grabbed with \tsobj{\csSVerb} will be presented ``as is'' with visible spaces. Likewise, \tsfmt[verb]{\tsobj{\cvSVerbSet}\{ \{ \tsobj{\ttfamily} \#1 \} \}} will result that the content grabbed with \tsobj{\csSVerb} will be presented with  the \tsobj{\ttfamily} (note the extra set of braces to localize the effect of the \tsobj{\ttfamily} command).
\end{codedescribe}
\begin{tsremark}  
  One can use \tsobj[code,or]{\hlDisplay,\codehl_display:nn} (see the section \emph{Display commands} from \citepkg{codehighlight}) when defining \tsobj[marg]{code}, for instance: \tsfmt[code]{\tsobj{\cvSVerbSet} \{ \tsobj{\hlDisplay}[inline]\{\#1\} \}}.
\end{tsremark}
\begin{tsremark}[\color{red}Warning:]
  Those display commands (from \citepkg{codehighlight}) expect the content to be terminated with a \tsfmt[verb]{\^{}\^{}J}. Do not use the \tsobj[key]{no endmark} with them, otherwise a quark loop will ensue.
\end{tsremark}

\begin{codedescribe}{\cvSVerbNew,\cvSVerbOn,\cvSVerbOff,\codeverb_sverb_new:nnnn,\codeverb_sverb_on:,\codeverb_sverb_off:}
\begin{codesyntax}%
\tsmacro{\cvSVerbNew}[keys]{start-patt,end-patt,code}
\tsmacro{\cvSVerbOn}{}
\tsmacro{\cvSVerbOff}{}
\tsmacro{\codeverb_sverb_new:nnnn}{keys,start-patt,end-patt,code}
\tsmacro{\codeverb_sverb_on:}{}
\tsmacro{\codeverb_sverb_off:}{}
\end{codesyntax}
\tsobj{\cvSVerbNew,\codeverb_sverb_new:nnnn} allow the setup and definition of custom short commands associated with active chars (characters with category code active, 13). Once defined, and activated in text, everything between \tsobj[marg]{start-patt} and \tsobj[marg]{end-patt} will be grabbed as verbatim content and processed by \tsobj[marg]{code} (which will receive the verbatim content as \tsfmt[verb]{\#1}. These can be called more than once, defining different \tsobj[marg,comma]{star-patt,end-patt}, and associated \tsobj[marg]{code}. \tsobj{\cvSVerbOn,\codeverb_sverb_on:} turn those definitions on, while \tsobj{\cvSVerbOff,\codeverb_sverb_off:} deactivate them. For example:
\end{codedescribe}

\cvSVerbOff
\begin{codestore}[short-verb]
\ExplSyntaxOn
\codeverb_sverb_new:nnnn { no ~ endmark } {|*} {*|}
  { \tl_trim_left_spaces:n { #1 } }
\ExplSyntaxOff

\cvSVerbOn
Example of use: |* \cmd{#1}*|
\cvSVerbOff
\end{codestore}

\tsdemo[codeprefix={},resultprefix={}]{short-verb}

\begin{tsremark}
  \tsobj[marg]{keys} are the same from the \tsobj{cvSVerbSet,\codeverb_sverb_setcs:nn}. The same remarks and warning (regarding the \tsobj[key]{no endmark} key) applies.
\end{tsremark}

\subsubsection{Caveats}\label{codeverb:caveats}
A few caveats to be considered:
\begin{itemize}
  \item \tsobj[marg]{start-patt} is a single (unique) character. This is the simplest case, the  \tsobj[marg]{start-patt} character will be made active and the content between it and \tsobj[marg]{end-patt} will be collected as verbatim content.
  \item \tsobj[marg]{start-patt} is a pattern compose of more than one character. In this case the 1st character of \tsobj[marg]{start-patt} will be made active and look ahead to see if the following tokens match the rest of the \tsobj[marg]{start-patt}, if so, then, the content between \tsobj[marg]{start-patt,end-patt} will be collected as verbatim content.
  \item There are more than one \tsobj[marg]{start-patt} with the same 1st character: This is very similar to the previous case, though, the active code (associated with the 1st character) will test for every possible \tsobj[marg]{start-patt}, starting by the last defined one.
      \begin{tsremark}
        For instance, one may want 3 definitions for \tsobj[marg]{start-patt}: \tsobj{|,||,|||}, in which case the longest one should be defined last.
      \end{tsremark}
      \begin{tsremark}[\color{red}Attention]
        When looking ahead, \tsobj{\peek_regex:NTF} is used. One side effect is that the first character following the \tsobj[marg]{start-patt} will be grabbed with the current category code table (and not the verbatim one, see \citepkg[Peeking ahead at the next token]{expl3}). In particular if the 1st character following \tsobj[marg]{start-patt} is a special one, like \tsverb[verb]{ \ } or \tsfmt[verb]{\#}, this will, probably, lead to low level errors. The work around is to use a single space after the \tsobj[marg]{start-patt}, since this 1st space will be grabbed with the current category code it can be easily removed with a command like \tsobj{\tl_trim_left_spaces:n} (as in the previous example) since it will (default settings) be the single space with category code 10 (space).
      \end{tsremark}
  \item The characters made active by the \tsobj{\cvSVerbNew,\codeverb_sverb_new:nnnn}, while effectively actives (\tsobj{\cvSVerbOn}), will be made other when using a verbatim environment (see \ref{codeverb:newenv}) or using any of the short verbatim commands.
\end{itemize}

\begin{codedescribe}{\cvSVerbUndef,\cvSVerbUndefAll,\codeverb_sverb_undef:n,\codeverb_sverb_undef_all:}
\begin{codesyntax}%
\tsmacro{\cvSVerbUndef}{start-patt}
\tsmacro{\cvSVerbUndefAll}{}
\tsmacro{\codeverb_sverb_undef:n}{start-patt}
\tsmacro{\codeverb_sverb_undef_all:}{}
\end{codesyntax}
\tsobj{\cvSVerbUndef,\codeverb_sverb_undef:n} will undefine the short cut associated with \tsobj[marg]{start-patt}, while \tsobj{\cvSVerbUndefAll,\codeverb_sverb_undef_all:} will undefine all current defined short cuts.
\end{codedescribe}



\section{Examples}

In the following examples, for simplicity, mostly \LaTeXe{} commands are used. Furthermore, they are based on the commands from this package and the ones from \citepkg{codehighlight}, since this package alone has no provision for syntax highlight.

\input{codeverbatim-cmm}

\printbibliography

\end{document} 