0

I want to generate the following line(s)

1 & {\QPCSymbols\XeTeXglyph 2}  & \textarabic{الحمدلله} & \texttt{!} & \verb$\XeTeXglyph 2$  \\
\hline

Let's say the first number is n and the second one is n+1, the contents of \textarabic is obtained from f_nusoos and the contents of \texttt from f_keys. Both files have the same number of lines.

I've created a Python3 script that should get me what I want but I end up with new line symbols (\n).

Here is what I have so far,

#! python3
import linecache

f_nusoos = 'symbol_nass_list.txt'
f_keys   = 'symbol_key_list.txt'
contentfile = open('content.tex', 'w+', encoding="utf-8")

theLine = " "

for x in range(3):
  contentfile.write('{} & {{\QPCSymbols\XeTeXglyph {}}}  & \\textarabic{{{}}} & \\texttt{{{}}} & \\verb$\XeTeXglyph {}$  \\\\'.format(x+1, x+2,linecache.getline(f_nusoos, x+1).rstrip('\n'), linecache.getline(f_keys, x+1), x+2).rstrip('\n'))
  contentfile.write('\hline')

The contents of content.tex after execution is,

1 & {\QPCSymbols\XeTeXglyph 2}  & \textarabic{بسم الله الرحمن الرحيم} & \texttt{!
} & \verb$\XeTeXglyph 2$  \\\hline2 & {\QPCSymbols\XeTeXglyph 3}  & \textarabic{بسم الله الرحمن الرحيم} & \texttt{"
} & \verb$\XeTeXglyph 3$  \\\hline3 & {\QPCSymbols\XeTeXglyph 4}  & \textarabic{بسم الله الرحمن الرحيم} & \texttt{#
} & \verb$\XeTeXglyph 4$  \\\hline

My expectation, however,

1 & {\QPCSymbols\XeTeXglyph 2}  & \textarabic{بسم الله الرحمن الرحيم} & \texttt{!} & \verb$\XeTeXglyph 2$\\
\hline
2 & {\QPCSymbols\XeTeXglyph 3}  & \textarabic{بسم الله الرحمن الرحيم} & \texttt{"} & \verb$\XeTeXglyph 3$\\
\hline
3 & {\QPCSymbols\XeTeXglyph 4}  & \textarabic{بسم الله الرحمن الرحيم} & \texttt{#} & \verb$\XeTeXglyph 4$\\
\hline

The problem seems to be a new line being inserted after texttt{CONTENT. I don't know why this is.

Content of f_nusoos.txt:

بسم الله الرحمن الرحيم
بسم الله الرحمن الرحيم
بسم الله الرحمن الرحيم

Content of f_keys.txt:

!
"
#
Khalid Hussain
  • 345
  • 4
  • 16
  • Could it be that the end-of-line character is not `\n`, but `\r\n` (Windows) or `\r` (MacOS)? This would explain why `rstrip('\n')` does not work. Maybe `rstrip()` without parameter is sufficient. – Karsten Koop Jun 02 '16 at 15:07

1 Answers1

0

I was staring at this for too long.

Instead of

contentfile.write('{} & {{\QPCSymbols\XeTeXglyph {}}}  & \\textarabic{{{}}} & \\texttt{{{}}} & \\verb$\XeTeXglyph {}$  \\\\'.format(x+1, x+2,linecache.getline(f_nusoos, x+1).rstrip('\n'), linecache.getline(f_keys, x+1), x+2).rstrip('\n'))

it should be

contentfile.write('{} & {{\QPCSymbols\XeTeXglyph {}}}  & \\textarabic{{{}}} & \\texttt{{{}}} & \\verb$\XeTeXglyph {}$  \\\\'.format(x+1, x+2,linecache.getline(f_nusoos, x+1).rstrip('\n'), linecache.getline(f_keys, x+1).rstrip('\n'), x+2))

The rstrip() should be for the input from the file and not for the counter.

Khalid Hussain
  • 345
  • 4
  • 16