Generalexpl3: arguments wrapped in brackets

LaTeX specific issues not fitting into one of the other forums of this category.
Post Reply
erwann
Posts: 75
Joined: Thu Aug 25, 2016 2:24 am

expl3: arguments wrapped in brackets

Post by erwann »

Hi, is there a way to modify the code below such that

Code: Select all

\foo c
returns 'EMPTY' rather than (c)?

PS: When internal and external macros share similar names (here, foo), what conventions are recommended? (In TeX, @ for the internal...)

Code: Select all

\documentclass{article}
\usepackage{xparse}

\ExplSyntaxOn

\cs_new:Nn \Foo:n { \tl_if_empty:nTF{#1}{EMPTY}{(#1)} }

\NewDocumentCommand { \foo } { m }
{
	\Foo:n{#1}
}

\ExplSyntaxOff

\begin{document}

\foo{c} % (c)

\foo{} % EMPTY

\foo c % (c)

\end{document}
x_86 / Linux Mint 18.3 / texlive 2015.20160320-1ubuntu0.1 / TeXworks 0.5r1361 (Debian)

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

cgnieder
Site Moderator
Posts: 2000
Joined: Sat Apr 16, 2011 7:27 pm

expl3: arguments wrapped in brackets

Post by cgnieder »

Here is a suggestion:

Code: Select all

\documentclass{article}
\usepackage{xparse}
     
\ExplSyntaxOn
     
\cs_new_protected:Nn \ewann_foo:n
  { \tl_if_empty:nTF {#1} {EMPTY} {(#1)} }
     
\NewDocumentCommand \foo {g}
  {
    \IfNoValueTF {#1}
      { \ewann_foo:n {} }
      { \ewann_foo:n {#1} }
  }

\ExplSyntaxOff
     
\begin{document}
     
\foo{c} % (c)

\foo{} % EMPTY
     
\foo c % (c)

\end{document}
site moderator & package author
Post Reply