4

I want to make a command that I say for example:

\newcommand{abbre}{...}

\def\abbre{Modular Response}

And \abbre should display MR.

Thanks

5
  • 2
    It is not clear to me what you really want. After \newcommand must be a macro, eg \newcommand\abbre{...}. In your case it makes no difference in using \def or not.
    – user2478
    Commented May 20, 2014 at 6:53
  • That's true, I don't need the \def command. But what I really want to know is how do I define the command \abbre for obtaining the initials of a phrase.
    – user51962
    Commented May 20, 2014 at 7:15
  • 1
    Look at the glossaries package, especially the \newacronym{MR}{mr}{Module Response} command and then use \gls{MR} in your text.
    – mforbes
    Commented May 20, 2014 at 7:51
  • 1
    There are dedicated packages for abbreviations. Besides the already mentioned glossaries there's also acronym and acro. I suggest you take a look at them.
    – cgnieder
    Commented May 20, 2014 at 10:25
  • Please add the content of your comment in your question, as the question itself is not clear enough. Commented May 20, 2014 at 11:51

3 Answers 3

2

Modified from my answer at Typeset just the first letter in a group to: 1) remove the space between letters; 2) present only the letters of the capitalized words of the phrase, and to 3) create a macro of the abbreviated name to recall the original phrase (see the example of \MRT in my MWE.).

This allows you to work in both directions. For example, I can speak of Modular Response of Tissue" and abbreviate it as \abbre{Modular Response of Tissue} to give MRT. On the other hand, having done the abbreviation once, I can formulate my document with MRT for the acronym and \MRT to get the phrase Modular Response of Tissue.

The most recently defined acronym may be re-accessed with \theabbre. If you don't want the acronym to print out with the invocation of \abbre{}, pass it the optional argument [q] for "quiet" as in \abbre[q]{Modular Response of Tissue}. You can later access it the acronym with \theabbre, if it is the most recently defined acronym.

Abbreviations are not limited in their length.

\documentclass[]{article}
\newcommand\abbre[2][v]{\def\theabbre{}%
  \expandafter\justfirstCAPS#2 \relax\relax\if q#1\else\theabbre\fi%
  \expandafter\def\csname\theabbre\endcsname{#2}}
\makeatletter
\def\justfirstCAPS#1#2 #3\relax{\ifnum`#1>`@\ifnum`#1<`[%
  \protected@edef\theabbre{\theabbre#1}\fi\fi%
  \if\relax#3\else\justfirstCAPS#3\relax\fi}
\makeatother
\textwidth 5.5in
\def\x{Laughing My A\$\$ Off Rolling On The Floor, Biting The Carpet, Scaring 
The Cat, Nearly Dying By Falling Out Of The Window In Front Of A Guy Who 
Looks Like Bill Gates, Who Then Horrified, Runs Out On The Street And Is 
Accidentally Killed By A Yellow Bulldozer}
\parskip 1em
\begin{document}
This prints \abbre{Modular Response of Tissue} as the abbreviation to Modular 
  Response of Tissue, which can thereafter be recalled with the
shorthand \verb|\MRT| as \MRT.  The most recently defined acronym is \theabbre.

Abbreviations are not limited to two, three, or even nine characters:

One of the longest internet acronyms, according to 
\texttt{www.urbandictionary.com}, is\\
\abbre{\x},\\ which stands for ``\x''.
\end{document}

enter image description here

1
  • @Arturo You are welcome. One of the ways you might want to use it (not mentioned in the answer is \abbre[q]{Computer Aided Tomography}\CAT{} (\theabbre). If you would prefer that \abbre just prints out the actual words (not the acronym), saving the acronym in \theabbre, I could make that change. Commented May 20, 2014 at 12:31
3
\documentclass{article}

\makeatletter
\newcommand*\firstL[1]{\@car #1\@empty\@nil}
\newcommand*\firstLetter[1]{\expandafter\@firstLetter#1 \@nil}
\def\@firstLetter#1 #2\@nil{%
  \firstL{#1}\ifx\\#2\\\else\@ReturnAfterFi{\@firstLetter#2\@nil}\fi}
\long\def\@ReturnAfterFi#1\fi{\fi#1}
\makeatother
\newcommand\abbre{Modular Response}
\begin{document}

\abbre~is the long version and \firstLetter{\abbre} the
short one. And \firstLetter{Modular Response} also. And
\firstLetter{This Is Also Returned With The first Letter}

\end{document}

enter image description here

2
  • Thank you. And what could I do if I want the \shortAbbr command to give me the capital leters in a phrase? For example with the phrase Modular Response of Tissues it should give MRT.
    – user51962
    Commented May 20, 2014 at 9:30
  • see my edited answer.
    – user2478
    Commented May 20, 2014 at 11:22
2

I can offer a more short macro (only two lines of the \abbre macro):

\def\abbre#1{\expandafter\abbreA#1 \relax/ }
\def\abbreA#1#2 {\ifx#1\relax \else\ifnum\uccode`#1=`#1#1\fi\expandafter\abbreA\fi}

\def\macro{Modular and Response}

\abbre{Something Text is Here} or \abbre\macro.

Result is: STH or MR. The macro \abbre is expandable thus it can be edefed:

\edef\abbremacro{\abbre\marco} % Now the meaning of \abbremacro is MR. 

You must log in to answer this question.