Questions tagged [write]

{write} is about writing to files in TeX macros.

Filter by
Sorted by
Tagged with
1 vote
0 answers
44 views

How to escape before saving to a file?

I'm trying to create a command that will be able to save plain text to a file (without any TeX commands): \documentclass{article} \begin{document} \newwrite\xwrite \newcommand\tofile[1]{ \immediate\...
  • 10.3k
4 votes
1 answer
163 views

Need macro to \write content into a file as a string from LaTeX

We are writing a cls file that produces a text file as a side effect of running latex. This will be done in a cloud service within a docker container, so security is a serious concern. The output file ...
0 votes
0 answers
25 views

Preserve vertical lastskip over \write

Is there a way to save a vertical \lastskip over \write, or, more generally, is there a way to program a "vertical version" of \@bsphack … \@esphack? In the following minimal example \...
  • 2,450
0 votes
1 answer
99 views

Write the contents of a bibliography from thebibliography environment to a file

I need to write contents from thebibliography environment (BixTeX/BibLaTeX are not used) to an XML file. Each bibliographic source should be in a separate pair of <reference> and </reference&...
1 vote
1 answer
52 views

Writing to a file values of function in expl3

I'm trying to master LaTeX3 using the example of the problem of parsing LaTeX code and then writing function values ​​to a file. Problem. Generate a piece of XML file in pdfLaTeX containing normalized ...
0 votes
0 answers
52 views

\pageref{} produce wrong page number when \label{} comes top of the page

I am trying to create a para id with page number as a separate file, through a command \def\paraopenid#1{\label{#1}\immediate\write\paraID{<ParaID="#1" StartPageNumber="\...
  • 1,814
0 votes
0 answers
30 views

Writing to and compiling .tex document from another GUI

I am a math teacher and I have a .tex template for my quizzes that looks something like this: \begin{document} \begin{flushleft} Name: \underline{\hspace{2in}} \hfill /XX % where XX is ...
  • 1
1 vote
1 answer
104 views

How to write and expand \gls command to a text file?

Is it possible to expand the \gls command in order to print it's "output" in a text file? Here a 'MWE.tex' file content: \documentclass{article} \usepackage{glossaries-extra} \...
7 votes
1 answer
106 views

What is the difference between \write and \immediate\write?

What is the difference between \write and \immediate\write commands when writing to a text file? \write command seems to write nothing on the text file... Here a MWE: \documentclass{article} \...
4 votes
1 answer
95 views

Using the word "write" as a label makes compilation crash

Took me all night (literally) to figure out. Compilation was failing one time out of two, with the following original error (line 12) : "Bad space factor (0)". That was crazy because ...
0 votes
1 answer
43 views

Append content to a file containing sharp

In my library, I need to be able to append some text to a file. The problem is that that file may contain the # symbol, and it turns out that every time I append something to a file containing a #, ...
  • 5,265
0 votes
0 answers
87 views

How get the result of a macro that uses xstring functions before writing to a file

