0

I am having difficulty constructing the function \celest_separ:n that can handle colour because code level functions do not have optional arguments. Quite unfortunate. How may I get out of such problem ?

What is the advantage of using - versus \textemdash ?

\documentclass[a4paper,12pt]{article}

\usepackage{xcolor}

\ExplSyntaxOn

\definecolor{dblue}{RGB}{0,0,139} \colorlet{celestk}{dblue}

\cs_set_eq:NN \wvAstr \textasteriskcentered \cs_set_eq:NN \wvDash \textemdash

\cs_new_protected:Nn \celest_separ:n { \IfNoValueTF {#2} { \color[#1] } { \color[#1]{#2} }

\begin{center}
  \wvDash \wvDash \wvDash
  \ \wvAstr \, \wvAstr \, \wvAstr
  \ \wvDash \wvDash \wvDash
\end{center}

}

\NewDocumentCommand \separ {O{celestk}o} { \IfNoValueTF {#2} { \celest_separ:n [#1] } { \celest_separ:n [#1] [#2] } }

\ExplSyntaxOff

\begin{document}

\separ

\end{document}

Celest
  • 1
  • 4
    Code level functions do not have optional arguments – Joseph Wright Oct 15 '23 at 21:42
  • Please don't edit to add a new question after your original has been answered. - is a hyphen. \emdash is a rule which I guess originally, at least, was of length 1em. Em and en are printer's measures. In many cases, -- and --- are ligatures. – cfr Oct 15 '23 at 23:47

1 Answers1

2

You can't call

\celest_separ:n [#1]

nor

\celest_separ:n [#1][#2]

You need to absorb the arguments and call internal functions having the correct signature (and definition).

But here I can't see how expl3 can really help.

You seem to want to allow for calls such as

\separ
\separ[red!80]
\separ[rgb][0.1,0.2,0.3]

I don't think that the center environment is good for the job, actually. And don't overthink about expl3.

\documentclass[twocolumn]{article}
\usepackage{xcolor}

\usepackage{lipsum}

\definecolor{dblue}{RGB}{0,0,139} \colorlet{celestk}{dblue}

\NewDocumentCommand{\separ}{O{celestk}o}{% \par\nopagebreak\vspace{0.5\baselineskip} \noindent\makebox[\columnwidth]{% \IfNoValueTF{#2}{\color{#1}}{\color[#1]{#2}}% ---!---!---\ % \textasteriskcentered,\textasteriskcentered,\textasteriskcentered \ ---!---!---% }\par\vspace{0.5\baselineskip} }

\begin{document}

\lipsum[1][1-2]

\separ

\lipsum[1][1-2]

\separ[red!80]

\lipsum[1][1-2]

\separ[rgb][0.4,0.1,0.1]

\lipsum[1][1-2]

\end{document}

Here twocolumn is used just to get a smaller picture.

enter image description here

egreg
  • 1,121,712