3

I have a document made up of many sub-documents. These documents can be compiled separately using LaTeX and the subfiles package but not when I use both newtxtext and bm as well. How can I overcome this?

For example, file main.tex:

\documentclass{report}
\usepackage{newtxtext}
\usepackage{newtxmath}
\usepackage{bm}
\usepackage{subfiles}
\begin{document}
\subfile{sub1}
\end{document}

File sub1.tex in the same directory:

\documentclass[main]{subfiles}
\begin{document}
$\bm{x}$
\end{document}

The main file compiles without a problem, but trying to compile sub1 by itself reports an error but only when newtxtext is included.

The log file tells me

Runaway argument?
{document}\ifx \reserved@a \@currenvir \else \@badend {document}\fi  \clearpage 
\ETC.
! File ended while scanning use of \reserved@a.
<inserted text> 
                \par 
<*> \input sub1.tex

I suspect you have forgotten a `}', causing me
to read past where you wanted me to stop.
I'll try to recover; but if the error is serious,
you'd better type `E' or `X' now and fix your file.

! Emergency stop.
<*> \input sub1.tex

*** (job aborted, no legal \end found)

Adding a paragraph break between $\bm{x}$ and the \end{document} gives the message

! Paragraph ended before \bm@test@token was complete.

Searching for this message brings up the question Package incompatibilites: etoolbox, hyperref, and bm, standalone?. Could this be a similar problem?

Adding \listfiles gives

 *File List*
   report.cls    2005/09/16 v1.4f Standard LaTeX document class
   size10.clo    2005/09/16 v1.4f Standard LaTeX file (size option)
newtxtext.sty    2014/04/26 v1.27
 fontaxes.sty    2014/03/23 v1.0d Font selection axes
  xkeyval.sty    2006/11/18 v2.5f package option processing (HA)
  xkeyval.tex    2006/11/18 v2.5f key=value parser (HA)
 etoolbox.sty    2011/01/03 v2.1 e-TeX tools for LaTeX
     etex.sty    1998/03/26 v2.0 eTeX basic definition package (PEB)
  fontenc.sty
    t1enc.def    2005/09/27 v1.99g Standard LaTeX file
 textcomp.sty    2005/09/27 v1.99g Standard LaTeX package
   ts1enc.def    2001/06/05 v3.0e (jk/car/fm) Standard LaTeX file
newtxmath.sty    2014/04/26 v1.27
  amsmath.sty    2000/07/18 v2.13 AMS math features
  amstext.sty    2000/06/29 v2.01
   amsgen.sty    1999/11/30 v2.0
   amsbsy.sty    1999/11/29 v1.2d
   amsopn.sty    1999/12/14 v2.01 operator names
  ifxetex.sty    2010/09/12 v0.6 Provides ifxetex conditional
 ifluatex.sty    2010/03/01 v1.3 Provides the ifluatex switch (HO)
   binhex.tex
       bm.sty    2004/02/26 v1.1c Bold Symbol Support (DPC/FMi)
 subfiles.sty    2012/05/23 Federico Garcia
 verbatim.sty    2003/08/22 v1.5q LaTeX2e package for verbatim enhancements
 omlntxmi.fd    2012/03/22 Fontinst v1.933 font definitions for OML/ntxmi.
 omsntxsy.fd    2012/11/14 Fontinst v1.933 font definitions for OMS/ntxsy.
  untxexa.fd    2012/04/16 Fontinst v1.933 font definitions for U/ntxexa.
   ts1cmr.fd    1999/05/25 v2.5h Standard LaTeX font definitions
  t1ntxrx.fd    2012/12/25 v1.0
    sub1.tex
  untxmia.fd    2012/04/16 Fontinst v1.933 font definitions for U/ntxmia.
  untxsya.fd    2012/04/12 Fontinst v1.933 font definitions for U/ntxsya.
  untxsyb.fd    2012/04/12 Fontinst v1.933 font definitions for U/ntxsyb.
  untxsyc.fd    2012/04/12 Fontinst v1.933 font definitions for U/ntxsyc.
  ***********

After installing the latest TeX Live and removing my previously installed packages, the error remains and the log file gives

 *File List*
 report.cls    2007/10/19 v1.4h Standard LaTeX document class
 size10.clo    2007/10/19 v1.4h Standard LaTeX file (size option)
newtxtext.sty    2014/04/07 v1.25
fontaxes.sty    2014/03/23 v1.0d Font selection axes
xkeyval.sty    2012/10/14 v2.6b package option processing (HA)
 xkeyval.tex    2012/10/14 v2.6b key=value parser (HA)
etoolbox.sty    2011/01/03 v2.1 e-TeX tools for LaTeX
    etex.sty    1998/03/26 v2.0 eTeX basic definition package (PEB)
 fontenc.sty
  t1enc.def    2005/09/27 v1.99g Standard LaTeX file
textcomp.sty    2005/09/27 v1.99g Standard LaTeX package
  ts1enc.def    2001/06/05 v3.0e (jk/car/fm) Standard LaTeX file
