1

I have a text file with similar lines as this one:

enter image description here

I am using:

\usepackage[utf8x]{inputenc}%
\usepackage{textalpha} % <--- Greek letters in text

But still the output looks like this:

enter image description here

How can I make it work?

Here is the code

\documentclass{article}%
\usepackage[utf8]{inputenc}%
\usepackage{textalpha} % <--- Greek letters in text

\begin{document}%
\begingroup %I am using that because I am actually importing a text file 
\noindent
\obeyline
\input{aᵢ₁x₁ + aᵢ₂x₂ + ... + aₙ₁xₙ = bᵢ}%
\endgroup%

\end{document}

BTW: If I open the text file with Word Pad, it looks like this:

enter image description here

Here is the complete text file: https://ufile.io/rxs84

14
  • Can you please add code for the strange line instead of a picture?
    – egreg
    Commented Oct 7, 2018 at 13:29
  • @egreg I added the code
    – james
    Commented Oct 7, 2018 at 13:38
  • What's the problem with inputting $a_{i1}x_1+a_{i2}x_2+\dots+a_{in}x_n=b_i$? Instead of all those wrong letters?
    – egreg
    Commented Oct 7, 2018 at 13:58
  • 1
    @james On a site that primarily does advertising and requires downloading? Not at all.
    – egreg
    Commented Oct 7, 2018 at 14:32
  • 2
    I'm confused. Your title talks about Greek letters but your example text contains only the Roman letters a, b and x. Commented Oct 7, 2018 at 18:14

2 Answers 2

2

You can use a Unicode engine, together with package catchfile which will allow to input the text document in a mode disabling TeX special characters such as $ or \.

I have configured it to allow text reflowing.

But spaces will be handled by TeX as usual, so the input can use U+00A0 (no-break space) to force some respected spacing.

Paragraphs separated by empty lines in input file will be simulated by a \parskip setting, so multiple empty lines are fused into one in this approach.

This answer evolved from @DavidPurton's one (sorry for some misleading comments I made there, now deleted).

\documentclass[french, a4paper]{article}
\usepackage{geometry}
\usepackage{babel}
\usepackage{fontspec}
\setmainfont{DejaVu Serif}
\setsansfont{DejaVu Sans}
\setmonofont{DejaVu Sans Mono}

\newfontfamily\DejaVuSansWithNoTeXLigatures{DejaVu Sans}[]% disable TeX ligatures

\usepackage{catchfile}

\makeatletter
\newcommand\mysanitize{%
  \let\do\@makeother
  \dospecials
  \catcode32=10\relax
}

