Skip to content

Commit

Permalink
Minor adjustments
Browse files Browse the repository at this point in the history
  • Loading branch information
PhelypeOleinik committed Jan 11, 2022
1 parent c17f7d9 commit f517b61
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 25 deletions.
2 changes: 1 addition & 1 deletion base/doc/ltnews35.tex
Original file line number Diff line number Diff line change
Expand Up @@ -468,7 +468,7 @@ \subsection{Color in formulas}
as \verb=\left(= but not the corresponding \verb=\right)=.

We have therefore added the command \cs{mathcolor} to the \pkg{color}
and \pkg{xcolor} pachage, which has the same syntax as \cs{textcolor},
and \pkg{xcolor} package, which has the same syntax as \cs{textcolor},
but is specially designed for use in math and handles sub and
superscripts and other aspects correctly and preserves correct
spacing. Thus, the above example can now be written as
Expand Down
46 changes: 22 additions & 24 deletions required/graphics/mathcolor.dtx
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
% unreadable input. For example, to color the summation sign in red
% in the following formula
% \[
% X = \color{red} \sum_{{\color{black} i=1}}^{{\color{black} n}} \color{black} x_i
% X = \color{red} \sum_{{\color{black} i=1}}^{{\color{black} n}} \color{black} x_i
% \]
% A total of four color commands and a number of seemingly
% unnecessary extra braces in the sub and superscript are needed:
Expand Down Expand Up @@ -100,13 +100,13 @@
% \begin{syntax}
% \cs{mathcolor} \oarg{model} \Arg{color-spec} \Arg{math material}
% \end{syntax}
% If has the same arguments as \cs{textcolor} but is intended for
% use in formula.The command does not generate a group and the
% It has the same arguments as \cs{textcolor} but is intended for
% use in formulas. The command does not generate a group and the
% \meta{math material} retains its math atom states and it correctly
% handles sub and superscripts that follow.
% \end{function}
%
% The command can also be use to color a single opening or closing
% The command can also be used to color a single opening or closing
% symbol, e.g., the correct input to our earlier example is
%\begin{verbatim}
% \[ \left\{ \frac{1}{2} \mathcolor{red}{\right\}} \]
Expand All @@ -133,7 +133,7 @@
% \section{The Implementation}
%
% The code is called inside of the \pkg{color} or \pkg{xcolor}
% package, so \texttt{@} is already a letter, but the
% packages, so \texttt{@} is already a letter, but the
% coding here is done in the L3 programming layer, so we need to
% activate that. But first we check if this file was loaded before,
% e.g., when both \pkg{color} and \pkg{xcolor} are in the preamble
Expand Down Expand Up @@ -169,21 +169,21 @@
% (needed if the command is nested or contains some further color
% changes with \cs{color} inside).
% \begin{macrocode}
\seq_gpush:No \g_@@_seq \current@color
\seq_gpush:No \g_@@_seq \current@color
% \end{macrocode}
% The we switch to the new color, but we do not want to reset the
% Then we switch to the new color, but we do not want to reset the
% color after the group (which is done by \cs{color} using
% \cs{aftergroup}\cs{reset@color}). The best solution here would be
% if the color packages would provide a command doing just the
% color switching, but for now we simply undo that part by pushing
% \cs{use_none:n} which gobbles\cs{reset@color} added by \cs{color}
% with \cs{aftergroup}.
% \cs{use_none:n} which gobbles the \cs{reset@color} added by
% \cs{color} with \cs{aftergroup}.
% \begin{macrocode}
\aftergroup \use_none:n
\group_insert_after:N \use_none:n
% \end{macrocode}
% Switching the color is also slightly suboptimal, because
% depending on whether or not we have a \meta{model} argument, we
% have to call \cs{color} with or without optional argument. But
% have to call \cs{color} with or without the optional argument. But
% going low-level here is not an option as we need to support
% different color packages and their internals are not identical.
% \begin{macrocode}
Expand All @@ -199,7 +199,7 @@
% separate command (which in fact needs to be called several times,
% so inlining the code wouldn't be possible.
% \begin{macrocode}
\@@_scan_for_scripts:w
\@@_scan_for_scripts:w
}
% \end{macrocode}
% \end{macro}
Expand Down Expand Up @@ -254,8 +254,8 @@
}
% \end{macrocode}
% Once that is done, we have to get rid of the token we peeked at
% and them restart scanning for sub or superscripts. Given that
% \cs{_@@_scan_for_scripts:w} expands while scanning the simplest
% and then restart scanning for sub or superscripts. Given that
% \cs{@@_scan_for_scripts:w} expands while scanning the simplest
% solution is to add \cs{use_none:n} in front of the peeked at token.
% \begin{macrocode}
{ \@@_scan_for_scripts:w \use_none:n }
Expand All @@ -264,7 +264,7 @@
% replace it by its expansion. The reason we have to do this (and
% not rely on the earlier peeking to expand for us is the fact
% that \texttt{'} is only ``math active'' and that doesn't expand
% under \cs{expand} or \cs{expandafter}.
% under \cs{expanded} or \cs{expandafter}.
% \begin{macrocode}
{ \peek_meaning_remove:NTF '
{ \@@_handle_scripts:Nw ^\c_group_begin_token \prim@s }
Expand Down Expand Up @@ -306,7 +306,7 @@
% the super or subscript. If that reset would happen after it then
% the color \cs{special} would interfere with \TeX{} math spacing.
% \begin{macrocode}
#1 \c_group_begin_token \c_group_begin_token
#1 \c_group_begin_token \c_group_begin_token
% \end{macrocode}
% Now it is time to change the color back to the one on the stack.
% \begin{macrocode}
Expand All @@ -317,27 +317,25 @@
% bit more so that the code executed after the current (inner) group
% looks like this:
%\begin{verbatim}
% \reset@color } \@@_scan_for_scripts:w
% \reset@color } \@@_scan_for_scripts:w
%\end{verbatim}
% The \cs{_@@_scan_for_scripts:w} then retakes control and initiates
% parsing for another sub or superscript.
% \begin{macrocode}
\aftergroup \c_group_end_token
\aftergroup \@@_scan_for_scripts:w
\group_insert_after:N \c_group_end_token
\group_insert_after:N \@@_scan_for_scripts:w
% \end{macrocode}
% Before we give control to \TeX{} to process the sub or
% superscript some final adjustment is necessary: if the input was
% \verb=^{...}= then we have on \verb={= too many, because we
% \verb=^{...}= then we have one \verb={= too many, because we
% already supplied the outer one already. In that case we drop
% it. Otherwise we have an unbraced single token sub or superscript
% which means we are missing a closing \verb=}= at the end and need
% to account for that: this is done in \cs{_@@_handle_unbraced_script:N}.
% \begin{macrocode}
\@@_peek_catcode_ignore_filler_expand:NTF \c_group_begin_token
{
\peek_catcode_remove:NT \c_group_begin_token { }
}
{ \@@_handle_unbraced_script:N }
{ \peek_catcode_remove:NT \c_group_begin_token { } }
{ \@@_handle_unbraced_script:N }
}% \end{macrocode}
% \end{macro}

Expand Down

0 comments on commit f517b61

Please sign in to comment.