I have a large document that used to compile well some 3 years ago. I came back to it and every time I try compiling it I get ! TeX capacity exceeded, sorry [save size=50000]. I tried to follow any good ideas, like here or here. The second one didn't help me as I use MiKTeX (I coudn't locate any files like texmf.cnf in MiKTeX). I tried following steps from the first one but either it doesn't work or I'm too stupid for this... (sorry!). I tried executing
initexmf --admin --edit-config-file=latex
to enter extra_mem_top = 2000000 and/or main_memory = 5000000
followed by
initexmf --admin --dump=latex
however the result remains the very same error.

I am posting a MWE, however it doesn't produce the error. The interesting thing is that my document consists of two large parts. When I compile it including only one part, it compiles well. Same thing when I compile it with the second part only. Just when compiling the whole document (with both large parts included), it produces the error and the build output reads:

enter image description here

Does anyone possibly have an idea how to solve this? It really looks like a memory error, not code error (since the code compiles well when there's only half of it)...

Edit: Strange thing. I can more or less determine the line that produces the error. When I remove that section from the document, the error is produced at the next following section. It looks like that the error is always in the same line, no matter what the content is.

\documentclass[paper=a5,fontsize=10pt,twoside,twocolumn,pagesize,DIV=15,headsepline,titlepage,openright]{scrbook}
\usepackage{scrlayer-scrpage}
\usepackage{cmap}
\usepackage[utf8x]{inputenc}
\usepackage[vietnamese,polish,english,ngerman]{babel}
\usepackage[T5,T1]{fontenc}
\usepackage{longtable}
\usepackage{lmodern}

\newcommand*\de{\fontencoding{T1}\selectfont\selectlanguage{ngerman}}
\newcommand*\en{\fontencoding{T1}\selectfont\selectlanguage{english}}
\newcommand*\pl{\fontencoding{T1}\selectfont\selectlanguage{polish}}
\newcommand*\vn{\fontencoding{T5}\selectfont\selectlanguage{vietnamese}}

\newcommand{\textfsf}{\sffamily\bfseries\selectfont}
\newcommand{\textksf}{\sffamily\itshape\small\selectfont}

\makeatletter
\g@addto@macro\description{\raggedright}
\makeatother

\setlength{\parindent}{0pt}
\setlength{\parskip}{0.8ex plus 0.4ex minus 0.2ex}
\flushbottom

\clearscrheadings
\ihead{}
\chead{}
\ohead{\rightmark}
\ifoot{}
\cfoot{}
\ofoot{\pagemark}
\pagestyle{scrheadings}

\pdfinfo{
/Title (xxx.pdf)
/Creator (xxx)
/Producer (xxx)
/Author (xxx)
/CreationDate (D:20100101000000)
/ModDate (D:20100101000000)
/Subject (xxx)
/Keywords (xxx)
}

\begin{document}
\frontmatter
\title{\pl ZÓŁTA KROWA\\ \vn CHÀO MỪNG}
\subtitle{\pl NA ŁĄCE\\ \vn CÁC BẠN}
\author{\pl dzień\\ \vn tốt}
\date{}
\publishers{\pl Wydawcy}
\maketitle
\mainmatter
\pl tu będzie trochę tekstu \vn vẫn có bằng tiếng Việt \\
\pl tu będzie trochę tekstu \vn vẫn có bằng tiếng Việt \\
\pl tu będzie trochę tekstu \vn vẫn có bằng tiếng Việt \\
\pl tu będzie trochę tekstu \vn vẫn có bằng tiếng Việt \\
\pl tu będzie trochę tekstu \vn vẫn có bằng tiếng Việt \\
\pl tu będzie trochę tekstu \vn vẫn có bằng tiếng Việt \\
\backmatter
\end{document}
  • save size errors are almost always coding errors. Someone is assigning globally and locally at the same time. But one need an example to debug this. – Ulrike Fischer Dec 4 at 13:06
  • Total random suggestion based on some users experience and unknown how your system is built try running pdfLaTeX.exe via command line to check it rebuilds logs and fails? then try say pdfLaTeX.exe -save-size=100000 [other commands] – KJO Dec 4 at 13:30
  • Why does your example still use the outdated option vietnam? – Ulrike Fischer Dec 4 at 13:40
  • @UlrikeFischer Oh, sorry, it was a copy mistake. It should be vietnamese and I just edited it. What do you mean saying "assigning globally and locally at the same time"? Could it mean that the compiler gets upset because of using the defined \vn and \pl over and over again? – Dominik Dec 4 at 16:38
  • @KJO Thanks, I tried it (although it really was trying since I have no experience with that). It threw out some undefined control sequence errors and the fatal error thing (that no pdf could be produced). – Dominik Dec 4 at 16:40
up vote 2 down vote accepted

I defined

\def\ten{
\pl tu będzie trochę tekstu \vn vẫn có bằng tiếng Việt \par
\pl tu będzie trochę tekstu \vn vẫn có bằng tiếng Việt \par
\pl tu będzie trochę tekstu \vn vẫn có bằng tiếng Việt \par
\pl tu będzie trochę tekstu \vn vẫn có bằng tiếng Việt \par
\pl tu będzie trochę tekstu \vn vẫn có bằng tiếng Việt \par
\pl tu będzie trochę tekstu \vn vẫn có bằng tiếng Việt \par
\pl tu będzie trochę tekstu \vn vẫn có bằng tiếng Việt \par
\pl tu będzie trochę tekstu \vn vẫn có bằng tiếng Việt \par
\pl tu będzie trochę tekstu \vn vẫn có bằng tiếng Việt \par
\pl tu będzie trochę tekstu \vn vẫn có bằng tiếng Việt \par
}\def\hundred{\ten\ten\ten\ten\ten\ten\ten\ten\ten\ten}
\def\thousand{\hundred\hundred\hundred\hundred\hundred\hundred\hundred\hundred\hundred\hundred}

in order to have several language changes. I also made a wrapper macro

\newcommand{\languagechange}[3]{%
  \newcommand{#1}{%
    \fontencoding{#2}\selectfont
    \selectlanguage{#3}%
  }%
}
\languagechange{\de}{T1}{ngerman}
\languagechange{\en}{T1}{english}
\languagechange{\pl}{T1}{polish}
\languagechange{\vn}{T5}{vietnamese}

Compiling a document with

\thousand\thousand\thousand

(that is, 3000 paragraphs), the statistics about the save size is

12194s

out of 80000s. With 3000 paragraphs more I get 24175s.

On the other hand, if I change the definition of \languagechange to

\newcommand{\languagechange}[3]{%
  \wlog{Lang: #3}%
  \newcommand{#1}{%
    \csname otherlanguage*\endcsname{#3}%
  }%
}

the statistics about the save size drops down to 389s. The main cause is the fact that \selectlanguage writes itself to the aux file and this has nefarious consequence on the save size. By the way, it isn't necessary to issue \fontencoding{T5}\selectfont in order to switch to Vietnamese, because this is already taken care of bybabel`.

Full example:

\documentclass[paper=a5,fontsize=10pt,twoside,twocolumn,pagesize,DIV=15,headsepline,titlepage,openright]{scrbook}
\usepackage{scrlayer-scrpage}
\usepackage{cmap}
\usepackage[utf8]{inputenc}
\usepackage[vietnamese,polish,english,ngerman]{babel}
\usepackage[T5,T1]{fontenc}
\usepackage{longtable}
\usepackage{lmodern}

\newcommand{\languagechange}[3]{%
%  \wlog{Lang: #3}%
  \newcommand{#1}{%
%    \fontencoding{#2}\selectfont
    \csname otherlanguage*\endcsname{#3}%
  }%
}
\languagechange{\de}{T1}{ngerman}
\languagechange{\en}{T1}{english}
\languagechange{\pl}{T1}{polish}
\languagechange{\vn}{T5}{vietnamese}

\newcommand{\textfsf}{\sffamily\bfseries\selectfont}
\newcommand{\textksf}{\sffamily\itshape\small\selectfont}

\makeatletter
\g@addto@macro\description{\raggedright}
\makeatother

\setlength{\parindent}{0pt}
\setlength{\parskip}{0.8ex plus 0.4ex minus 0.2ex}
\flushbottom

\clearscrheadings
\ihead{}
\chead{}
\ohead{\rightmark}
\ifoot{}
\cfoot{}
\ofoot{\pagemark}
\pagestyle{scrheadings}

\pdfinfo{
/Title (xxx.pdf)
/Creator (xxx)
/Producer (xxx)
/Author (xxx)
/CreationDate (D:20100101000000)
/ModDate (D:20100101000000)
/Subject (xxx)
/Keywords (xxx)
}

\begin{document}
\frontmatter
\title{\pl ZÓŁTA KROWA\\ \vn CHÀO MỪNG}
\subtitle{\pl NA ŁĄCE\\ \vn CÁC BẠN}
\author{\pl dzień\\ \vn tốt}
\date{}
\publishers{\pl Wydawcy}
\maketitle
\mainmatter

\def\ten{
\pl tu będzie trochę tekstu \vn vẫn có bằng tiếng Việt \par
\pl tu będzie trochę tekstu \vn vẫn có bằng tiếng Việt \par
\pl tu będzie trochę tekstu \vn vẫn có bằng tiếng Việt \par
\pl tu będzie trochę tekstu \vn vẫn có bằng tiếng Việt \par
\pl tu będzie trochę tekstu \vn vẫn có bằng tiếng Việt \par
\pl tu będzie trochę tekstu \vn vẫn có bằng tiếng Việt \par
\pl tu będzie trochę tekstu \vn vẫn có bằng tiếng Việt \par
\pl tu będzie trochę tekstu \vn vẫn có bằng tiếng Việt \par
\pl tu będzie trochę tekstu \vn vẫn có bằng tiếng Việt \par
\pl tu będzie trochę tekstu \vn vẫn có bằng tiếng Việt \par
}\def\hundred{\ten\ten\ten\ten\ten\ten\ten\ten\ten\ten}
\def\thousand{\hundred\hundred\hundred\hundred\hundred\hundred\hundred\hundred\hundred\hundred}

%\tracingrestores=1

\thousand\thousand\thousand
\thousand\thousand\thousand
\thousand\thousand\thousand
\thousand\thousand\thousand
\thousand\thousand\thousand
\thousand\thousand\thousand
\thousand\thousand\thousand
\thousand\thousand\thousand
\thousand\thousand\thousand
\thousand\thousand\thousand

\backmatter
\end{document}

This produces 884 pages, with 30000 paragraphs and 60000 language changes. The final statistics are

Here is how much of TeX's memory you used:
 5560 strings out of 492639
 122151 string characters out of 6129301
 308623 words of memory out of 5000000
 9358 multiletter control sequences out of 15000+600000
 62048 words of font info for 39 fonts, out of 8000000 for 9000
 1141 hyphenation exceptions out of 8191
 51i,18n,70p,9111b,389s stack positions out of 5000i,500n,10000p,200000b,80000s

As you can see, a very little part of the stack size is used.

  • Well, this is high level! I tried with the wrapper macro but it also produces the save size error. Then I tried to run it with the wlog thing. This produces over 600 errors, most of which concern \bbl@tempd like ! Argument of \bbl@tempd has an extra }, ! Paragraph ended before \bbl@tempd was complete, Undefined control sequence, ! Paragraph ended before \bbl@foreign@x was complete, ! Extra } or forgotten \endgroup... – Dominik Dec 4 at 19:15
  • @Dominik First remove the aux file – egreg Dec 4 at 20:46
  • Thanks, I did remove the aux file... However, I just ran a new trial - with those \tens, \hundreds and \thousands. I am getting exactly the same errors as initially (save size errors) when I am having at least 13 \thousands. And it doesn't matter if the language changes are defined as \newcommand*\vn{\fontencoding{T5}\selectfont\selectlanguage{vietnamese}} or as in your wrapper macro. The compilation speed feels the same to me and the error is being referred to more or less in the same place of the aux file. – Dominik Dec 6 at 14:05
  • @Dominik I added a full example; compiling it with pdflatex has no problem. – egreg Dec 6 at 21:09
  • Thanks for the full example. I compiled it and it works fine indeed (and compiles much more quickly!). When I get to some more time, I will try to determine where exactly the difference lies - maybe I'll be able to locate the bug. When I know more, I'll post it. – Dominik Dec 14 at 13:36

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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