Text FormattingI cannot input accented letter from external file.

Information and discussion about LaTeX's general text formatting features (e.g. bold, italic, enumerations, ...)
Post Reply
fpires
Posts: 15
Joined: Wed Dec 23, 2015 7:10 pm

I cannot input accented letter from external file.

Post by fpires »

Hello, everyone!

Well, I have a simple question. If I write the code below, everything works good.

Code: Select all

\documentclass[a4paper,12pt]{report}
\usepackage[utf8]{inputenc}
\begin{document}
Hello, world.
\newwrite\temp
\immediate\openout\temp=Test
\immediate\write\temp{This is a test.}
\immediate\closeout\temp
\input{Test}
\end{document}
However, I need to write letters with accent in my text, and because of that I use

Code: Select all

\usepackage[utf8]{inputenc}
in the preamble. If the accented letter is in the text itself, it is printed normally, but if it is written in the external file, I cannot run the code. For example, if I write

Code: Select all

\documentclass[a4paper,12pt]{report}
\usepackage[utf8]{inputenc}
\begin{document}
Hello, world.
\newwrite\temp
\immediate\openout\temp=Test
\immediate\write\temp{This is a test. á}
\immediate\closeout\temp
\input{Test}
\end{document}
I get the following error message:

! Undefined control sequence.
l.1 This is a test. \unhbox \voidb
@x \bgroup \let \unhbox \voidb@x \setbox \...

The external Test file looks like this:

Code: Select all

This is a test. \unhbox \voidb@x \bgroup \let \unhbox \voidb@x \setbox \@tempboxa \hbox {a\global \mathchardef \accent@spacefactor \spacefactor }\accent 19 a\egroup \spacefactor \accent@spacefactor 
Would any of you have a solution for this problem? I suppose it is simple, but I am not exactly very used to Latex.

Thank you in advance!

Felipe

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org
LaTeX Beginner's Guide LaTeX Cookbook LaTeX TikZ graphics TikZによるLaTeXグラフィックス
User avatar
Stefan Kottwitz
Site Admin
Posts: 10290
Joined: Mon Mar 10, 2008 9:44 pm

I cannot input accented letter from external file.

Post by Stefan Kottwitz »

Hi Felipe!

A simple way is, to not expand the letter to code:

Code: Select all

\immediate\write\temp{\unexpanded{This is a test. á}}
Or protect it, so it won't get expanded as well:

Code: Select all

\makeatletter
\immediate\protected@write\temp{This is a test. á}
\makeatother
Stefan
LaTeX.org admin
fpires
Posts: 15
Joined: Wed Dec 23, 2015 7:10 pm

Re: I cannot input accented letter from external file.

Post by fpires »

Hello, Stefan,

thank you very much! It worked perfectly!
Post Reply