2

How italic the first letter of a word in \verb|| structure? Suppose that I want have italic (or underscore) for G in \verb|Good|.

  • 6
    Do you really need \verb? – egreg Apr 30 '17 at 8:37
  • If it is possible, I need that. I used this structure in more than 100 words in my work, so It is hard to change it. – user2991243 Apr 30 '17 at 8:40
  • 4
    why have you got Good in \verb ???? the only use of verb is to disable LaTeX formatting and present the characters as a verbatim string. There is no formatting in Good to disable so \verb is not appropriate, and then you ask to add formatting which seems a strange choice for \verb – David Carlisle Apr 30 '17 at 8:57
5

I'm not sure you're using the right tool for the job and I'd be wary of redefining \verb.

\documentclass{article}
\usepackage{xparse}

\ExplSyntaxOn
\NewDocumentCommand\iverb{v}
 {
  \xyz_verbit_split:n { #1 }
 }
\cs_new_protected:Nn \xyz_verbit_split:n
 {
  \texttt
   {
    \underline { \tl_head:n { #1 } }
    \tl_tail:n { #1 }
   }
 }
\ExplSyntaxOff

\begin{document}

\verb|Good|

\iverb|Good|

\end{document}

enter image description here

4

Use the abilities of your editor to replace the string \verb by \myverb. There are also tools that can do it for a bunch of files (in case you have too many files to open them all by hand).

Then add the definition

\def\myverb|#1#2|{\texttt{\underline{#1}#2}}

to your preamble. It assumes that there is at least one token between the vertical bars.

enter image description here

\documentclass{article}
\newcommand\myverb{}% Make sure \myverb is undefined
\def\myverb|#1#2|{\texttt{\underline{#1}#2}}
\begin{document}
\myverb|Good|
\myverb|Goo|
\myverb|Go|
\myverb|G|
%\myverb|| % This gives an error
\end{document}
  • 3
    @CarLaTeX Probably the whole "problem" can be solved by the editor alone. Replacements with regular expressions can take you quite far. – gernot Apr 30 '17 at 9:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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