Is there something like a short version of \emph? What I want is something comparable to \lstShortInline or what the shortvrb provides, just not for the \verb command but for the \emph command instead.

E.g. instead of This is an \emph{important} test., I want to write This is an |important| test. or something similiar.

  • 1
    Do you want to write only the short version, or do you want to have the short version in the source? The former is a matter of the editing environment...
    – DevSolar
    Commented Jan 9, 2012 at 13:37

3 Answers 3

\catcode`\|=13 % make | active
This is an \emph{important} test.
This is an |important| test.

You could just go:


Then you can use |text| as if it were \emph{text}.


All the answers given so far capture an argument, fixing the category codes of the argument tokens forever. That will not work if you want verbatim text mixed with your emphasized text. They are also not \protected, so they won't work in a caption or footnote.

The below uses |+ ...text... +| to delimit emphasized text and works in the cases I just described (as well as meeting your original requirements). I find it better to use a shortcut like "|+" and "+|" because it allows you to insert "|" into your document easily. Otherwise, you need to make up some control sequence representing the original meaning of "|".

%% Justin Bailey
%% [email protected]
%% January, 2012
\newtoks\toinsert %% scratch token register
%% Capture meaning of | and + 
\let\emphbar=| \let\emphplus=+ 
\catcode`\|=\active \catcode`\+=\active
%% See if | is followed by +, indicating we are starting empahsized
%% text. If so, begina new group and run \startEmphC. If not, put |
%% back back into stream.
  \the\toinsert} %%
  \let \math@bgroup \relax%%
  \def \math@egroup {\let \math@bgroup \@@math@bgroup%%
    \let \math@egroup \@@math@egroup}%%
%% See if + is followd by a |, indicating the end of emphasized
%% text. If it is, end the group and gobble the | token. Otherwise,
%% put a + back into the stream. 
%% Associate | and + with startEmphA and stopEmphA. A more
%% robust implementation would put these in a macro so
%% we could turn the definitions of | and + on or off.
\protected\def|{\startEmphA} \protected\def+{\stopEmphA}
%% Basic test
\tracingmacros=2\tracingcommands=2This is an |+important+| test.

%% Use special characters inside emphasize environment. Note
%% that | becomes an em-dash in this font.
This is an |+important (+x|y+)+| test.

%% Test in math mode
This is an $|+important+|$ test.

%% Test in a caption
This is an |+important+| test.
\caption{This is an |+important+| test.}

%% With verbatim text.
This is an |+important \verb=$test$=+|.

%% Nested emphasis
This is an |+important, |+important+|+| test.

The above produces the following document:

Example text.

  • I do actually have a quite short version here: gist.github.com/1584374 It's a little different, but works great for me.
    – Michael
    Commented Jan 11, 2012 at 10:45
  • That works in most cases but its not robust enough to handle verbatim text. For example, This is an /important \verb=$test$=/ test. will fail with an error. Similarly, it will fail in a \caption unless you add \protected before the definition of \def/#1/{...}. Commented Jan 11, 2012 at 15:59

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .