I would like to write something like this inline:

This is paragraph element <p>

I'm using verbatim for writing the HTML element part, but cannot form everything in one line. I get something like this:

This is paragraph element

After looking through some answers on this forum I found that I should use \verb.
Can anyone help me correct my code:

This is paragraph element
  • 3
    Welcome to TeX.SE. What is wrong with \verb!<p>!? There are also some packages that provide inline display for various programming languages , see listings or minted, for example – user31729 Aug 22 '17 at 16:56
  • 3
    Did you try "This is paragraph element \verb+<p>+."? Note the use of the delimiter + to start and terminate the inline verbatim material. The delimiter can be any symbol that doesn't occur in the verbatim material. – Mico Aug 22 '17 at 17:00
  • @ChristianHupfer this works perfectly for me. I thought that using verbatim was the only way I could achieve this. Thanks. – denisr Aug 22 '17 at 17:01
  • this should provide additional useful information: When should one use \verb and when \texttt – barbara beeton Aug 22 '17 at 19:03

To typeset inline verbatim-like material, it's best to use the macros \verb and \Verb; the latter is provided by the fancyvrb package. If that package is loaded and the instruction \VerbatimFootnotes is executed, one can even have \Verb instructions in footnotes. (One can't do this with \verb.)

Note that \verb and \Verb don't use matching pairs of curly braces ({ and }) to delimit their arguments; instead, use any non-letter symbol (except "*") that doesn't occur in the verbatim material itself. (Even \verb{<p>{ is legal, though I'll be the first one to state that it looks positively weird.)

If you prefer to render the inline verbatim material using the "regular" text font instead of a monospaced font, consider loading the listings package and writing "Paragraph element \lstinline{<p>}".

enter image description here

\usepackage{fancyvrb} % for "\Verb" macro
\VerbatimFootnotes    % enable use of \Verb in footnotes

\setlength\textheight{3cm} % just for this example

Paragraph element \verb+<p>+
Paragraph element \verb_</p>_
Paragraph element \Verb^<p>^
Paragraph element \Verb#</p>#
Some text.\footnote{In a footnote: \Verb"<p>",  \Verb:</p>:.}

Code golfing with xparse and its v - argument specifier, meaning verbatim or just use \verb!<p>! for example.



Some HTML \ShowInline{<p>}

End tag for HTML\ShowInline{</p>}

enter image description here

  • Is there some advantage to using this approach to, say, loading the listings package and typing Some HTML \lstinline{<p>}? – Mico Aug 22 '17 at 17:23
  • @Mico: None, actually. That's why I called it code golfing ;-) – user31729 Aug 22 '17 at 20:31

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.