## LaTeX forum ⇒ Text Formatting ⇒ Write accented characters to file using \write

Information and discussion about LaTeX's general text formatting features (e.g. bold, italic, enumerations, ...)
giampierosalvi
Posts: 1
Joined: Wed Sep 06, 2017 4:28 pm

### Write accented characters to file using \write

Hi,
I am trying to output some information to an auxiliary file using \write and among other things I have authors names that often include accented letters. If I use the string explicitly the accented letters are expanded into TeX commands, but I can solve this by using \unexpanded. However, if the string is contained in a variable, and I use \unexpanded, I get the name of the variable instead of its content. The command \unexpanded works fine again if the variable is a command parameter, for example #1.

I don't have an understanding of expansion that is clear enough to sort this out, so any help is appreciated. All I want to do is to write the content of a variable holding a string with accented letters to the text file.

Thank you!

Here is a minimal example:

\documentclass{article}\usepackage[utf8]{inputenc} \newwrite\file\immediate\openout\file=\jobname_extra.txt\AtEndDocument{\closeout\file} \begin{document}\immediate\write\file{Test 1}                   % works fine\immediate\write\file{José}                     % expands into TeX code\immediate\write\file{\unexpanded{José}}          % works fine\def\mystring{José}\immediate\write\file{\mystring}                  % expands into TeX code\immediate\write\file{\unexpanded{\mystring}}    % outputs \mystring literally\newcommand{\writeaccented}[1]{  \immediate\write\file{\unexpanded{#1}}}\writeaccented{José}                            % works fine\end{document}

Johannes_B
Site Moderator
Posts: 3583
Joined: Thu Nov 01, 2012 4:08 pm
The smart way: Calm down and take a deep breath, read posts and provided links attentively, try to understand and ask if necessary.