0

Using: Win 10, MikTex 2.9.6210, TeXnicCenter 2.02. Compiling with TeXnicCenter's default profile LaTeX => PDF, which uses pdflatex.exe

I seem to have ran into a pickle. I have two files:

  • _Main.tex -> created by editing a template file I downloaded from my faculty's website.
  • TestingCRLF.tex -> created with RightClick > New > Text Document and then edited.

They both contain the code:

\documentclass[11pt,openright,twoside]{report}
\usepackage[utf8]{inputenc}
\usepackage[portuguese,english]{babel}

\title{Testing special characters.}
\author{The very Me}

\begin{document}
    \maketitle
    Testânto caractéres epecíais.

\end{document}

_Main.tex compiles withouth error but TestingCRLF.tex has 3 errors. One for each of the special characters within document. The errors I get are:

! Package inputenc Error: Unicode char ânt (U+E4)
(inputenc)                not set up for use with LaTeX.
See the inputenc package documentation for explanation.
Type H <return> for immediate help.
...

l.10 Testânt
           o caractéres especíais.

The other two errors mention characters (U+E0) and (U+D7).

In the past I've faced the issue of porting a tex file from linux, which uses only Line Feed ('\n') character for ending a line, while Windows used Carriage Return and Line Feed ("\r\n") to end a line. This caused this type of errors when compiling.

To check for that issue I used NotePad++ which allows you to see special hidden characters. I tell you, both files have "\r\n" at the end of each line. So I can only conclude both files are IDENTICAL. But one compiles and the other does not.

10
  • The first file might contain the correct DOM (en.wikipedia.org/wiki/Byte_order_mark) whereas the other does not. Aug 18, 2017 at 11:22
  • 2
    Well if the one gives errors and the other not, they are not identical. Are you sure that the problematic file is encoded in utf8? texniccenter perhaps saved it as ansinew. Aug 18, 2017 at 11:23
  • @ Philipp Imhf Yes, naturally the must be different, but it's mind boggling that latex is sensitive to something like that. I'll check on BOM
    – A. Vieira
    Aug 18, 2017 at 11:26
  • @ Ulrike Fischer - If you mean the usepackage[utf8]{inputenc} line, then yes. They are the same. I copy and pasted with Ctrl+A selection from one file to the other, within TeXnicCenter.
    – A. Vieira
    Aug 18, 2017 at 11:28
  • 3
    No I mean the real encoding of the file. With \usepackage[utf8]{inputenc} you are not setting the encoding, you only inform latex about the file encoding. When you are not saying the truth, you get errors. Aug 18, 2017 at 11:29

1 Answer 1

1

As Ulrike Fischer said in the question's comment, the issue was the Encoding of the file. This means the issue is not related with LaTeX.

As far as I've understood, when editing a file, the character encoding determines what bytes sequences represent which characters. TestingCRLF.tex had ANSI encoding, so when I entered the special characters they were not in UTF-8 encoding.

To fix this, I opened the file in Notepad++, which allows me to change the encoding used to interpret the file. It was ANSI and I changed it to UTF-8. All special characters showed up unencoded (as hex characters). Now in UTF-8 mode, I replaced them all with correct versions.

That's it. So, in the end guess what.. The files were different after all! haha

1
  • 2
    A tip for the future: if you use Encoding/Convert to UTF-8 instead of Encoding/Encode in UTF-8 in Notepad++, special characters are transformed into the correct Unicode equivalents automatically, so you do not have to replace them manually yourself.
    – diabonas
    Aug 18, 2017 at 11:45

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .