Tell me more ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I've searched for but not found an answer to this.

I am using two layers of \newcommands to create symbols inline with text, using \includegraphics. (It's for music symbols.)

At present, I have this as the generic command:

\newcommand*{\inlineImage}[2]{\raisebox{#1pt}{\fbox{\includegraphics{__#2__}}}}

And then many commands of the form:

\newcommand*{\Sixteenth}{\inlineImage{-1.5}{Sixteenth}}

This works, but it is cumbersome to type the same text twice during set up. Of course, I could employ a command with arguments in my document body, but I don't want to do that. Is there a way to replace the specific commands with something of the form:

\newcommand*{\Sixteenth}{\inlineImage{-1.5}{<thecommandname>}}
share|improve this question
1  
Try something like \def\newnote#1{\edef\csname #1\endcsname\inlineImage{-1.5}{#1}} – Eddy_Em Aug 13 at 19:01
1  
Welcome to TeX.sx! Your post was migrated here from Stack Overflow. Please register on this site, too, and make sure that both accounts are associated with each other (by using the same OpenID), otherwise you won't be able to comment on or accept answers or edit your question. – Werner yesterday
@Eddy_Em Why not make that an answer. – Andrew Swann 13 hours ago

migrated from stackoverflow.com yesterday

This question came from our site for professional and enthusiast programmers.

1 Answer

To make command from text use \csname .. \endcsname macros. For example, if you will write

\def\newnote#1{\expandafter\def\csname #1\endcsname{\inlineImage{-1.5}{#1}}}

then commands like

\newnote{Fourth}
\newnote{Eighth}
\newnote{Sixteenth}

will define notes \Fourth, \Eighth and \Sixteenth, which will insert appropriate images.

share|improve this answer
1  
That needs to be \expandafter\edef\csname ...\endcsname. Otherwise you're redefining the macro \csname... – cgnieder 12 hours ago
1  
I'd also use \def instead of \edef and add the missing braces – cgnieder 12 hours ago
Yes, thanks. Fix – Eddy_Em 11 hours ago

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.