Text Formattingverbatim | Problem with Input Encoding

Information and discussion about LaTeX's general text formatting features (e.g. bold, italic, enumerations, ...)
Post Reply
rmonascal
Posts: 2
Joined: Sun Apr 29, 2012 6:33 pm

verbatim | Problem with Input Encoding

Post by rmonascal »

Hello everyone,

I'm using verbatim to print directly a piece of code from input to output. I understand that the verbatim environment should process directly anything passed to it. But it seems it depends on the encoding used, both for input and output.

The problem arises with the symbol "¬" (logical negation), which makes LaTeX think a '$' is missing and tries to insert it, even though I'm in the verbatim environment. And it does print it, but the rest of the line looses it's typewriter font.

Later on, I discovered that not specifying an input encoding the problem disappeared (I was using \usepackage[latin1]{inputenc}, because the rest of the document is in Spanish). The compilation process ended successfully, but instead of printing de "¬" symbol, it printed a "ň" symbol (an "n" with a reversed circumflex accent). I think this is quite a strange behaviour for verbatim.

Here is what I think could be a minimum working example for the problem:

Code: Select all

\documentclass[spanish]{report}
\usepackage[T1]{fontenc}
\usepackage[latin1]{inputenc} % Comment this line to see the other scenario.
\usepackage{babel}

\begin{document}
  \begin{verbatim}
    I'm typewrited.
    ¬ <- This is the problem. (And I am not typewrited).
    I'm typewrited too.
  \end{verbatim}
\end{document}
Do you guys know what could be going on? I'm using MikTex 2.9.

Thank you all in advance,
Ricardo Monascal
Last edited by localghost on Sun Apr 29, 2012 7:08 pm, edited 1 time in total.

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

Juanjo
Posts: 657
Joined: Sat Jan 27, 2007 12:46 am

verbatim | Problem with Input Encoding

Post by Juanjo »

It seems that there is no ¬ symbol in typewriter font. LaTeX tries to replace it with other symbol, either by an accented n or by the \neg symbol, which should be written in math mode. As a workaround, you may use the fanvyvrb package. For an occasional use of the ¬ symbol, you can replace it by \ensuremath{\neg}. If you often use it, it is worthy to define a command. Both alternatives are shown in the following example:

Code: Select all

\documentclass[spanish]{report}
\usepackage[T1]{fontenc}
\usepackage[latin1]{inputenc}
\usepackage{babel}

\usepackage{fancyvrb}
\fvset{commandchars=\\\{\}}

\newcommand*{\NO}{\ensuremath{\neg}}

\begin{document}
 
\begin{Verbatim}
   I'm typewrited.
   \ensuremath{\neg} <- This is no longer the problem
   I'm typewrited too.
\end{Verbatim}

\begin{Verbatim}
   I'm typewrited.
   \NO <- This is no longer the problem
   I'm typewrited too.
\end{Verbatim}

\end{document}
If you need to include the characters \, { and } in the verbatim text, then change the settings in the \fvset command and change also commands inside Verbatim accordingly.

P.S. Since you write in Spanish, you may be interested in joining the es-tex list for Spanish TeX users.
The CTAN lion is an artwork by Duane Bibby. Courtesy of www.ctan.org.
rmonascal
Posts: 2
Joined: Sun Apr 29, 2012 6:33 pm

Re: verbatim | Problem with Input Encoding

Post by rmonascal »

Thank you so very much Juanjo! I was getting a bit frustrated by this issue and your solution worked just perfectly. :D
Post Reply