2

I am creating a simple tutorial file to take a seminar. My problem is: I want to get the output as "\textbf is used for making the font bold". How can I get that? Likewise, i want to make this for some other keywords too, \textit and all the others...

If the problem is a % , i can use \% as well

But here, i want \textbf to be print in the pdf.

3 Answers 3

5

You can use command \verb## and environment verbatim like this:

\documentclass{article}

\begin{document}

\verb#\textbf# is used to make the font bold, for example i could write:

\verb#\textbf{This Is Boldface!}#, resulting in \textbf{This Is Boldface!}

When you have multiple lines of code, it is best to use environment \verb#verbatim#:

\begin{verbatim}
\begin{verbatim}
\textbf{} %is used to make the font bold
\textbf{} %is used to make the font bold
\textbf{} %is used to make the font bold
\textbf{} %is used to make the font bold
\end{verbatim}\vskip-10pt
\verb#\end{verbatim}#

\end{document}

When you have multiple lines of code, it is best to use environment verbatim.

3

It will be incomplete if listings is not mentioned for such a purpose.

\documentclass{article}
\usepackage{listings}
\lstset{ %
  language={[LaTeX]TeX},
    basicstyle=\small\ttfamily,
    }
\begin{document}
  \lstinline{\textbf} is used to make the font \textbf{bold}

  \lstinline{\textit} is used to make the font \textit{italic}
\end{document}

enter image description here

2
\documentclass{article}
%\usepackage[T1]{fontenc}

\begin{document}

Hi! you can do:

\texttt{\textbackslash textbf} is used to make the font \textbf{bold}

\texttt{\textbackslash textit} is used to make the font \textit{italic}

or:

\textbackslash\texttt{textbf} is used to make the font \textbf{bold}

\textbackslash\texttt{textit} is used to make the font \textit{italic}

\end{document}

Hi! Take a look at this above: the simpler the better? I had this solution in my mind and, writing it down, I could appreciate it works with no packages (provided T1 encoding is used, thanks to @egreg).

Addendum: if you plan to use it several times, then why not making a newcommand:

\documentclass{article}
%\usepackage[utf8]{inputenc}\usepackage[T1]{fontenc}

\newcommand{\mact}[1]{\texttt{\textbackslash #1}}

\begin{document}

Hi again! you can just do:

\mact{textbf} is used to make the font \textbf{bold}

\mact{textit} is used to make the font \textit{italic}

\end{document}

Hope it helps!

2
  • 1
    Much better, of course, provided T1 encoding is used.
    – egreg
    Nov 12, 2014 at 19:07
  • 1
    @MattAllegro "it works with no packages". That is our swagger.
    – RicoRally
    Nov 14, 2014 at 19:55

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.