It's not fontspec
. If you remove it, together with \newfontfamily
and \myfont
, you get, with pdflatex
,
[![without fontspec][1]][1]
The reason is that the endlines are converted to the character having code 13, which in the standard setting is the ligature “fl”. The Amiri font has no character there and LuaLaTeX uses a box.
The reason is that \readline
stores the line of text as characters of category code 12 (except spaces that retain catcode 10).
You need to read the file with \endlinechar
set to –1.
\begin{filecontents*}{\jobname.txt}
This is the first line.
This is the second line.
\end{filecontents*}
\documentclass[12pt]{article}
\usepackage{pgffor}
%\usepackage{fontspec}
\makeatletter
\newread\myread
\newcount\linecnt
\openin\myread=\jobname.txt
\chardef\stored@endlinechar=\endlinechar
\endlinechar=-1
\@whilesw\unless\ifeof\myread\fi{%
\advance\linecnt by \@ne
\readline\myread t\expandafter o\csname description\number\linecnt\endcsname
}
\endlinechar=\stored@endlinechar
\makeatother
%\newfontfamily\myfont{Amiri}
\begin{document}
% \myfont
\foreach[] \n in {1,...,2}{
{\csname description\n\endcsname}\par
}
\end{document}
Removing the comments and running LuaLaTeX, you get
Actually, I believe you should use \read
and not \readline
, so category codes are normal and control sequences are interpreted.
This is how I'd implement the thing.
\begin{filecontents*}{\jobname.txt}
This is the first line.
This is the second line.
\end{filecontents*}
\documentclass[12pt]{article}
\usepackage{pgffor}
\usepackage{fontspec}
\ExplSyntaxOn
\ior_new:N \g_mitoxix_lines_ior
\NewDocumentCommand{\storelines}{mm}
{% #1 = symbolic name, #2 = file name
\seq_clear_new:c { l__mitoxix_lines_#1_seq }
\ior_open:Nn \g_mitoxix_lines_ior { #2 }
\ior_map_inline:Nn \g_mitoxix_lines_ior
{
\seq_put_right:ce { l__mitoxix_lines_#1_seq } { \tl_trim_spaces:n { ##1 } }
}
\iow_close:N \g_mitoxix_lines_ior
}
\NewExpandableDocumentCommand{\useline}{mm}
{% #1 = symbolic name, #2 = index
\seq_item:cn { l__mitoxix_lines_#1_seq } { #2 }
}
\ExplSyntaxOff
\newfontfamily\myfont{Amiri}
\storelines{description}{\jobname.txt}
\begin{document}
\myfont
\foreach \n in {1,...,2}{
\useline{description}{\n}\par
}
\end{document}