Fonts & Character SetsSpecial Characters in Name of Input File

Information and discussion about fonts and character sets (e.g. how to use language specific characters)
Faergen
Posts: 7
Joined: Wed Mar 27, 2013 8:21 am

Special Characters in Name of Input File

Post by Faergen »

I cannot get LaTeX to recognize special danish characters in input files, even though it recognizes them completely fine when I write them in the .tex file. I use the Danish characters 'æ' 'ø' and 'å'.

There is no error if I just remove the \input{mytextwithæøå.txt} from my document, so there is nothing wrong with my preamble. I just don't know what I need to do, to have the characters recognized.


Addendum:
I forgot to mention, that if i just change the special characters in the input file, the problem also goes away. Just to nail it down completely, that the issue is the recognition of special characters in input files (both in text and in file name).

Thank you
-Faergen

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org
LaTeX Beginner's Guide LaTeX Cookbook LaTeX TikZ graphics TikZによるLaTeXグラフィックス
Frits
Posts: 169
Joined: Wed Feb 02, 2011 6:02 pm

Special Characters in Name of Input File

Post by Frits »

Your problem is broader than LaTeX. LaTeX is not able to encode such special characters within commands like \input or \includegraphics (although the grffile package can sometimes be of help for the latter).

Personally I would just stick to the conventional characters [a-z][A-Z][0-9], - and _ in file names.
howtoTeX.com - Your LaTeX resource site (Tips, Tricks, Templates and more!)
Follow howtoTeX on twitter
User avatar
localghost
Site Moderator
Posts: 9201
Joined: Fri Feb 02, 2007 12:06 pm

Special Characters in Name of Input File

Post by localghost »

Frits wrote:[…] Personally I would just stick to the conventional characters [a-z][A-Z][0-9], - and _ in filenames.
Underscores (_) should be avoided, too.


Best regards and welcome to the board
Thorsten
How to make a "Minimal Example"
Board Rules
Avoidable Mistakes[/size]

¹ System: openSUSE 42.2 (Linux 4.4.52), TeX Live 2016 (vanilla), TeXworks 0.6.1
Faergen
Posts: 7
Joined: Wed Mar 27, 2013 8:21 am

Re: Special Characters in Name of Input File

Post by Faergen »

Alright, I can easily avoid using those characters in filenames, but what about content? Because it also complains when the text itself contains æ ø å even though it is completely fine with them, if I write them in the .tex document itself.

and thank you for the welcome :0)
-Faergen
User avatar
localghost
Site Moderator
Posts: 9201
Joined: Fri Feb 02, 2007 12:06 pm

Special Characters in Name of Input File

Post by localghost »

Provide a self-contained and minimal example that shows the problem clearly. Special characters in other languages than English usually need a package like selinput (from the oberdiek bundle) or inputenc.
How to make a "Minimal Example"
Board Rules
Avoidable Mistakes[/size]

¹ System: openSUSE 42.2 (Linux 4.4.52), TeX Live 2016 (vanilla), TeXworks 0.6.1
Faergen
Posts: 7
Joined: Wed Mar 27, 2013 8:21 am

Special Characters in Name of Input File

Post by Faergen »

Alright:

Code: Select all

\documentclass[10pt,a4paper]{article}
\usepackage[danish]{babel}
\renewcommand{\danishhyphenmins}{22}
\usepackage{lmodern}
\usepackage[T1]{fontenc}
\usepackage[utf8x]{inputenc}
\usepackage[danish=quotes]{csquotes}

\begin{document}

æ ø å
\input{text.txt}

\end{document}
If you make a txt file, and copy the three letters æ ø å inside, you'll find that you get an error. But if you remove the \input{text.txt} and just run it, it writes the three letters just fine within the document.

The problem is; How do I get latex to recognize special characters within txt files. Because it clearly knows them within the .tex file itself.

Regards
-Faergen
User avatar
localghost
Site Moderator
Posts: 9201
Joined: Fri Feb 02, 2007 12:06 pm

Re: Special Characters in Name of Input File

Post by localghost »

Make sure that the master file and the input file have the same file encoding (UTF-8 here). If that doesn't help, attach both generated files to your next post in order to make the problem comprehensible for others.
How to make a "Minimal Example"
Board Rules
Avoidable Mistakes[/size]

¹ System: openSUSE 42.2 (Linux 4.4.52), TeX Live 2016 (vanilla), TeXworks 0.6.1
Faergen
Posts: 7
Joined: Wed Mar 27, 2013 8:21 am

Special Characters in Name of Input File

Post by Faergen »

I have no clue how to make a .txt file any other encoding than what it is. I don't know what you mean by "both generated files". I have two files I have created: The minimal.tex that contain the following code:

Code: Select all

    \documentclass[10pt,a4paper]{article}
    \usepackage[danish]{babel}
    \renewcommand{\danishhyphenmins}{22}
    \usepackage{lmodern}
    \usepackage[T1]{fontenc}
    \usepackage[utf8x]{inputenc}
    \usepackage[danish=quotes]{csquotes}

    \begin{document}

    æ ø å
    \input{text.txt}

    \end{document}
and the text.txt within which I have just written the three characters æ ø å.

I just want latex to recognize those three characters inside the txt file, just as it can recognize them when typed directly into the minimal.tex file.

I have attached both the .tex and .txt file.
Attachments
text.txt
(5 Bytes) Downloaded 608 times
minimal.tex
(287 Bytes) Downloaded 598 times
User avatar
localghost
Site Moderator
Posts: 9201
Joined: Fri Feb 02, 2007 12:06 pm

Special Characters in Name of Input File

Post by localghost »

Faergen wrote:I have no clue how to make a .txt file any other encoding than what it is. […]
Why do you create a *.txt file at all? With \input you can input *.tex files as usual and create them with your LaTeX editor.
Faergen wrote:[…] I don't know what you mean by "both generated files". I have two files I have created: […]
In fact I meant the two files that you attached.

The problem is that your file "input.txt" is encoded with ISO-8859-15, which is wrong here. You can recode it by opening it with your editor, then go to "Save as" and set the encoding to UTF-8 in the dialog window. Remember to save it as a *.tex file. Then you can simply use \input{input} in your master file.
How to make a "Minimal Example"
Board Rules
Avoidable Mistakes[/size]

¹ System: openSUSE 42.2 (Linux 4.4.52), TeX Live 2016 (vanilla), TeXworks 0.6.1
Faergen
Posts: 7
Joined: Wed Mar 27, 2013 8:21 am

Re: Special Characters in Name of Input File

Post by Faergen »

I want to use .txt files, because it is easier for me to have a template in a folder, with my database of citations and just put some .txt files in there That way I can do the bare minimum of coding in the template for the particular assignment, so it's easy to clean up for the next one.

Having more .tex files just means more code, not less. I'm looking for a way only to include text and the little code I need to typeset and cite in each section, in each of the .txt files. Not to rewrite all the packages again.

And there is no dialogue box when I save as. Neither for txt files nor for .tex files. I have put utf-8 to be the standard encoder in the preferences in TexWorks but that is the closest, outside of packages, I come to have any control over it, and it doesn't seem to have any influence whatsoever on the files.

Isn't there a package that helps Latex read input files like it reads it's own text? I mean, it seems very strange, that the Same characters it knows how to read within the program, it can't simply read when it is in a .txt file, even though it should apply the same encoding to that file, as it applies to itself.

EDIT
Oh, and the problem is actually the same. If I make a .tex file, it doesn't recognize the characters either.
Last edited by Faergen on Wed Mar 27, 2013 11:12 pm, edited 2 times in total.
Post Reply