## 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:

1. \documentclass{article}
2. \usepackage[utf8]{inputenc}
3.
4. \newwrite\file
5. \immediate\openout\file=\jobname_extra.txt
6. \AtEndDocument{\closeout\file}
7.
8. \begin{document}
9. \immediate\write\file{Test 1} % works fine
10. \immediate\write\file{José} % expands into TeX code
11. \immediate\write\file{\unexpanded{José}} % works fine
12. \def\mystring{José}
13. \immediate\write\file{\mystring} % expands into TeX code
14. \immediate\write\file{\unexpanded{\mystring}} % outputs \mystring literally
15. \newcommand{\writeaccented}[1]{
16. \immediate\write\file{\unexpanded{#1}}
17. }
18. \writeaccented{José} % works fine
19. \end{document}

Johannes_B
Site Moderator
Posts: 3644
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.