6

Consider the following MNWE, which I'm compiling with pdfTeX:

\documentclass{article} \usepackage{morewrites} \usepackage{memoize} \usepackage{tikz} \begin{document} \begin{tikz} \draw (0,0) -| (1,1); \end{tikz} \end{document} 

This fails to compile with the error

! I can't write on file `{.//prawf.700EB6A4550C47FDDA18E01DBED7CCDC.memo}'. <to be read again> \scan_stop: l.229 \draw (0,0) -| (1,1); (Press Enter to retry, or Control-D to exit; default file extension is `.tex') Please type another output file name: 

I'm guessing this might have to do with the use of \write16 in memoize.sty and advice.sty since morewrites.pdf says

TEXhackers note: The revised \newwrite allocate stream numbers starting at 19. This might break some code that expects stream numbers to be less than 16.

However, the \write16 in both cases is invoked in code which, as I understand it, is for tracing purposes and off by default. So I'm not certain if this is the problem or not.

Nonetheless, I tried adding, for example,

\makeatletter \def\advice@trace#1{\immediate\write\@unused{[tracing advice] #1}} \def\mmz@trace#1{\immediate\write\@unused{[tracing memoize] #1}} \makeatother 

but this was obviously a stupid idea because it made no difference at all. That is, the following code compiles fine:

\documentclass{article} %\usepackage{morewrites} \usepackage{memoize} \usepackage{tikz} \makeatletter \def\advice@trace#1{\immediate\write\@unused{[tracing advice] #1}} \def\mmz@trace#1{\immediate\write\@unused{[tracing memoize] #1}} \makeatother \begin{document} \begin{tikz} \draw (0,0) -| (1,1); \end{tikz} \end{document} 

But as soon as I uncomment the call to morewrites, compilation breaks with the error reported above.

So I'm not clear whether this is simply the use of \write16, whether I've missed less obvious uses of \write16 or if there's a further incompatibility here.

I'm aware that using luaTeX might avoid the need for morewrites, but the documents where I need morewrites are sufficiently committed to pdfTeX that I'll probably just avoid memoize if using it requires switching engines.

What causes the error and is there a way I can work around it in pdfTeX?

Before somebody asks if I really need morewrites, David Carlisle told me I needed morewrites after some change to LaTeX several years ago.

[That is, is there any chance I might be able to have my cake and eat it, too? A sort of self-perpetuating cake of some kind ....]

6
  • 1
    The document does indeed compile with lualatex (even with morewrites loaded). Commented Nov 7, 2023 at 3:03
  • @AlanMunn That's expected. morewrites bails out if luatex is used. It issues a warning, but that's all. Commented Nov 7, 2023 at 3:26
  • do you really need morewrites? if in your real document you remove it do you get an allocation error on allocating a new \write ? Commented Nov 7, 2023 at 7:13
  • @DavidCarlisle I think so. I can see the number of new writes in the log file. To reduce them, I'd have to change the way I've setup glossaries, I think. For example, I could use bib2gls rather than xindy. But that would mean converting all the databases. I know there's a conversion tool, but I'm not sure how messy it would get. Commented Nov 7, 2023 at 15:56
  • @cfr you can write any number of files from classic tex, what you can't do is have more than 16 files open for writing at the same time. I don't know what xindy is doing here but is really need that many open streams? Commented Nov 7, 2023 at 15:59

2 Answers 2

5

Edit 1/2024: With the newest version of morewrites it should work.

======

The problem is that the morewrites package is rather old. It doesn't know that the various file primitives now allow braced arguments. That means that if you compiled this

\documentclass{article} \newwrite\mywrite \immediate\openout\mywrite{./blub.txt} \begin{document} \immediate\write\mywrite{blub} \immediate\closeout\mywrite bluba \end{document} 

then it works fine in texlive 2023 and writes the file blub.txt but errors in texlive 2017 as it tries to write the file {./blub.txt} with the braces (which kind of works) and the inner slash (which the OS doesn't allow) and can't resolve this:

! I can't write on file `{./blub.txt}'. 

memoize makes use of the new syntax, and the redefinitions of morewrites which reinstates the "old" syntax then lead to similar errors:

\immediate\openout\mmz@out{\mmz@cmemo@path}% doesn't work in older tex systems. 

See also the bug report: https://github.com/blefloch/latex-morewrites/issues/19

3

Ulrike has explained the issue, but if you really need morewrites (and usually, it's not needed) and you don't fancy tracing through both packages to bring them in to line, you can do the following (as long as your OS allows)/

Note this is a step towards a workaround, avoiding the error, but does not produce usable output

mkdir "{." 

then when morewrites tries to write

{./example.700EB6A4550C47FDDA18E01DBED7CCDC.memo} 

including the braces, rather than giving an error it will write the file

example.700EB6A4550C47FDDA18E01DBED7CCDC.memo} 

in the directory (folder) {.

So you end up with a weirdly named file ending in } in a weirdly named directory starting with { but it does actually work.


Note this allows \input{./foo} to avoid an error and has a new interpretation as foo} in directory {.. Unfortunately memoize also uses newer primitives that have always accepted brace forms such as \pdf@mdfivesum{./foo} so these refer to the intended (but now non-existant) file foo in the current directory. So the above avoids the error but memoize fails in various ways. A real fix would be to update morewrites (or the pdftex engine) both of which are not impossible to imagine happening, but not actually done.

3
  • Weird, Windows actually allows such directories. Commented Nov 7, 2023 at 15:17
  • @DavidCarlisle Er ... who/how? Commented Nov 7, 2023 at 17:46
  • Cleaned up a bit .... Commented Nov 8, 2023 at 16:37

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.