Questions tagged [write]

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

Filter by
Sorted by
Tagged with
1 vote
1 answer
72 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} \...
user avatar
7 votes
1 answer
84 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} \...
user avatar
4 votes
1 answer
93 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 ...
user avatar
0 votes
1 answer
30 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 #, ...
user avatar
  • 5,053
0 votes
0 answers
76 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 ...
user avatar
0 votes
0 answers
28 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 ...
user avatar
  • 149
1 vote
0 answers
25 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. \...
user avatar
  • 149
3 votes
1 answer
53 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{...
user avatar
0 votes
1 answer
34 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 ...
user avatar
  • 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 ...
user avatar
7 votes
1 answer
253 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}}$}}% \...
user avatar
2 votes
1 answer
99 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 ...
user avatar
  • 119
1 vote
1 answer
39 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 ...
user avatar
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 \\ ...
user avatar
  • 119
1 vote
1 answer
45 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\...
user avatar
  • 119
1 vote
1 answer
47 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 ...
user avatar
  • 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 ...
user avatar
  • 281
1 vote
2 answers
52 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\...
user avatar
  • 6,130
5 votes
1 answer
180 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 ...
user avatar
2 votes
1 answer
62 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{...
user avatar
  • 512
3 votes
3 answers
115 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 ...
user avatar
  • 6,217
3 votes
2 answers
53 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=...
user avatar
  • 6,217
3 votes
2 answers
156 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 ...
user avatar
  • 344
3 votes
1 answer
65 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 ...
user avatar
  • 6,130
0 votes
1 answer
29 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{...
user avatar
  • 6,130
0 votes
0 answers
52 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 #...
user avatar
  • 6,130
7 votes
3 answers
530 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 ...
user avatar
  • 1,115
1 vote
1 answer
46 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`}=...
user avatar
7 votes
2 answers
165 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{...
user avatar
  • 25.5k
1 vote
1 answer
83 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 ...
user avatar
1 vote
1 answer
49 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 ...
user avatar
  • 53.3k
0 votes
2 answers
24 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} \...
user avatar
  • 4,336
0 votes
1 answer
86 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 ...
user avatar
0 votes
1 answer
29 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} ...
user avatar
  • 6,217
3 votes
2 answers
86 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?
user avatar
  • 10.1k
1 vote
1 answer
61 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 \...
user avatar
  • 6,217
0 votes
0 answers
96 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 ...
user avatar
0 votes
2 answers
55 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{\...
user avatar
2 votes
1 answer
480 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 ...
user avatar
0 votes
1 answer
27 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 \...
user avatar
  • 6,217
1 vote
2 answers
51 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=...
user avatar
  • 6,217
1 vote
1 answer
113 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 ...
user avatar
2 votes
1 answer
279 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 ...
user avatar
  • 11.4k
1 vote
1 answer
58 views

How to \write content with backslashes to a file?

The following MWE works as I expect but when I make certain changes I get errors: If I introduce say \textbf{something} within a \solution{} say \solution{\textbf{xx}}. If I change \theenumi to \...
user avatar
  • 2,545
1 vote
2 answers
68 views

Writing into a file, strange behavior with expansion

I want to write some data into a file, but I need to replace a subtring in these data beforehand. For some reason, the expansion through the \write macro does not give the expected result. Instead, a ...
user avatar
1 vote
1 answer
94 views

writing functions and wrapping commands for abstraction

Can i write a little function (or macro or whatever) that wraps two commands (functions?) into one; united under a single alias? Specifically I want to wrap \input{} and \includegraphics{} into a ...
user avatar
  • 1,969
0 votes
1 answer
160 views

Directly input a sage file in a sagetex block

Is there a command similar to \lstinputlisting with sagetex, which would import directly a .sage file in the relevant block, and have it evaluated by sagetex? If not, how would one write such a ...
user avatar
  • 12.9k
0 votes
1 answer
63 views

Add created parameters in child file to main.tex

My code/idea from 2 topics: Input a parameter from another file filecontents: select rows of group to display File parameters.tex: \documentclass{article} \usepackage[utf8]{vietnam} \usepackage{...
user avatar
  • 1,921
2 votes
1 answer
78 views

`\unexpand\expandafter` add spaces : how to append a text at the end of a file

I'd like to append code to a file containing latex code... So I tried the solution proposed here, but unfortunately it fails when there are backslash in the file: How can I open a file in "append&...
user avatar
  • 5,053
0 votes
0 answers
61 views

Tutorial: Low-Level Basic Implementation of an Asynchronous Table of Contents?

Closely Related: - Mimicking LaTeX's "table of contents" functionality Using documentclass{minimal}, what is the shortest way to write a low-level asynchronous Table of Contents, (...
user avatar