\newcommand\myVerbInput[1]{\par
    \CatchFileDef{\my@file}{#1}{\mysanitize}%
    \begingroup
     % put here the font commands you want
     % we shall use for this demo:
     \DejaVuSansWithNoTeXLigatures
     \frenchspacing
     \parindent\z@
     \parskip\baselineskip
     \my@file\par
    \endgroup}

\makeatother

% For demonstration only
\usepackage{filecontents}
\begin{filecontents*}{\jobname.txt}
Bon est une solution de quoi ? C'est une solution de l'équation aᵢ₁x₁
+ aᵢ₂x₂ + ... + aₙ₁xₙ = bᵢ. Bon est une solution de quoi ? C'est une
solution de l'équation aᵢ₁x₁ + aᵢ₂x₂ + ... + aₙ₁xₙ = bᵢ. Bon est une
solution de quoi ? C'est une solution de l'équation aᵢ₁x₁ + aᵢ₂x₂ +
... + aₙ₁xₙ = bᵢ. Bon est une solution de quoi ? C'est une solution de
l'équation aᵢ₁x₁ + aᵢ₂x₂ + ... + aₙ₁xₙ = bᵢ.

Voici un nouveau paragraphe, une vraie logorrhée mathématique et on va
tester au passage si l'ensemble {$&~#$&~#$&~#éàçè§è} donne autant de
problèmes que l'ensemble vide. Voici un nouveau paragraphe, une vraie
logorrhée mathématique et on va tester au passage si l'ensemble
{$&~#$&~#$&~#éàçè§è} donne autant de problèmes que l'ensemble vide.
Voici un nouveau paragraphe, une vraie logorrhée mathématique et on va
tester au passage si l'ensemble {$&~#$&~#$&~#éàçè§è} donne autant de
problèmes que l'ensemble vide.

Ok alors essayons quelques trucs en Unicode:

             ασδφγηηξκμ

             ⇒☛«»❮❯‱❝❞€☂☃.

             Ligature: -- ? non, tout va bien n'est-ce pas?

             (fin de la démonstration de l'Hypothèse du continu)
\end{filecontents*}

\begin{document}
Text before (serif)
\myVerbInput{\jobname.txt}
Text after (serif)
\end{document}

% Local variables:
% TeX-engine: xetex
% End:

As usual there is the problem of an OpenType font with wide enough glyph coverage, this is why I chose DejaVu Sans. The Serif one is lacking some of the glyphs used above.

enter image description here

5
  • Sorry for the late reply ! Thank you so much !! This seems to work! One question: Could I change the font to Helvetica ?
    – james
    Commented Oct 10, 2018 at 9:01
  • on my Mac, the system provides fonts Helvetica and Helvetica Neue. But they appear to be lacking the U+2099 glyph (LATIN SUBSCRIPT SMALL LETTER N). I also tried TeX Gyre Heros which comes with TeX distributions but it is lacking and additionally to U+2099. Apart from that, using another font is as simple as replacing in my code DejaVu Sans by what you want in the \DejaVuSansWithNoTeXLigatures line. You may also prefer to rename that font macro.
    – user4686
    Commented Oct 10, 2018 at 10:20
  • A question: Would it be possible to convert the math part of the text it to math form ?
    – james
    Commented Oct 14, 2018 at 6:31
  • sort of, but inside math, the braces { and } will have to revert to their standard meanings. This becomes more complicated that your initial question, so you should try to formulate another, focused, question. Because one wonders if your only problem isn't to have correct font. Do you really have any backslash or & or # that LaTeX doesn't like in your text? apart from math? and then why use math mode at all if your equations are written in Unicode without any LaTeX mark-up?
    – user4686
    Commented Oct 14, 2018 at 8:11
  • Thank you very much for your comment ! :) I would like to create math, because it looks nice in LaTeX, that's all. I might post a new focused question. :)
    – james
    Commented Oct 14, 2018 at 8:17
3

If you want to input a utf-8 encoded text file and just have it mostly work without caring too much what it looks like, then I'd suggest using a combination of

  • a unicode TeX engine (lualatex or xelatex)
  • a font with wide unicode coverage (e.g., Free Serif)
  • some verbatim environment that allows line breaking (e.g., fancyvrb in combination with fvextra)

Compile this with lualatex or xelatex. This will allow lines to be automatically broken at spaces. I'm not sure how to make the text justified, but perhaps your don't care too much.

\documentclass{article}
\usepackage{fontspec}
\setmainfont{Free Serif}[NFSSFamily=freeserif]
\usepackage{fancyvrb}
\usepackage{fvextra}
\begin{document}
\VerbatimInput[fontfamily=freeserif,breaklines,breaksymbol={}]{3.txt}
\end{document}

Output

enter image description here

5
  • Thank you so much !! This seems to work. The problem that I have know, is that the text is not automatically adjusted to the page width. It just keeps going over the edge. Do you have any idea of how to fix that ?
    – james
    Commented Oct 7, 2018 at 14:36
  • @james, I just saw your file. Just wrap your text files first. Either your editor should be able to do this or use fold (unix.stackexchange.com/a/25174) Commented Oct 7, 2018 at 14:39
  • Thank you very much for your help. Do you see any method to do that directly in the current latex script ?
    – james
    Commented Oct 7, 2018 at 14:55
  • @jfbu, do you know how to justify \VerbatimInput? All the solutions I can find on this site involve running macros within a Verbatim environment to set up justification. Commented Oct 8, 2018 at 3:30
  • @jbfu, still missing glyphs! That's a pity. Finding a suitable font or using substitution is a pain. I didn't use \input because I wasn't sure all characters were TeX safe. Commented Oct 8, 2018 at 7:04

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .