TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I would like to define a newcommand that takes one required parameter, but instead of passing it in using {...} as normal, to use a different parameter delineator like the \verb command does (e.g., \mycmd|args|). Trying to do this with a normal \newcommand definition seems to behave strangely.

share|improve this question
I was actually planning to add a macro which allows you to define \verb like macros with this argument separators to either the verbdef package or my own newverbs package, but didn't had the time yet. – Martin Scharrer Jun 30 '11 at 7:13

If you do not want catcode sanitization:

    {\def\domyverb##1#1{ the argument was `##1'}%

and then use it as follows.



share|improve this answer

It mostly depends on what you want to do. If all you need is to use the argument "as is", then


will do. This doesn't check whether \mycmd is defined; if you need the check, then use


If you need this to do "verbatim" things, the definition must be quite more complicated.

share|improve this answer
what about defining a command whose argument can be placed between a pair of arbitrary symbols? How is \verb defined so that \verb|spleen|, \verb+spleen+, etc. work? – Ian Thompson Jun 29 '11 at 23:39

Technically you need an internal macro which has the character at the end of its parameter text, as Aditya already showed in her answer. I as well assume that you only want the argument delimiter but not actual verbatim mode.

If you want to be able to define such macros a lot then you can use a new \newcommand like macro which defines your macro to use such an internal but reusable macro which after reading the argument for you calls a second macro which holds your actual code. See my example below. However, it is limited to macro with a single mandatory argument and also doesn't provide a *-version of itself.


    \expandafter\newcommand\csname \string#1@sp\endcsname[1]%
% ^ This defines both `\foobar` and `\\foobar@sp` where the latter holds the actual code
    \def\@@getseparg##1#2{\csname \string#1@sp\endcsname{##1}}%

\newspcommand{\mycommand}{Got this stuff (#1)}
\newspcommand{\mycom}{Got this stuff (#1)}






\mycom AtestA

share|improve this answer

Your Answer


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

Not the answer you're looking for? Browse other questions tagged or ask your own question.