\sc
is a legacy font command based on \scshape
that is used in the book
class for compatibility with LaTeX2.09. You could use another name such as \Sc
but beware such shorthands make it harder to use standard section features such as the *
form for the unnumbered variant, and the optional argument for the table of contents version of the header.
Also as you are adding a lot of white space (in a standard context not in \ExplSyntaxOn
) these space tokens can affect the output, consider
\documentclass[10pt]{book}
\NewDocumentCommand{\ch}{om}{
\IfNoValueTF{#1}{
\chapter{#2}
}{
\chapter{#2}\label{ch:#1}
}
}
\NewDocumentCommand{\Sc}{om}{
\IfNoValueTF{#1}{
\section{#2}
}{
\section{#2}\label{sc:#1}
}
}
\begin{document}
\ch{AAA}
aaaaa aaaaaaaaaaaaa aaaaaaaaaaaaaaa a
aaaaa aaaaaaaaa aaaaaaaaaaaaaaa. a
\Sc{BBB}
aaaaa aaaaaaaaaaaaa aaaaaaaaaaaaaaa a
aaaaa aaaaaaaaa aaaaaaaaaaaaaaa. a {} {}
\section{BBB}
aaaaa aaaaaaaaaaaaa aaaaaaaaaaaaaaa a
aaaaa aaaaaaaaa aaaaaaaaaaaaaaa. a
\section{BBB}
\end{document}
Which produces
Where the \Sc
version is producing the heading as if the previous paragraph ended with additional space as shown in section 2 as opposed to the intended layout produced by \section
in section 3.
If you use
\documentclass{article}
\usepackage[english,bulgarian]{babel}
\usepackage[utf8]{inputenc}
\usepackage[T2A]{fontenc}
\begin{document}
Здравей
\ExplSyntaxOn
\tl_set:Nx \l_tmpa_tl {Здравей}
\show\l_tmpa_tl
\tl_map_inline:Nn \l_tmpa_tl { #1 ~ }
\ExplSyntaxOff
\end{document}
You will see the current release defines
> \l_tmpa_tl=macro:
->Здравей.
older releases
> \l_tmpa_tl=macro:
->\T2A\CYRZ \T2A\cyrd \T2A\cyrr \T2A\cyra \T2A\cyrv \T2A\cyre \T2A\cyrishrt .
Usually the new version is to be preferred, what is the actual use case here, there is probably a way to achieve it?
A quick fix would be this which keeps each two-byte UTF-8 pair in a group:
> \l_tmpa_tl=macro:
->{З}{д}{р}{а}{в}{е}{й}.
\documentclass{article}
\usepackage[english,bulgarian]{babel}
\usepackage[utf8]{inputenc}
\usepackage[T2A]{fontenc}
\begin{document}
Здравей
\ExplSyntaxOn
\def\uviii#1#2{\ifx\relax#1\else{#1#2}\expandafter\uviii\fi}
\tl_set:Nx \l_tmpa_tl {\uviii Здравей\relax\relax}
%\show\l_tmpa_tl
\tl_map_inline:Nn \l_tmpa_tl { #1 ~ }
\ExplSyntaxOff
\end{document}
\documentclass{article}
\usepackage[english,bulgarian]{babel}
\usepackage[utf8]{inputenc}
\usepackage[T2A]{fontenc}
\begin{document}
Здравей
\ExplSyntaxOn
\def\uviii#1{\ifx\relax#1\else
\ifnum\expandafter`\string#1<128~
\expandafter\expandafter\expandafter\uviiia\else
\expandafter\expandafter\expandafter\uviiib
\fi
\fi
#1}
\def\uviiia#1{#1\uviii}
\def\uviiib#1#2{{#1#2}\uviii}
\tl_set:Nx \l_tmpa_tl {\uviii Здравейabc\relax}
%\show\l_tmpa_tl
\tl_map_inline:Nn \l_tmpa_tl { #1 ~ }
\ExplSyntaxOff
\end{document}
Best Answer
You can organize parsing arguments like this:
The code above uses optional braced argument
g
which is not recommended in thexparse
documentation.IfNoValueF
prints the next group of arguments if it finds them and adds\next@cites
to search for more. If there's no braced argument ahead, it stops. For the sake of simplicity, the current code silently ignores bracketed arguments if they are present but there's no the braced one.