Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

The goal: This is for an exam. I have a program which should be compiled and executed by batch script. Another batch script calls that first batch an writes the output to a .txt file. Then the contents of that .txt file should be included in a document which is produced with Latex.

The problem: Latex produces an character encoding error during the build. Error message:

Package inputenc Error: Keyboard character used is undefined in inputencoding 'utf8'

The generated file looks like this:

Ausgabe generiert am 11.05.2013 um  8:28:11,39
************** Skript zur Kompilierung der Source-Dateien **********************
Kompilieren der Sourcedateien zu "Program.exe"

Microsoft (R) Visual C# 2008 Compiler Version 3.5.30729.6400
, für Microsoft (R) .NET Framework Version 3.5
Copyright (C) Microsoft Corporation. Alle Rechte vorbehalten.

Erfolgreiche Kompiliereung

In line 6 the german umlaut 'ü' (ue) is the problem. Also there is a problem with the # character later.

LaTeX config:

\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}

Code is included like this:

\lstinputlisting[style=tests]{log/log.txt}

The strange thing, I have special characters like Umlaut (äöü) etc. all over the place in my document and that works fine. If I copy a file from my project and rename it to log.txt it works fine. But if I create a new file on the file system (or generate it with the script) and write some special characters to it, it crashes.

More details: I am using Windows 8, Texnicenter and MikTex. The listing style looks like this:

\lstdefinestyle{tests}{
    language=,
    basicstyle=\ttfamily,       
    numbers=none, 
    breaklines=true,             
    frame=none,                     
    breakatwhitespace=false,            
    backgroundcolor=\color{hellgelb},  
    literate=
    {Ö}{{\"O}}1
    {Ä}{{\"A}}1
    {Ü}{{\"U}}1
    {ß}{{\ss}}2
    {ü}{{\"u}}1
    {ä}{{\"a}}1
    {ö}{{\"o}}1
}

What I have tried: Googled my a.. off. I tried to use all possible codepages in the batch file like: 1250, 1252, 850, 65000, 65001, 1200, 1201, 12000, 12001. Nothing works.

I'd appreciate your help very much!

Edit Batch that writes the output:

@echo off
SET log=%~dp0\latex_doku\log\log.txt
SET skripts=%~dp0..\..\cd\batch
SET folder=%~dp0\latex_doku\log\
SET result=%~dp0..\..\cd\unit_tests\results\TestResult.xml

ECHO Generieren der Ausgabedatei...
ECHO Ausgabe generiert am %DATE% um %time%>%log%

REM kompilieren
CALL %skripts%\compile.bat>>%log%

REM Systemtests ohne Eingabedateien ausfuehren
CALL %skripts%\run_tests.bat>>%log%

REM ausfuehren
CALL %skripts%\run.bat>>%log%

REM TestResults
IF NOT EXIST %result% GOTO EXT
xcopy "%result%" "%folder%" /y

:EXT
pause

When I dont specify a codepage the result looks like this:

enter image description here

When I specify cp 1252 for example it looks like this:

enter image description here

It is strange that the character is shown correctly in the editor...

share|improve this question
    
Can you show the batch, that writes the output (here or at pastebin)? –  Endoro May 11 '13 at 7:08
    
Yes sure, I forgot to show it. I tried different codepages with chcp command. –  user1993065 May 11 '13 at 7:26
    
Does this batch write the input for Latex? Or the other called batches? –  Endoro May 11 '13 at 7:31
    
It calls this one: goo.gl/gmwnk. so it creates the log.txt file which is the input for latex but the contents are produced partly by this batch, the compile batch, the program.exe and the other batches... –  user1993065 May 11 '13 at 7:36
    
I have no clue. I would recommend, if you get no answer here, ask in a forum where the guys are more familiar with those special character issues (eg. chip.de or administrator.de. –  Endoro May 11 '13 at 8:41
show 2 more comments

migrated from stackoverflow.com May 12 '13 at 0:07

This question came from our site for professional and enthusiast programmers.

1 Answer

Do you know package listingsutf8?

It allows you to print a source in UTF8 (changed to Latin1) with the code:

% in preamble:
\usepackage{listingsutf8}[2011/11/10]

% to print the utf8 code:
\lstinputlisting[%
  style=tests,%
  inputencoding=utf8/latin1,%
]{log/log.txt} 

Because you gave no MWE I can't test if it is working for you. Please do it by your own.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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