Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle ^^Ms inside formatted "lines" #46

Merged
merged 1 commit into from
May 13, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 33 additions & 10 deletions mmacells.sty
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,9 @@
\tl_new:N \l__mmacells_math_replacements_tl
\tl_new:N \l__mmacells_math_replacements_bold_tl

\cs_new:Npn \__mmacells_fv_formatline:n #1 { #1 }
\cs_generate_variant:Nn \__mmacells_fv_formatline:n { V }

\cs_new_nopar:Npn \__mmacells_prepare_verbatimenv: { }
\cs_new_nopar:Npn \__mmacells_begin_verbatimenv: { }
\cs_new_nopar:Npn \__mmacells_end_verbatimenv: { }
Expand Down Expand Up @@ -663,18 +666,38 @@
\cs_new_protected:Npn \__mmacells_wrap_fv_formatline:n #1
{
\cs_set_eq:NN \__mmacells_fv_formatline:n \FancyVerbFormatLine
\cs_set:Npn \FancyVerbFormatLine ##1
{ #1 { \__mmacells_fv_formatline:n { ##1 } } }
% listings permanently adds code to \FV@VerbatimBegin and
% \FV@VerbatimEnd command (and corresponding for LVerbatim and BVerbatim)
% This code is executed if \FancyVerbFormatLine
% is equivalent to \lstFV@FancyVerbFormatLine. So if we're using
% listings-fancyverb interface we must make sure that those two commands
% are the same.
\bool_if:NT \l_mmacells_uselistings_bool
{ \cs_set_eq:NN \lstFV@FancyVerbFormatLine \FancyVerbFormatLine }

\bool_if:NTF \l_mmacells_uselistings_bool
{
% ^^M characters present in argument passed to \FancyVerbFormatLine,
% set by listings-fancyverb interface, lead to infinite compilation.
% So we'll just get rid of them.
\cs_set:Npn \FancyVerbFormatLine ##1
{
\tl_set:Nn \l_tmpa_tl { ##1 }
\__mmacells_replace_carriage_return:N \l_tmpa_tl
#1 { \__mmacells_fv_formatline:V \l_tmpa_tl }
}

% listings permanently adds code to \FV@VerbatimBegin and
% \FV@VerbatimEnd command (and corresponding for LVerbatim and
% BVerbatim). This code is executed if \FancyVerbFormatLine
% is equivalent to \lstFV@FancyVerbFormatLine. So if we're using
% listings-fancyverb interface we must make sure that those two commands
% are the same.
\cs_set_eq:NN \lstFV@FancyVerbFormatLine \FancyVerbFormatLine
}
{
\cs_set:Npn \FancyVerbFormatLine ##1
{ #1 { \__mmacells_fv_formatline:n { ##1 } } }
}
}

\char_set_catcode_active:n { `\^^M }
\cs_new_protected:Npn \__mmacells_replace_carriage_return:N #1
{ \regex_replace_all:nnN { ^^M } { \c{empty} } #1 }
\char_set_catcode_end_line:n { `\^^M }

\cs_new_protected:Npn \__mmacells_clist_put_right:Nncn #1#2#3#4
{
\tl_set:Nn \l_tmpa_tl { #2 }
Expand Down