# How can I define a new function in LaTeX (easy way to add \verb!word!)

How can I define a new function in LaTeX? I want something like this:

%Current:
\verb!word!

I want something like this to do the same:
\vb_word


Or an easy way to add this function. I have more than 100 variables that I should add this function to it. It is hard to add two ! for every word.

• do you need verbatim? (there are no special characters in word?) \vrb_word would have no easily defined terminator, verbatim package makes it easy to define eg |word| with just two | but verbatim has lots of restrictions, why not \texttt{word} ? – David Carlisle Feb 8 '17 at 23:21
• @DavidCarlisle Thank you for your comment. But your suggestions have {} or || in left and right sides. I'm searching a way to only paste a defined function in the beginning of my words. – user2991243 Feb 8 '17 at 23:24
• but how do you define a word? are greek letters in words, or accented letters, do words have a space to end the font change, or might it be a . or , or ... It is just massively more complicated and under specified what you want in that case. – David Carlisle Feb 8 '17 at 23:31
• @DavidCarlisle. Those are simple words. These isn't any space in middle, beginning or end of these words. These isn't any 'a' or 'or'. Just some words like 'X', 'x', 'format', 'file', – user2991243 Feb 8 '17 at 23:55
• simple words doesn't discount Greek or Cyrillic or accented letters in an international forum but I posted something that works for ascii – David Carlisle Feb 9 '17 at 0:04

I wouldn't do this but....

\documentclass{article}

\def\vb{\bgroup\ttfamily\xvb}
\def\xvb{\futurelet\tmp\xxvb}
\def\xxvb{%
\ifcat a\noexpand\tmp\tmp\expandafter\xxxvb
\else\egroup\fi}
\def\xxxvb#1{\xvb}

\begin{document}

one \vb two  two \vb three, four (\vb five) six seven

\end{document}