Is it possible to test whether a "line feed" or "line feed + carriage return" were used to end lines in a tex file? I'd like to create a log message with this information.

The reasoning for this is to ensure that all of my files have the same line endings. I know that I could do this using a scripting language. I am just curious whether or not I can test for these characters in TeX? I know TeX sees them as equivalent e.g either situation would yield a single token when tokenizing. I guess this would need to happen before or during the tokenization phase. An example does not seem fitting here.

  • 1
    The standard behavior of TeX Live implementations is to ascertain the line ending for a given file and act on consequence; it fails with LF-CR, usually, but it detects LF (Unix), CR+LF (Windows) and CR (legacy Mac OS). – egreg May 29 '17 at 14:12

No, or at least not from the TeX end (LuaTeX is different: can use Lua). Line-end normalisation happens very early, before any TeX code gets to see anything. As such, all you will ever get is characters of the value of \endlinechar, so they are always all the same (and so life is easy for the macro programmer).

  • very early meaning that initex does it? – Jonathan Komar May 29 '17 at 14:06
  • @macmadness86 I mean very early in the process of tokenizing the file, before the macro layer has access to anything. – Joseph Wright May 29 '17 at 14:07

Not only can you not tell what is the line end terminator you can not tell if there was a linebreak character at all, nor can you tell if there were any space characters at the end of the line.

This is all in the system-specific part of TeX hidden from the macro layer. On a mainframe with fixed length text fields there may be no line character and all lines are 80 (or 132 or whatever) characters wide, but the tex implementation on such machines will (or did when they existed) strip all trailing white space and make the input appear to be a stream of characters with a single \endlinechar marking lines (records).

Similarly on tex implementations that do use a stream with end of line terminators, the web2c tex implementation normalises LF, CR or CRLF pairs to a single end of line, and all space characters before such a marker are removed.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.