# Macro indent line even on newline

I'm new to creating my own commands (this is my first) and I can't seem to achieve what I set out to do.

My current command looks like this

\documentclass{article}
\usepackage{xparse}
\DeclareDocumentCommand \acro { m m o } {%
\noindent\textbf{#1}\hspace{1em}#2 \IfNoValueF {#3} {\\
\noindent\phantom{#1}\hspace{1em}#3
}\vspace{1em}
}

\begin{document}

\acro{TCP}{Transmission Control Protocol}[This is an explanation that can be pretty long and should be indented the same even if it extends into a new line.]

\end{document}


Which takes two mandatory arguments and one optional. My problem is with the optional argument. The command is meant to be used when creating a simple glossary (I looked at the default glossaries and it did not do what I wanted). The first argument is the acronym (like TCP), the second argument is what the acronym stands for (Transmission Control Protocol), and the third argument is meant as a long explanation of what it actually is and means.

Now, the results I want is this

TCP    Transmission Control Protocol
This is an explanation that can be pretty long and should be indented
the same even if it extends into a new line.


However, I don't seem to be able to control the indentation of the second line. The results I'm getting is like this

TCP    Transmission Control Protocol
This is an explanation that can be pretty long and should be indented
the same even if it extends into a new line.


I've tried parbox, makebox, minipage, and some more I can't remember right now. These have the problem that I have to specify the width of the box, and I don't know how wide the box should be since the acronym (or rather, the word that should be explained) could be either very long or very short.

Any help would be greatly appreciated.

[SOLUTION]

\documentclass{article}
\usepackage{xparse}
\usepackage{enumitem}
\newlist{acrolist}{description}{1}
\setlist[acrolist{font=\bfseries,leftmargin=4em,labelwidth=4em,labelsep=0pt}
\NewDocumentCommand\acro{mmo}{%
\item[#1] #2 \IfValueT{#3}{\\
#3
}
\vspace{0.5em}
}
\begin{document}
\begin{acrolist}
\acro{TCP}{Transmission Control Protocol}[This is an explanation that can be pretty long and should be indented the same even if it extends into a new line.]
\acro{PHY}{Physical}[The physical (MAC) address of a device]
\end{acrolist}

\end{document}


Thanks to Manuel for all the suggestions and providing the answer.

• Possibly Christian has already solved your problem, but if not (and in general) it's always better to post a full minimal working example of the code that you have so that people can see what packages etc you need to get your code to work (but don't add code that is not needed). Having an example file with \documentclass....\begin{document}...\end{document} to start with makes it much easier for people to help you - and hence much more likely that they will! – Andrew Sep 19 '14 at 9:38
• May be a tabulate environment would be better? A list? a tabular? – Manuel Sep 19 '14 at 9:45
• @ChristianHupfer Added a MWE and added a % to the line. Sadly it did not fix the problem. – Chewtoy Sep 19 '14 at 9:50
• @Chewtoy: I misunderstood your question anyway... I will delete my comment. I suggest to use \phantom{\textbf{#1}} since there is slight shift to the right due to bold font then, but this does not solve the issue with the indentation – user31729 Sep 19 '14 at 9:55
• In addition, the suggestion by Manuel seems to provide a better way to typeset this – user31729 Sep 19 '14 at 9:57

You could also use lists (this is the way I would do it). Load enumitem and

\begin{description}[font=\normalfont,leftmargin=5em,labelwidth=5em,labelsep=0pt]
\item[TCP] Transmission Control Protocol \\
This is an explanation that can be pretty long and should be
indented the same even if it extends into a new line.
\end{description}


It would be great to have an interface? Then

\usepackage{enumitem}
\newlist{acrolist}{description}{1}
\setlist[acrolist]{font=\bfseries,leftmargin=4em,labelwidth=4em,labelsep=0pt}
\NewDocumentCommand\acro{mmo}{\item[#1] #2 \IfValueT{#3}{\\ #3}}


and then use

\begin{acrolist}
\acro{one}{some text}[explanation]
\acro{two}{some other text}[explanation]
\acro{TCP}{Transmission Control Protocol}[This is an explanation that can be
pretty long and should be indented the same even if it extends into
a new line.]
\end{acrolist}


Or

\begin{tabular}{lp{8cm}}
TCP & Transmission Control Protocol \\
& This is an explanation that can be pretty long and should be indented
the same even if it extends into a new line.
\end{tabular}


or, loading tabularx package and using

\begin{tabularx}{\textwidth}{lX}
TCP & Transmission Control Protocol \\
& This is an explanation that can be pretty long and should be indented the
same even if it extends into a new line.
\end{tabularx}


does solve your problem (I think). Of course, you can define your \acro at wish to work in this way.

• Thanks! I used the tabularx and got what I needed. In addition to what you have done I threw in a \IfNoValueF in the tabular, \textbf{#1} & #2 \IfNoValueF{#3}{\\ & #3} which adds the description-part at the right place if it is defined. – Chewtoy Sep 19 '14 at 10:38
• @Chewtoy I would definetly use the list, which has many advantages (like breaking across pages) and is much more flexible. – Manuel Sep 19 '14 at 11:42
• @Chewtoy use a list not tabularx here (I wrote tabularx but I wouldn't use it for this) – David Carlisle Sep 19 '14 at 12:49
• @Manuel Both work great, but I see the advantage of the list and will go on using that. It makes more sense to use it. It also indents the description text equally, which is a bonus. – Chewtoy Sep 19 '14 at 13:15
• @Chewtoy The gratest thing is that you can configure it with enumitem package in many, many ways. – Manuel Sep 19 '14 at 14:23

As variant as a description list. The leftmargin is an optional argument (4em by default):

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{xparse}

\usepackage{enumitem}

\newlist{acroglossary}{description}{1}
\setlist[acroglossary]{leftmargin = 4em, labelwidth =0pt, labelsep=!}%

\DeclareDocumentCommand \acro { m m o } {%
\item[\rlap{#1}]\textit{#2} \IfNoValueF {#3} {\smallskip\\#3 }
}%

\begin{document}

\begin{acroglossary}
\item[\rlap{TCP}] \textit{Transmission Control Protocol}\\[1ex]
This is an explanation that can be pretty long and should be indented the same even if it extends into a new line.
\end{acroglossary}

\begin{acroglossary}[leftmargin =6em]
\acro{FTGFOP}{Finest Tippy Golden Flowery Orange Pekoe}%
[Highest quality whole leaf grade for tea. \\ Also, as a joke, ‘Far Too Good For Ordinary People’.]
\end{acroglossary}

\end{document}