TeX command write is not inserting new lines where expected

  • LaTeX
  • Thread starter Eclair_de_XII
  • Start date
  • Tags
    Lines
In summary, the conversation discusses alternative ways to add newlines in TeX, as well as using PlainTeX and importing packages from Overleaf.
  • #1
Eclair_de_XII
1,083
91
TL;DR Summary
I'm trying to learn how to use the \write command in order to tell TeX to write files. I want to start a new line with each message inserted. According to TeX for the Impatient, whenever the program encounters the character whose charcode is given by the numerical \newlinechar parameter, the engine starts a new line. Such is not the case for the code below. Why is this?
Code:
\documentclass{article}

\newlinechar=`\^^J

\def\first{This is the first sentence.^^J}
\def\second{This is the second sentence.^^J}
\def\third{This is the third sentence.^^J}
\def\nth{You get the idea.^^J}

\def\outfile{outfile.txt}
\newwrite\myout

\begin{document}

\immediate\openout\myout=\outfile
\immediate\write\myout{\first}
\immediate\write\myout{\second}
\immediate\write\myout{\third}
\immediate\write\myout{\nth}
\immediate\closeout\myout

\end{document}
 
Physics news on Phys.org
  • #3
The thing is, the commands there, like \newline and \par only typeset new-lines (line-breaks?). I want to write new-lines into an output file, and unfortunately, none of the commands I've tried in that link seem to work for that purpose. Thanks for the input, besides.
 
  • Like
Likes jedishrfu
  • #4
You can always use overleaf and import the ams...
 
  • #5
I was sort of looking forward to doing this using just PlainTeX.

In any case, are you referring to an ams package that they have hosted on that web-site?
 
  • #6
Eclair_de_XII said:
I was sort of looking forward to doing this using just PlainTeX.

In any case, are you referring to an ams package that they have hosted on that web-site?
Yes. my mistake. I read LaTek instead of TeX for some odd reason.
 

FAQ: TeX command write is not inserting new lines where expected

Why is my TeX command write not inserting new lines where I expect it to?

There could be several reasons for this issue. One possibility is that there is a formatting issue in your code, such as missing curly braces or incorrect line breaks. Another possibility is that the command you are using is not designed to insert new lines, but rather to concatenate strings or variables.

How can I troubleshoot the issue of my TeX command write not inserting new lines?

First, check your code for any formatting errors. Make sure all necessary curly braces are present and that line breaks are properly indicated. If the issue persists, try using a different command or method for inserting new lines, such as using the "par" command.

Can I adjust the spacing between lines when using the TeX command write?

Yes, you can adjust the spacing between lines by using the "baselineskip" command. This allows you to control the distance between lines of text in your document.

Is there a way to force a line break when using the TeX command write?

Yes, you can use the double backslash "\\" to force a line break when using the TeX command write. This will create a new line without any additional spacing.

Are there any alternative commands or methods for inserting new lines in TeX?

Yes, there are several other commands and methods for inserting new lines in TeX. Some examples include the "newline" command, the "par" command, and the "vskip" command. It is always a good idea to explore different options to find the one that best suits your needs.

Similar threads

Replies
8
Views
11K
Replies
11
Views
5K
Replies
8
Views
3K
Replies
3
Views
551
Replies
3
Views
724
Back
Top