newtxmath.sty    2014/04/07 v1.25
 amsmath.sty    2013/01/14 v2.14 AMS math features
 amstext.sty    2000/06/29 v2.01
  amsgen.sty    1999/11/30 v2.0
  amsbsy.sty    1999/11/29 v1.2d
  amsopn.sty    1999/12/14 v2.01 operator names
 ifxetex.sty    2010/09/12 v0.6 Provides ifxetex conditional
ifluatex.sty    2010/03/01 v1.3 Provides the ifluatex switch (HO)
  binhex.tex
      bm.sty    2004/02/26 v1.1c Bold Symbol Support (DPC/FMi)
subfiles.sty    2012/05/23 Federico Garcia
verbatim.sty    2003/08/22 v1.5q LaTeX2e package for verbatim enhancements
omlntxmi.fd    2012/03/22 Fontinst v1.933 font definitions for OML/ntxmi.
omsntxsy.fd    2012/11/14 Fontinst v1.933 font definitions for OMS/ntxsy.
 untxexa.fd    2012/04/16 Fontinst v1.933 font definitions for U/ntxexa.
  ts1cmr.fd    1999/05/25 v2.5h Standard LaTeX font definitions
 t1ntxrx.fd    2012/12/25 v1.0
    sub1.tex
 untxmia.fd    2012/04/16 Fontinst v1.933 font definitions for U/ntxmia.
 untxsya.fd    2012/04/12 Fontinst v1.933 font definitions for U/ntxsya.
 untxsyb.fd    2012/04/12 Fontinst v1.933 font definitions for U/ntxsyb.
 untxsyc.fd    2012/04/12 Fontinst v1.933 font definitions for U/ntxsyc.
 ***********

Inspired by the question Package incompatibilites: etoolbox, hyperref, and bm, standalone?, in etoolbox.sty I commented out

\patchcmd\enddocument
  {\deadcycles}
  {\let\AfterEndDocument\@firstofone
   \@afterenddocumenthook
   \deadcycles}
  {}
  {\let\etb@@end\@@end
   \def\@@end{%
     \let\AfterEndDocument\@firstofone
     \@afterenddocumenthook
     \etb@@end}}
{<environment>}{<code>}

This allows sub1.tex to be compiled on its own without error. This suggests that there is a conflict of the type described in the linked question.

  • 1
    Sorry, but I get no error. – egreg May 27 '14 at 18:06
  • 1
    I get no error with a blank line after $\bm{x}$ either. – egreg May 27 '14 at 20:29
  • Thank you for attempting to reproduce the problem. Could you share you log file so that I can compare it with mine? The fact that you can't reproduce it suggests there is a problem with my installation of the packages but the fact that the main file compiles as expected suggests otherwise. – Quarticle May 28 '14 at 08:44
  • Please, add \listfiles to your main document and report the relevant part of the .log file you get. – egreg May 28 '14 at 09:42
  • You have an old TeX distribution (report.cls has been last changed on 2007/10/19 and amsmath.sty on 2013/01/14, for instance). Adding the most recent version of newtx and subfiles to such an old distribution can expose to all kinds of problems. Update your TeX distribution, which seems to be eight years old. – egreg May 28 '14 at 10:39
  • I have installed the latest TeX Live distribution and the error remains. I have added the listfiles output. – Quarticle May 28 '14 at 20:58
  • Now the file list is the same, but I don't get any error. – egreg May 28 '14 at 21:23
  • Do you have any suggestions as to where the problem might be? – Quarticle May 28 '14 at 21:27
  • Sorry, no. An extraneous invisible character? – egreg May 28 '14 at 21:34
  • I do think it is a reproducible problem. I did a full install of TeX Live on a different computer. The only things I did were to install TeX Live and make the example files described. Running latex main.tex gives no problem. Running latex sub1.tex gives the error described. – Quarticle Jul 07 '14 at 14:43
  • The problem seems to be in newtxtext. – egreg Jul 07 '14 at 15:10

1 Answers1

5

the newtxtext package loads etoolbox package which redefines \@@end. It really shouldn't do that. Since it does you can do this to locally restore it.

\makeatletter
\let\@@@@@@end\@@end
\def\fixend{\let\@@end\@@@@@@end}
\makeatother
\documentclass[main]{subfiles}
\begin{document}
$\fixend\bm{x}$
\end{document}
David Carlisle
  • 757,742
  • 1
    Note that it's etoolbox that redefines \@@end – Joseph Wright Jul 07 '14 at 15:51
  • @JosephWright is it? OK thanks I'll re-apportion blame:-) – David Carlisle Jul 07 '14 at 15:55
  • Notice the patch: \patchcmd\enddocument {\deadcycles} {\let\AfterEndDocument\@firstofone \@afterenddocumenthook \deadcycles} {} {\let\etb@@end\@@end \def\@@end{% \let\AfterEndDocument\@firstofone \@afterenddocumenthook \etb@@end}} only alters \@@end if the initial patch of \enddocument fails. – Joseph Wright Jul 07 '14 at 15:57
  • @JosephWright presumably subfiles has made "only inside end document" to be rather more places:-) – David Carlisle Jul 07 '14 at 15:58
  • Slight correction: it only makes the change to \@@end if \enddocument has been altered, which is what happens with subfiles. – Joseph Wright Jul 07 '14 at 16:01