0

This is my setting.

  1. I have a main tex-file:

    % TextTest.tex
    \documentclass[a4paper,11pt]{article}
    \usepackage[utf8]{inputenc} % in order to be able to write åäö.
    \input{name.tex}
    \begin{document}
        Hello ÅÄÖ. \name
    \end{document}
    
  2. I have a windows batch file:

    @echo off
    cls
    
    set /p name= "Name: "
    echo \def\name{%name%}  %% ÅÄÖ >> name.tex
    
    REM generate pdf 
    pdflatex.exe textTest.tex
    
  3. And a generated tex-file name.tex.

However, the above does not work when the name contain e.g. Ä. This is what I have tried: - to set the encoding CHCP 65001 in the batch file. - to set the encoding CHCP 1252 in the batch file. - start the batch file with cmd.exe /U (unicode) and /A (Ansi) - save the tex-files in different encodings.

closed as off-topic by egreg, Zarko, user13907, Claudio Fiandrino, Jesse Oct 30 '15 at 12:39

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "This question does not fall within the scope of TeX, LaTeX or related typesetting systems as defined in the help center." – egreg, Zarko, Community, Claudio Fiandrino, Jesse
If this question can be reworded to fit the rules in the help center, please edit the question.

  • You need to replace utf8 in \usepackage[utf8]{inputenc} % in order to be able to write åäö. by the encoding that you are actually using. [latin1] probably – David Carlisle Oct 30 '15 at 0:07
  • @DavidCarlisle Thanks, this is pretty common see e.g. the answer by Dror in tex.stackexchange.com/questions/57743/… – AD. Oct 30 '15 at 0:18
  • @DavidCarlisle Also, the problem is that windows changes the encoding ( and latin1 did not help by the way). – AD. Oct 30 '15 at 0:20
  • I am not sure what you see in the question/answer that is relevant here That is about encoding in bibliographies? It may be that latin1 is the wrong encoding for your locale (it is hard to tell from the fragments of information given) but the inputenc option must match the encoding used in the textTest file so the letters in that file work, then either you write out name.tex with the same encoding or use {\inputencoding{something}\input{name}} the actual encodings used can be any encoding latex supports utf-8, windows "ansi" iso-8859-1, ...(latin1) .... – David Carlisle Oct 30 '15 at 8:20
3

This is not a latex question. You have a batch file with unknown encoding which you call in cmd-window with unknown settings and which writes a name.tex with unknown encoding. None of this steps are in control of the TeX system, you should better ask on other sites how to create your name.tex in a sensible way.

If you know that your name.tex is always e.g. ansinew/latin1 encoded then you can temporarly change the inputencoding in your tex file when you load it:

\documentclass[a4paper,11pt]{article}
\usepackage[utf8]{inputenc} % in order to be able to write åäö.
\inputencoding{ansinew}
\input{name-ansi.tex}
\inputencoding{utf8}
\begin{document}
    Hello ÅÄÖ. \name
\end{document}

You will then have to expand the Umlauts when defining \name:

\makeatletter
\protected@edef\name{öäüÄÜz}
\makeatother
  • I do not think this help, but it was new to me and can be useful. Also, you are right I it is not a LaTeX problem, hence I accept this as a reference to others. – AD. Oct 30 '15 at 10:07
  • Thanks again, using this I was able to reach my goal. I provided a resolution in an own answer. – AD. Oct 30 '15 at 10:45
0

Things works fine after this change in the batch file, use unicode and change the echo containing the "Name variable" like this

    @echo off
    REM ÅÄÖ
    chcp 65001

    cls
    set /p myName= "Name: "
    set "XX=\def\myName{%myName%}  %% ÅÄÖ"
    setlocal EnableDelayedExpansion 
    (
       echo !XX! 
    )   >> a.tex

    pdflatex.exe textTest.tex
  • I have some doubts. If it works without \protected@edef then your a.tex is probably utf8 and you don't need the \inputencoding{ansinew}. (It doesn't harm either). – Ulrike Fischer Oct 30 '15 at 10:49
  • @UlrikeFischer You are right, it worked fine without the ansi change of the imput. – AD. Oct 30 '15 at 10:54
  • In case that you can't control the encoding of a.tex: You can use the selinput package to find out the encoding of the file and change inputenc if necessary (you must use its commands inside a.tex). – Ulrike Fischer Oct 30 '15 at 10:58

Not the answer you're looking for? Browse other questions tagged or ask your own question.