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:
Code: Select all
Code, edit and compile here:
\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}