GeneralCustomize LaTeX / Split cmd name

LaTeX specific issues not fitting into one of the other forums of this category.
Post Reply
arobase
Posts: 33
Joined: Sat Apr 14, 2012 7:46 pm

Customize LaTeX / Split cmd name

Post by arobase »

Is there an alternative to

Code: Select all

\newcommand*\foomycmd{Soccer.}
\newcommand*\barmycmd{Footbal.}
allowing to invoke,

Code: Select all

\foo\mycmd 
\bar\mycmd
instead of

Code: Select all

\foomycmd % Soccer.
\barmycmd % Football
but with the same effect?

PS: this is a follow up to a previous similar question:
arobase wrote:Is there a way to selectively override \not? For example,
I'd like to define \not\mycmd as

Code: Select all

\text{not}\mycmd

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

Customize LaTeX / Split cmd name

Post by cgnieder »

I'm not sure I understand what you want. Do you want to define a command \foomycmd and then \foo\mycmd shall expand to it?

This is possible but you need to define \foo also.

Code: Select all

\documentclass{article}
\usepackage{expl3}
\newcommand*\foomycmd{football}
\newcommand*\barmycmd{soccer}
\ExplSyntaxOn
\cs_new:Npn \foo #1
  {
    \tl_clear:N \l_tmpa_tl
    \tl_set_rescan:Nnn \l_tmpa_tl { \char_set_catcode_letter:N \\ } { #1 }
    \use:c { foo \tl_tail:N \l_tmpa_tl }
  }
\cs_set:Npn \bar #1
  {
    \tl_clear:N \l_tmpa_tl
    \tl_set_rescan:Nnn \l_tmpa_tl { \char_set_catcode_letter:N \\ } { #1 }
    \use:c { bar \tl_tail:N \l_tmpa_tl }
  }
\ExplSyntaxOff

\begin{document}
\foo\mycmd \\
\bar\mycmd
\end{document}
The command \foo takes \mycmd as an argument, strips the backslash and then calls \foomycmd. \foo\othercmd would call \fooothercmd.

If that isn't what you want maybe you can show the real application you have in mind, an actual usage?

Regards
site moderator & package author
Post Reply