I encountered the need to write last name with initials (extracted from the full author's string based on first chars of first and middle name) into an external file. I use the xstring package to ...
0 votes
0 answers
34 views

save the position information of the tikzpicture bounding box

I learned from this question that each tikzpicture can generate a bounding box. I want to save the position information of the tikzpicture bounding box (such as the upper left corner and width and ...
  • 149
1 vote
0 answers
27 views

Print information when changing pages

Can I print some information when generating a new page? For example, in the following example, I want to print "new page!" or page number in a txt file every time a new page is generated. \...
  • 149
3 votes
1 answer
72 views

Use \immediate\write18 with Single Quote

I would like to use \immediate\write18 (encoded in the \OuputToFileA macro) to output a string containing a single quote. If I replace the single quote with another character, such as X \StrSubstitute{...
0 votes
1 answer
42 views

how to change the format of date to exported to a CSV file

I want to write export some Information in a csv data. One thing I don't get in in the csv data, it is the date. Firstly when I use \today in my Latex document I get 15.January 2022, but I want it in ...
  • 119
1 vote
1 answer
41 views

Using \immediate\write18 when lineno package yields spurious text

I am getting spurious text in the output of \immediate\write18 when the lineno package is used. The MWE below yields the following in the file foo.tex: If one comments out the line that includes ...
7 votes
1 answer
260 views

Inconsistent behaviour of \detokenize on macro beginning with "e" or "f"

I need to write to a file the unexpanded LaTeX. The macro \OuputToFile is bascially an \immediate\write18 and works fine with the following: \OuputToFile{\detokenize{$\OuterMacro{\cXXX{X}}$}}% \...
2 votes
1 answer
106 views

merge many txt to one

There are plenty of .txt files and I try to figure a way in Latex to merge all *.txt to one *.txt. I thought about \newread and \newwrite but I don't know if there is a better way or how to start. the ...
  • 119
1 vote
1 answer
45 views

Converting data to utf8 in a write

I need to \write (or to \iow_now:Nn) a file containing utf8-encoded text, from a LaTeX file in an encoding that is not necessarily utf8 (for context: one typical use of this is to collect metadata ...
0 votes
0 answers
28 views

Tex adding information to txt

Is there any possibility to add Information to a .txt or other type of document? For example I have the following .tex \begin{filecontents*}{Info.tex} @ P & 1 & 60 & 2 & 77 \\ ...
  • 119
1 vote
1 answer
46 views

problem creating tex from tex because of missing space

I have saved a name in \Name. It is ABC. So actually I wrote both possibilities this one \immediate\write\file{\read\noexpand\NoFile to \\Name} and this one \immediate\write\file{\read\noexpand\...
  • 119
1 vote
1 answer
49 views

tex document creat tex document with special content

I want a *.tex document that create a *.tex that content the following lines: \newread\NoFile \newcounter{AME} \openin\NoFile=V/AME.txt \read\NoFile to \AME \closein\NoFile so I looked up in the ...
  • 119
6 votes
1 answer
234 views

How to extract variables from an auxiliary file?

I would like to use an auxiliary file to read and write some information. Context In this case, I am using this auxiliary file to record the widths used in the footnote formatting. Indeed, I want my ...
  • 335
1 vote
2 answers
53 views

How to automatically protect all the commands passed in an argument?

I need to write to an auxfile some mathematical formulas. The following MWE does not work: \documentclass{article} \usepackage{amsmath} \newwrite\filehandle \newcommand{\addToFile}[1]{\immediate\write\...
  • 6,242
7 votes
1 answer
239 views

Maximum amount of characters per line in .tex-input files?

According to TeXbook TeX does preprocess files of .tex-input line per line (converting all characters of the line to TeX's internal character-representation-scheme (ASCII or Unicode), truncating ...
2 votes
1 answer
89 views

Suppress filecontents warning if the file is defined before documentclass

I would like to define filecontents blocks before documentclass in my LaTeX document. Is there any way to suppress warning Writing or overwriting file ./filename? My MWE is as follows: \begin{...
  • 522
3 votes
3 answers
125 views

newwrite out of a table with umlauts

I have a follow-up question on https://tex.stackexchange.com/a/598981/46023 Everything works in the MWE there, but when used in my original example it no longer works (note: originaltable.csv is a ...
  • 6,357
3 votes
2 answers
65 views

newwrite and read in with umlauts

I write the file out.csv, which contains umlauts and tried to read it in. How can I make this work? \documentclass[margin=5pt, varwidth]{standalone} \usepackage{pgfplotstable} \pgfplotsset{compat=...
  • 6,357
3 votes
2 answers
223 views

LaTeX expansion of number into ordinal suffix

For a project I am working on I want to automatically 'calculate' the ordinal suffix for numbers. I need to calculate ordinals for various numbers, and later also write them to an external file (the ...
  • 354
3 votes
1 answer
76 views

Problem with special characters when writing to an external file

The following MWE throws the error Undefined control sequence. Test avec \unhbox \voidb @x \bgroup \let \unhbox \voidb @x \setbo... l.1 ...e\egroup \spacefactor \accent@spacefactor } ? How can I ...
  • 6,242
0 votes
1 answer
30 views

Error when writing \section in an external file

The following MWE throws the error Undefined control sequence. \GenericError ... #4 \errhelp @err@ ... l.9 \immediate\write\fich@sol {\section{Test}} ? What's the problem? \documentclass{...
  • 6,242
0 votes
0 answers
56 views

How to create a TeX variable whose name depends on a parameter

I would like to create multiple \newwrite in my document, for instance: one by chapter. I've tried the following but it doesn't work. I guess, in the end, my question falls back to: giver a parameter #...
  • 6,242
7 votes
3 answers
541 views

How do I \write18 a koma var?

I'm trying to do some shell processing of data that depends on the settings inside the TeX file. To do this I want to \immediate\write18 a command that depends on a \usekomavar, but pdflatex complains ...
  • 1,125
1 vote
1 answer
52 views

Writing properly escaped strings to a file

I have to write a properly (as in JSON or Javascript) escaped string to a file. My minimal example is \documentclass{standalone} \begingroup \catcode`<=1 \catcode`>=2 \catcode`{=12 \catcode`}=...
7 votes
2 answers
173 views

\selectlanguage pushes section to new page

The following code \documentclass{article} \usepackage{kantlipsum} \usepackage[ngerman,english]{babel} \begin{document} \section{Foo} \kant[1] \begin{itemize} \item \item \item \item \item \end{...
  • 26.7k
1 vote
1 answer
108 views

Problem writing to file through \directlua in a memoir class document

Below is a minimal example of some code where the memoir class seems to collide with Lua code, executed within a \directlua command, that writes to an external file. Can anyone help me figure out the ...
1 vote
1 answer
53 views

How can I use \iow_now:Nx with umlauts/unicode?

I do some file writing with expl3 but also need the Nx version, which collides with the usage of umlauts. The Nn version handles the umlauts correctly but doesn’t expand the token list for writing it ...
  • 53.8k
0 votes
2 answers
25 views

Show reference at begin of document with conditions

I'd like to show some reference at begin of document with some conditions. Here is the example code \documentclass{article} \usepackage{hyperref} \newcounter{ctest} \setcounter{ctest}{0} \...
  • 4,396
0 votes
1 answer
102 views

Biblatex: Writing the output of \thefield{...} to a file

Short question: in Biblatex, how do I print the (string) field contents to a file? When processing an entry I would like to do something like this: \write\file{\thefield{userc}}% the file contents ...
0 votes
1 answer
32 views

Table with foreachloop as writeout in a external textfile

I create a table with 2 foreach-loops. Now I would like to have that as a textfile too. But there are some if-decision. How to use newwrite correctly here? \documentclass[]{article} \usepackage{tikz} ...
  • 6,357
3 votes
2 answers
118 views

How to use % inside \write18 command? [duplicate]

I'm doing this: \documentclass{article} \begin{document} \write18{echo '100%' > hash.tex} \input{hash.tex} \end{document} However, this doesn't work (doesn't compile). What is the workaround?
  • 10.3k
1 vote
1 answer
72 views

newwrite: Adding text to a existing outfile

I have \documentclass[a4paper]{article} \begin{document} \newwrite\myoutfile \immediate\openout\myoutfile=\jobname-myoutfile.txt \immediate\write\myoutfile{ aaa } \immediate\closeout\myoutfile \...
  • 6,357
0 votes
0 answers
115 views

Writing to custom ouput file with lualatex: Hook to start of the writing process and substitute not-fully expandable macros

I am working on writing document with informations, that are at the end of each part summarized in summary. To prevent writing them twice, I am using datatool to create "buffers" in runtime, from ...
0 votes
2 answers
56 views

Failing to write to file and input the same

\documentclass{minimal} \usepackage{etoolbox} \newwrite\tempfile \makeatletter \let\features\@gobble \makeatother \newcommand{\feature}[1]{% \expandafter\def\expandafter\features\expandafter{\...
2 votes
1 answer
539 views

Verbatim write in Plain TeX

I am trying to write verbatim text into a file in Plain TeX. In LaTeX I could use the verbatim package. My goal is using Asymptote in Plain TeX. So I need something that works like \verbatim@start ...
1 vote
1 answer
30 views

\newwrite, pgfplotstable: Put generated rows together to one pgfplotstable (follow-up question)

I get a Code from @egreg that create rows in outwritten textfiles in a loop. I need to put all these rows together in 1 pgfplotstable, that means something like \ifnum\the\filecount=1 \...
  • 6,357
1 vote
2 answers
54 views

\write and pgfplotstable: Adding \pgfplotstableread into \loop goes wrong

I get a code from @DavidCarlisle, that generate output-txt-files, and I want to put all the outputfiles in a pgfplotstable together. So I try adding \ifnum\the\filecount=1 \pgfplotstableread[col sep=...
  • 6,357
1 vote
1 answer
124 views

Writing expanded macro with space to file

I'm trying to write an expanded macro to a file without the expansion eating the space after it. I could replace the {} empty group with an explicit \space, but I want this to be fairly robust. Is ...
2 votes
1 answer
292 views

Verbatim LaTeX content of an environment exported to an external file

Is there a way to export the content of an environment to an external file without blocking the action of the environment ? Typically in the following example, I would like to keep the content of the ...
  • 11.6k