Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I have problem with adding text into LaTeX document. I have LaTeX document about LaTeX and I need to insert some code snippets. I need to add "\usepackage{musixtex}" as a text, which should be displayed as a text. Do you know how?

share|improve this question

migrated from stackoverflow.com Mar 23 '12 at 15:12

This question came from our site for professional and enthusiast programmers.

1  
Welcome to TeX.sx! Your question was migrated here from Stack Overflow. Please register on this site, too, and make sure that both accounts are associated with each other, otherwise you won't be able to comment on or accept answers or edit your question. –  Werner Apr 3 '12 at 2:59
add comment

2 Answers

enter image description here

\documentclass{article}
\usepackage{xcolor}
\usepackage{listings}
\lstset
{
    language=[LaTeX]TeX,
    breaklines=true,
    basicstyle=\tt\scriptsize,
    keywordstyle=\color{blue},
    identifierstyle=\color{magenta},
}

\begin{document}
This is inline \lstinline!\TeX! and the following is displayed 

\begin{lstlisting}
\documentclass{article}
\begin{document}
Hello World
\end{document}
\end{lstlisting}

\end{document}

If you need source code and rendered output side by side, use showexpl (no need to load listings because showexpl loads listings automatically) as follows.

enter image description here

\documentclass{article}
\usepackage{tikz}
\usepackage{showexpl}
\lstset
{
    language=[LaTeX]TeX,
    breaklines=true,
    basicstyle=\tt\scriptsize,
    keywordstyle=\color{blue},
    identifierstyle=\color{magenta},
}

\begin{document}
This is inline \lstinline!\TeX! and the following is displayed 

\begin{lstlisting}
\documentclass{article}
\begin{document}
Hello World
\end{document}
\end{lstlisting}


\begin{LTXexample}[pos=b,preset=\centering,width=0.5\linewidth]
\begin{tikzpicture}
    \draw[fill=red] (0,0) circle (1);
\end{tikzpicture}
\end{LTXexample}

\end{document}
share|improve this answer
add comment
up vote 6 down vote accepted

You can use \verb like this:

\documentclass{letter}
\begin{document}
Example: \verb!\usepackage{musixtex}!
\end{document}

Edits by Speravir and Sam Whited:

There is also a starred version, which makes the spaces visible:

\documentclass{article}
\begin{document}
\verb|\LaTeX vs. \LaTeX\ or \LaTeX{} \dots|

\verb*|\LaTeX vs. \LaTeX\ or \LaTeX{} \dots|

\LaTeX vs. \LaTeX\ or \LaTeX{} \dots
\end{document}

Multiline

If you end up with more than a short, one line, phrase you might also try the verbatim (built in) or Verbatim (an improved version located in the fancyvrb package) environments.

eg.

\begin{verbatim}
  Some LaTeX code here
  Which can be multiple lines
  \usepackage{musixtex}
  \begin{music}\nostartrule
  \instrumentnumber{1}

  ...
\end{verbatim}
share|improve this answer
    
It doesn't work :-( it show me only "musixtex" –  Waypoint Mar 22 '12 at 9:49
    
modified the example to be testable. It works for me... Try compiling the above as-is. –  mitchnull Mar 22 '12 at 10:09
    
it works in this sample, but I am using it in beamer presentation and here it is not working –  Waypoint Mar 22 '12 at 10:28
1  
Ah, it is solved now, I have forgotten to make frame "fragile", thanks –  Waypoint Mar 22 '12 at 10:31
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.