General ⇒ How to amalgamate commands?
How to amalgamate commands?
let's say one defines a simple command \boldletter{X} which prints the bold version of its argument (X in this case).
How can one define a shorthand for this command, e.g. \bletX = \boldletter{X} such that it would work for all letters in the alphabet A...Z and a...z - so for instance: \bletG = \boldletter{G}.
Of course, this is easy to do by defining new commands \bletA, \bletB, ... one by one.
But can this
\blet + "*" = \boldletter{"*"}
be done more elegantly for all "*"?
Thanks in advance for your help.
NEW: TikZ book now 40% off at Amazon.com for a short time.
And: Currently, Packt sells ebooks for $4.99 each if you buy 5 of their over 1000 ebooks. If you choose only a single one, $9.99. How about combining 3 LaTeX books with Python, gnuplot, mathplotlib, Matlab, ChatGPT or other AI books? Epub and PDF. Bundle (3 books, add more for higher discount): https://packt.link/MDH5p
Re: How to amalgamate commands?
B.A.
Re: How to amalgamate commands?
That's true for all commands, and that's the way I've been doing it until now.
The reason for wanting to actually join them is that I find it easier (e.g. for debugging) to read the code by having composite commands.
-
- Posts: 105
- Joined: Fri Nov 30, 2007 11:32 pm
Re: How to amalgamate commands?
\newcommand{\blet}[1]{\boldletter{#1}}
Once you define the above command you can use \blet{X} to get \boldletter{X} where X is any alphabet.
Re: How to amalgamate commands?
I know that, of course.
The only reason for having chosen the bold example was to serve as an illustration of the problem.
To make things clearer: I do know how to write text and math in boldface, as well as defining/redefining commands.
As explained in the first post, what I'm really looking for is a way to create composite commands in general, whereby \fooXX is interpreted as \foo{XX} for whatever XX. Do I need to use TeX primitives for that, or can it be done in LaTeX?
- localghost
- Site Moderator
- Posts: 9202
- Joined: Fri Feb 02, 2007 12:06 pm
How to amalgamate commands?
gaius wrote: […] As explained in the first post, what I'm really looking for is a way to create composite commands in general, whereby \fooXX is interpreted as \foo{XX} for whatever XX. Do I need to use TeX primitives for that, or can it be done in LaTeX?
In which way would that make typesetting easier? Or isn't that the intention of your question?
Best regards
Thorsten
Board Rules
Avoidable Mistakes
¹ System: TeX Live 2025 (vanilla), TeXworks 0.6.10
How to amalgamate commands?
In which way would that make typesetting easier? Or isn't that the intention of your question?
This question came up when I was trying to define an upright version for all symbols in the basic Math Letters font (I collected and patched together a set of roman shaped symbols from different fonts, covering the Math letters set).
Instead of having a style file with lots of definitions like
\DeclareMathSymbol{\alphaup}{\mathord}{lettersup}{11}
one for each upright symbol \xxxxxup.
It would be nice if one could make it so that the "up" suffix (or prefix) would make the rest of the command Roman shaped.
At the time I ended up doing it symbol by symbol as exemplified above, but am still curious if/how it can be done in LaTeX.
It's not so much that it would be extremely useful or facilitate typesetting terribly, but the solution would probably be instructive for other situations.
regards
-
- Posts: 105
- Joined: Fri Nov 30, 2007 11:32 pm
Re: How to amalgamate commands?
How to amalgamate commands?
Code: Select all
\documentclass[]{article}\makeatletter\newcounter{ii} \setcounter{ii}{1}\@whilenum{\value{ii}<27}\do{%\def\temp{\Alph{ii}}\expandafter\edef\csname foo\temp\endcsname{This is letter~\fbox{\temp}}\stepcounter{ii}}\makeatother\begin{document}\fooA. \fooB. \fooC\ldots\fooZ. \par\bfseries \fooA. \fooB. \fooC\ldots\fooZ.\end{document}
Code: Select all
\newcommand{\foo}[1]{This is letter~\fbox{#1}}
Edited to add this:
In the preamble, one can replace the \makeatletter--\makeatother block by the following lines:
Code: Select all
\makeatletter\@for\temp:={A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z}\do{%\expandafter\edef\csname foo\temp\endcsname{This is letter~\fbox{\temp}}}\makeatother
How to amalgamate commands?
In the meantime I found two packages where they seem to do exactly this: one is txfonts (package for Times fonts) and the other is wrisym (package for Mathematica files).
In the case of wrisym they have commands like \dsX defined as \mathbb{X}, and similarly for the Fraktur and \mathcal alphabets. In the case \mathbb they first define \dsX individually for each character, and later redefine \mathbb{X} to act as \dsX for general alphanumeric X.
The definition of \mathbb is
Code: Select all
\DeclareRobustCommand*{\mathbb}[1]{%\gdef\F@ntPrefix{ds}\@EachCharacter #1\@EndEachCharacter}
Code: Select all
\long\def\DoLongFutureLet #1#2#3#4{%\def\@FutureLetDecide{%#1#2\@FutureLetToken\def\@FutureLetNext{#3}%\else\def\@FutureLetNext{#4}%\fi\@FutureLetNext}%\futurelet\@FutureLetToken\@FutureLetDecide}\def\DoFutureLet #1#2#3#4{\DoLongFutureLet{#1}{#2}{#3}{#4}}\def\EachCharacter #1\EndEachCharackter{%\@EachCharacter #1\@EndEachCharacter}\def\@EachCharacter{%\DoFutureLet{\ifx}{\@EndEachCharacter}%{\@EachCharacterDone}%{\@PickUpTheCharacter}%}
Code: Select all
\long\def\DoLongFutureLet #1#2#3#4{%\def\@FutureLetDecide{#1#2\@FutureLetToken\def\@FutureLetNext{#3}\else\def\@FutureLetNext{#4}\fi\@FutureLetNext}\futurelet\@FutureLetToken\@FutureLetDecide}\def\DoFutureLet #1#2#3#4{\DoLongFutureLet{#1}{#2}{#3}{#4}}\def\@EachCharacter{\DoFutureLet{\ifx}{\@EndEachCharacter}%{\@EachCharacterDone}{\@PickUpTheCharacter}}\def\m@keCharacter#1{\csname\F@ntPrefix#1\endcsname}\def\@PickUpTheCharacter#1{\m@keCharacter{#1}\@EachCharacter}\def\@EachCharacterDone \@EndEachCharacter{}\DeclareRobustCommand*{\varmathbb}[1]{\gdef\F@ntPrefix{m@thbbch@r}%\@EachCharacter #1\@EndEachCharacter}