GeneralUsing verbatim in my macro...

LaTeX specific issues not fitting into one of the other forums of this category.
Post Reply
MrTree
Posts: 3
Joined: Tue Aug 04, 2009 7:04 pm

Using verbatim in my macro...

Post by MrTree »

I have a cunning plan for the document I'm working on but I'm having trouble implementing it...

I use several macros to define various constants etc for example

Code: Select all

\newcommand{\xscale}{\tilde{x}}
Now, I want to put together a table where I define all of these.
For example;

Code: Select all

\begin{tabular}{l l l}
Variable&Meaning&\LaTeX Command\\
$\xscale$&Scaled Coorinate&\verb$\xscale$\\
\endPtabular}
The verbatim text at the end is only for my own reference and I won't want it displayed in the final version...

What I would like to do is put together a command whereby I can add a new variable to the list by;

Code: Select all

\newvar{\name}{Definition}
This will create the line

Code: Select all

$\name$&Definition&\verb$\name$\\
When it comes to the final version I just switch the command out for one that doesn't print the \verb section...
I've learnt that \verb and verbatim cannot be used in this manner but am unable to find a suitable work-around.

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

phi
Posts: 577
Joined: Tue Oct 21, 2008 8:10 pm

Using verbatim in my macro...

Post by phi »

this should work:

Code: Select all

\newcommand*{\newvar}[2]{%
  $#1$&%
  #2&%
  \texttt{\string#1}\\%
}
MrTree
Posts: 3
Joined: Tue Aug 04, 2009 7:04 pm

Re: Using verbatim in my macro...

Post by MrTree »

You, sir, are a star.

Works like a charm; thank you very much.
MrTree
Posts: 3
Joined: Tue Aug 04, 2009 7:04 pm

Using verbatim in my macro...

Post by MrTree »

The only caviat is that I can't do

Code: Select all

\newvar{\xscale,\yscale}{Scaled Cartesian coordinates.}
But I can work around that for now, unless the fix is simple.

Cheers
phi
Posts: 577
Joined: Tue Oct 21, 2008 8:10 pm

Re: Using verbatim in my macro...

Post by phi »

You can use \detokenize{#1} instead of \string#1, but then there will be additional spaces after each control word.
Post Reply