This is a quite specific question. I have some code and I'm completely stuck because it won't work for an inexplicable reason. I need to find in which line of an external file there is a tab. I use the ifthen and the xstring package to test everything. I tried to make it as short as possible (which is not quite short...).
If I simply have to search for a tab from a given file with name \fname there is no problem at all (this is really a minimal working example):
\documentclass{article}
\usepackage{ifthen}
\usepackage{xstring}
\begin{document}
\newcounter{nolines} % counter NumberOfLines
\def\fname{FileOne.txt} % define filename
OPENING \fname
\immediate\newread\file
\immediate\openin\file=\fname
\setcounter{nolines}{0}
\catcode`\^^I=11 % set tab ( ) to normal character
\loop\unless\ifeof\file % loop until end of \file
\stepcounter{nolines} % counter +1
\immediate\read\file to\fline % read a line of \file
\ifthenelse{\equal{\fline}{\par}}{% if \fline empty, very important check
Line \thenolines: emtpy
}{% if \fline not empty
\IfSubStr{\fline}{ }{% if \fline contains 'tab'
Line \thenolines: tab
}{% if \fline does not contain 'tab'
Line \thenolines: no tab.
}
}
\repeat % go back to \loop
\catcode`\^^I=10 % revert the code of tab ( )
CLOSING \fname
\immediate\closein\file
\end{document}
The second argument of the command \IfSubStr is a tab! Change it if you copy/paste before running. An example of the text file:
1.This is some text.
3.Here comes a tab: !
4.And some more text.
Again change the space to tab (after a tab: of course) if you copy/paste. This gives the output:
OPENING File.txt
Line 1: no tab.
Line 2: emtpy
Line 3: tab
Line 4: no tab.
Line 5: emtpy
CLOSING File.txt
Which is entirely correct. But if I have to search for the file-name in another file (this file contains a lot of file-names, and there are a lot of those 'parent-files'. Thus manually is out of the question. The example is kept simple) it suddenly detects in every scanned line a tab (not empty lines). Replace \def\fname{FileOne.txt} % define filename with
\def\parentfile{File.txt} % define parentfile instead
\immediate\newread\parent
\immediate\openin\parent=\parentfile
\immediate\read\parent to\fname % read a line of the parentfile
\ifthenelse{\equal{\fname}{\par}}{% if \fname is empty
}{% if \fname is not emtpy
and add at the bottom before \end{document}
}
\immediate\closein\parent
File.txt simply contains
FileOne.txt
This gives the unexpected output of
OPENING FileOne.txt
Line 1: tab
Line 2: emtpy
Line 3: tab
Line 4: tab
Line 5: emtpy
CLOSING FileOne.txt
Which is not what I wanted. Without changing anything to the 'recognize tab code', still the output is different for a reason I really do not understand and cannot find out (for 2 days now...)
Sorry again for the long question, but I couldn't make it shorter.