# output generated macro content with newline

I would like to debug a latex macro, but I do not really know how. I got the following MWE which replaces the \\ in a string. I would like to print the value of generated string to check the result. The first output of \show is as expected \textbf {Test123\\Test234}. Now I would like to output the macro \addrGlobal, so that it shows \textbf {Test123\newline Test234}, but it does not work as expected. How can this output be archieved?

\documentclass{article}

\usepackage[a4paper,top=1.27cm,left=1cm,right=1cm,bottom=2cm]{geometry}
\usepackage{ifpdf}
\usepackage[utf8x]{inputenc}
\usepackage{xstring}

\saveexpandmode\expandarg
}%

\relax

\begin{document}

\end{document}

• You should add \usepackage{xstring}, and then I think you want to look at \addr (after invoking \addrGlobal), not \addrGlobal. Jul 20 '13 at 17:29

There are various issues in your code.

1. Why checking whether \address is empty? You have just defined it not to be
2. \makeatletter and \makeatother are missing around the code that uses \@empty
3. The string \empty\\ doesn't appear in \address, so nothing is changed.
4. \addrGlobal will not contain a string, but rather \addr, when \addrGlobal is executed, which isn't in your code. Until you don't issue \addrGlobal, no value will be given to \addr.

Here's a possible fix.

\documentclass{article}

\usepackage{xstring}

\saveexpandmode\expandarg\exploregroups
\restoreexpandmode
}



Note \noexpand\\ in order not to expand the string to be searched and \exploregroups. The \ifx\@empty\address test is useless, because if the string is empty, no substitution will be performed.

Here is the output on the terminal:

> \address=macro:
->\textbf {Test123\\Test234}.