ArchiveOrangemail archive

XeTeX (Unicode-based TeX) discussion.


xetex.tug.org
(List home) (Recent threads) (32 other TeX Users Group lists)

Subscription Options

  • RSS or Atom: Read-only subscription using a browser or aggregator. This is the recommended way if you don't need to send messages to the list. You can learn more about feed syndication and clients here.
  • Conventional: All messages are delivered to your mail address, and you can reply. To subscribe, send an email to the list's subscribe address with "subscribe" in the subject line, or visit the list's homepage here.
  • Low traffic list: less than 3 messages per day
  • This list contains about 25,474 messages, beginning Apr 2004
  • 0 messages added yesterday
Report the Spam
This button sends a spam report to the moderator. Please use it sparingly. For other removal requests, read this.
Are you sure? yes no

Problem with apacite and fontspec

Ad
Diederick C. Niehorster 1222963781Thu, 02 Oct 2008 16:09:41 +0000 (UTC)
Dear Xetex Users,

I've just discovered XeteX and got very excited by it. So I decided to
practice and convert a work in progress from plain LateX to XeteX (well,
just add some fontspec stuff to select a different (OpenType) font). I ran
into the following problem:

When both the packages apacite and fontspec are loaded and I cite more than
one paper by the same authors from the same year, I get an error message
during compilation.

If I don't load either apacite (just use plainnat.bst with natbib) or
fontspec, this error does not occur.

The error message occurring is:

------

! Undefined control sequence.

\@calc at post@scan ...fi \fi \fi \fi \fi \calc at next

l.16 ...e item works fine: \citet{Wertheimer1967a}

------

This error is not specific to the two papers I cite in the example, it
occurs with others also.

Any ideas on how to fix this or is this a bug incompatibility in one of the
packages that has to be fixed?

Thanks,

Diederick

Example files:

------ natfonttest.tex (uncomment the line %However to reproduce the error)

\documentclass[12pt,a4paper]{article}

\usepackage[tocbib]{apacite}

\usepackage[sort]{natbib}

\usepackage{fontspec}   % provides font selecting commands

\title{Apacite Test}

\author{Me}

\begin{document}

\maketitle

\begin{abstract}

    Testing apacite with fontspec:

\end{abstract}

Citing items with the same author from the same year creates problems:

Citing one item works fine: \citet{Wertheimer1967a}.

%However, when citing more than one we run into problems:
\citet{Wertheimer1967b}.

The problem seems to be with the \verb \BCnt ~command that shows up when

siting more items from the same author and the same year.

\bibliographystyle{apacite}

\bibliography{natfonttest} 

\end{document}

------

------ natfonttest.bib

@INCOLLECTION{Wertheimer1967a,

  author = {Max Wertheimer},

  title = {Experimentelle {S}tudien \"uber das {S}ehen von {B}ewegung},

  booktitle = {Drei {A}bhandlungen zur {G}estalttheorie},

  publisher = {Wissenschaftliche Buchgesellschaft},

  year = {1967},

  pages = {1--105},

  address = {Darmstadt},

  edition = {2},

  originaljournal = {Zeitschrift f\"ur Psychologie},

  originalpages = {161--265},

  originalvolumee = {61},

  originalyear = {1912},

  owner = {Diederick},

  timestamp = {2008.05.10}

}

@INCOLLECTION{Wertheimer1967b,

  author = {Max Wertheimer},

  title = {\"{U}ber das {D}enken der {N}aturv\"olker, {Z}ahlen und
{Z}ahlgebilde},

  booktitle = {Drei {A}bhandlungen zur {G}estalttheorie},

  publisher = {Wissenschaftliche Buchgesellschaft},

  year = {1967},

  pages = {106--161},

  address = {Darmstadt},

  edition = {2},

  originaljournal = {Zeitschrift f\"ur Psychologie},

  originalpages = {321--378},

  originalvolumee = {60},

  originalyear = {1911},

  owner = {Diederick},

  timestamp = {2008.05.10}

}

------
Ross Moore 1222995845Fri, 03 Oct 2008 01:04:05 +0000 (UTC)
Hi Diedrick,
On 03/10/2008, at 2:09 AM, Diederick C. Niehorster wrote: > Dear Xetex Users, > > > > I?ve just discovered XeteX and got very excited by it. So I decided > to practice and convert a work in progress from plain LateX to > XeteX (well, just add some fontspec stuff to select a different > (OpenType) font). I ran into the following problem: > > When both the packages apacite and fontspec are loaded and I cite > more than one paper by the same authors from the same year, I get > an error message during compilation. > > If I don?t load either apacite (just use plainnat.bst with natbib) > or fontspec, this error does not occur. > > The error message occurring is: > > ------ > > ! Undefined control sequence. > > \@calc at post@scan ...fi \fi \fi \fi \fi \calc at next > > > > l.16 ...e item works fine: \citet{Wertheimer1967a} >
I've tested your example and found that the incompatibility is triggered by the use of the calc.sty package, which is loaded by fontspec.sty . More specifically, calc.sty changes the way \setcounter works. The programming in apacite.sty does not take this into account. The problem occurs when using \citet and other \cite command variants defined by natbib.sty , since these require significant extra parsing beyond what LaTeX would do without natbib . Here's a simple fix that seems to work: \usepackage[tocbib]{apacite} %% ---- RRM 2008/10/03 %% for compatibility with calc.sty %% we need an extra \protect as below before \setcounter %% \renewcommand{\BCnt}[1]{\protect\setcounter{BibCnt}{#1}\protect \theBibCnt} \renewcommand{\BCntIP}[1]{\protect\setcounter{BibCnt}{#1}\mbox{- \protect\theBibCnt}} \renewcommand{\BCntND}[1]{\protect\setcounter{BibCnt}{#1}\mbox{- \protect\theBibCnt}} \usepackage[sort]{natbib} %\usepackage{calc} \usepackage{fontspec} % provides font selecting commands ... This avoids \setcounter being expanded too early, at a place where it isn't actually being used. All still works correctly at the place where it *is* required. An alternative solution, and perhaps a better one, would be to have made the commands \BCnt \BCntIP \BCntND robust in the first place; e.g. apacite.sty should use \DeclareRobustCommand{\BCnt}[1]{\setcounter{BibCnt}{#1}\theBibCnt} \DeclareRobustCommand{\BCntIP}[1]{\setcounter{BibCnt}{#1}\mbox{- \theBibCnt}} \DeclareRobustCommand{\BCntND}[1]{\setcounter{BibCnt}{#1}\mbox{- \theBibCnt}} You can patch this solution cleanly into existing documents, as follows: \usepackage[tocbib]{apacite} \DeclareRobustCommand{\robustBCnt}[1]{\setcounter{BibCnt}{#1}\theBibCnt} \DeclareRobustCommand{\robustBCntIP}[1]{\setcounter{BibCnt}{#1}\mbox{- \theBibCnt}} \DeclareRobustCommand{\robustBCntND}[1]{\setcounter{BibCnt}{#1}\mbox{- \theBibCnt}} \let\BCnt\robustBCnt \let\BCntIP\robustBCntIP \let\BCntND\robustBCntND \usepackage[sort]{natbib} %\usepackage{calc} \usepackage{fontspec} % provides font selecting commands ... Furthermore, if a future version of apacite.sty makes its own fix, as suggested above, then documents with this modification should continue to work properly. However, a danger is if \BCnt \BCntIP \BCntND are changed in a *different way*, to solve this or any other problem. This analysis is based on: \ProvidesPackage{apacite} [2007/09/03 v4.00 APA citation] which is the latest version available at CTAN.
> ------ > > > > This error is not specific to the two papers I cite in the example, > it occurs with others also. > > Any ideas on how to fix this or is this a bug incompatibility in > one of the packages that has to be fixed? >
Hope this helps, Ross
> > > Thanks, > > Diederick >
Erik Meijer 1223006092Fri, 03 Oct 2008 03:54:52 +0000 (UTC)
Diederick, Ross,

Thanks for pointing this out and solving it. The next release of
apacite will include this improvement and a few other bug fixes.
I hope I'll be able to upload it soon.

Note that (as indicated in the latest release of apacite) my current
email address is apacite at gmail.com

Thanks,
Erik
Ross Moore wrote: > Hi Diedrick, > > On 03/10/2008, at 2:09 AM, Diederick C. Niehorster wrote: > >> Dear Xetex Users, >> >> >> >> I?ve just discovered XeteX and got very excited by it. So I decided >> to practice and convert a work in progress from plain LateX to XeteX >> (well, just add some fontspec stuff to select a different (OpenType) >> font). I ran into the following problem: >> >> When both the packages apacite and fontspec are loaded and I cite >> more than one paper by the same authors from the same year, I get an >> error message during compilation. >> >> If I don?t load either apacite (just use plainnat.bst with natbib) or >> fontspec, this error does not occur. >> >> The error message occurring is: >> >> ------ >> >> ! Undefined control sequence. >> >> \@calc at post@scan ...fi \fi \fi \fi \fi \calc at next >> >> >> >> l.16 ...e item works fine: \citet{Wertheimer1967a} >> > > I've tested your example and found that the incompatibility > is triggered by the use of the calc.sty package, > which is loaded by fontspec.sty . > > > More specifically, calc.sty changes the way \setcounter works. > The programming in apacite.sty does not take this into account. > The problem occurs when using \citet and other \cite command variants > defined by natbib.sty , since these require significant extra parsing > beyond what LaTeX would do without natbib . > > > Here's a simple fix that seems to work: > > > \usepackage[tocbib]{apacite} > %% ---- RRM 2008/10/03 > %% for compatibility with calc.sty > %% we need an extra \protect as below before \setcounter > %% > \renewcommand{\BCnt}[1]{\protect\setcounter{BibCnt}{#1}\protect \theBibCnt} > \renewcommand{\BCntIP}[1]{\protect\setcounter{BibCnt}{#1}\mbox{- > \protect\theBibCnt}} > \renewcommand{\BCntND}[1]{\protect\setcounter{BibCnt}{#1}\mbox{- > \protect\theBibCnt}} > > \usepackage[sort]{natbib} > %\usepackage{calc} > \usepackage{fontspec} % provides font selecting commands > ... > > > This avoids \setcounter being expanded too early, at a place > where it isn't actually being used. > All still works correctly at the place where it *is* required. > > > > An alternative solution, and perhaps a better one, would be > to have made the commands \BCnt \BCntIP \BCntND robust > in the first place; e.g. apacite.sty should use > > \DeclareRobustCommand{\BCnt}[1]{\setcounter{BibCnt}{#1}\theBibCnt} > \DeclareRobustCommand{\BCntIP}[1]{\setcounter{BibCnt}{#1}\mbox{- > \theBibCnt}} > \DeclareRobustCommand{\BCntND}[1]{\setcounter{BibCnt}{#1}\mbox{- > \theBibCnt}} > > > You can patch this solution cleanly into existing documents, > as follows: > > > \usepackage[tocbib]{apacite} > \DeclareRobustCommand{\robustBCnt}[1]{\setcounter{BibCnt}{#1}\theBibCnt} > \DeclareRobustCommand{\robustBCntIP}[1]{\setcounter{BibCnt}{#1}\mbox{- > \theBibCnt}} > \DeclareRobustCommand{\robustBCntND}[1]{\setcounter{BibCnt}{#1}\mbox{- > \theBibCnt}} > \let\BCnt\robustBCnt > \let\BCntIP\robustBCntIP > \let\BCntND\robustBCntND > > \usepackage[sort]{natbib} > %\usepackage{calc} > \usepackage{fontspec} % provides font selecting commands > ... > > > Furthermore, if a future version of apacite.sty makes its own fix, > as suggested above, then documents with this modification should continue > to work properly. However, a danger is if \BCnt \BCntIP \BCntND > are changed in a *different way*, to solve this or any other problem. > > > This analysis is based on: > > \ProvidesPackage{apacite} > [2007/09/03 v4.00 APA citation] > > which is the latest version available at CTAN. > > > > >> ------ >> >> >> >> This error is not specific to the two papers I cite in the example, >> it occurs with others also. >> >> Any ideas on how to fix this or is this a bug incompatibility in one >> of the packages that has to be fixed? >> > > > Hope this helps, > > Ross > >> >> >> Thanks, >> >> Diederick >> > > ------------------------------------------------------------------------ > Ross Moore ross at maths.mq.edu.au > Mathematics Department office: E7A-419 > Macquarie University tel: +61 (0)2 9850 8955 > Sydney, Australia 2109 fax: +61 (0)2 9850 8114 > ------------------------------------------------------------------------ > > > >
Will Robertson 1223011700Fri, 03 Oct 2008 05:28:20 +0000 (UTC)
On 03/10/2008, at 1:24 PM, Erik Meijer wrote: > Thanks for pointing this out and solving it. The next release of > apacite will include this improvement and a few other bug fixes. > I hope I'll be able to upload it soon.
While I think of it, this might also be solved by an upcoming release
of the calc package; Morten would know more. Here's what he wrote a few months ago about a similar problem: > I am thinking that fontspec has nothing to do with this but rather the > calc package as termcal uses \relax quite a bit to terminate numbers. > > And I also think that I fixed that infelicity in calc some time ago > - it > just hasn't been released yet. > > Here are some excerpts from the new documentation: > > % When \TeX\ is scanning for a \<number> etc.\ it is > % common to terminate the scanning with a space token or by inserting > % \cs{relax}. As of version~4.3 \textsf{calc} allows \cs{relax} tokens > % to appear in places where they would usually be used for terminating > % \TeX's scanning. In short this is just before any of \texttt{+-*/)} > % or at the end of the expression being evaluated. > > % \changes{v4.3}{2007/08/22}{Discard terminating \cs{relax} tokens and > % avoid extra error message from \cs{calc at next}} > > > And the changed code is just this single macro: > > \def\@calc at post@scan#1{% > \ifx#1!\let\calc at next\endgroup \else > \ifx#1+\let\calc at next\calc at add \else > \ifx#1-\let\calc at next\calc at subtract \else > \ifx#1*\let\calc at next\calc at multiplyx \else > \ifx#1/\let\calc at next\calc at dividex \else > \ifx#1)\let\calc at next\calc at close \else > \ifx#1\relax\let\calc at next\calc at post@scan \else > \def\calc at next{\calc at error#1}% > \fi > \fi > \fi > \fi > \fi > \fi > \fi > \calc at next} > > > Try adding this to your preamble after loading fontspec (and > wrapping it > in \makeatletter and \makeatother of course)
Hope this helps, Will
Ross Moore 1223017411Fri, 03 Oct 2008 07:03:31 +0000 (UTC)
Hi Will,
On 03/10/2008, at 3:28 PM, Will Robertson wrote: > On 03/10/2008, at 1:24 PM, Erik Meijer wrote: > >> Thanks for pointing this out and solving it. The next release of >> apacite will include this improvement and a few other bug fixes. >> I hope I'll be able to upload it soon. > > While I think of it, this might also be solved by an upcoming release > of the calc package; Morten would know more. Here's what he wrote a > few months ago about a similar problem:
No; it is a different problem altogether...
>> And the changed code is just this single macro: >> >> \def\@calc at post@scan#1{%
... I've tried with this change, but it isn't the cause of the problem. The coding should never get as far as calling any of these \@calc at .... internals. It is failing while natbib is parsing the info it needs in deciding what kind of citation it is going to display. The lack of robustness of an APAcite macro causes premature expansions, ultimately leading to the crash. Indeed, it encounters all sorts of assignments while simply expanding macros for pattern-matching. So something has to go wrong eventually, and its \@calc at post@scan that first throws up an error message.
>> \ifx#1!\let\calc at next\endgroup \else >> \ifx#1+\let\calc at next\calc at add \else >> \ifx#1-\let\calc at next\calc at subtract \else >> \ifx#1*\let\calc at next\calc at multiplyx \else >> \ifx#1/\let\calc at next\calc at dividex \else >> \ifx#1)\let\calc at next\calc at close \else >> \ifx#1\relax\let\calc at next\calc at post@scan \else >> \def\calc at next{\calc at error#1}% >> \fi >> \fi >> \fi >> \fi >> \fi >> \fi >> \fi >> \calc at next} >> >> >> Try adding this to your preamble after loading fontspec (and >> wrapping it >> in \makeatletter and \makeatother of course) > > Hope this helps,
Nice thought, that maybe fixing one error might also prevent others --- just not this time. > Will Cheers, Ross
Will Robertson 1223022312Fri, 03 Oct 2008 08:25:12 +0000 (UTC)
On 03/10/2008, at 4:33 PM, Ross Moore wrote: > Nice thought, that maybe fixing one error might also > prevent others --- just not this time.
Ah well :) This second message seemed to have some similarities but I should have looked into it in more detail. Thanks for your quick and insightful analysis! W
Morten H√łgholm 1223024521Fri, 03 Oct 2008 09:02:01 +0000 (UTC)
On Fri, Oct 3, 2008 at 3:04 AM, Ross Moore  wrote:

Hi all,
> More specifically, calc.sty changes the way \setcounter works. > The programming in apacite.sty does not take this into account. > The problem occurs when using \citet and other \cite command variants > defined by natbib.sty , since these require significant extra parsing > beyond what LaTeX would do without natbib . > > > Here's a simple fix that seems to work: > > > \usepackage[tocbib]{apacite} > %% ---- RRM 2008/10/03 > %% for compatibility with calc.sty > %% we need an extra \protect as below before \setcounter > %%
Which makes me think that I cannot recall why \setcounter et al. are not automatically robust. Well, most likely candidate is that it is documented as fragile in Lamport but I can't see the harm in a little robustification at this point (most of the kernel is robust now)... People \protect'ing \setcounter won't note the difference anyway. In my book all assignment commands ought to be robust when TeX is so picky about assignments in an expandable context.
Diederick C. Niehorster 1223049605Fri, 03 Oct 2008 16:00:05 +0000 (UTC)
Hi Ross,

Your solution(s) indeed seem to have fixed the problem here also.

Thanks to all the others for jumping in on this thread so quickly!

Thanks again,
Diederick
> -----Original Message----- > From: Diederick C. Niehorster
> -----Original Message----- > From: Diederick C. Niehorster Ross Moore > Sent: Friday, October 03, 2008 9:04 AM > To: Unicode-based TeX for Mac OS X and other platforms > Subject: Re: [XeTeX] Problem with apacite and fontspec > > Hi Diedrick, > > On 03/10/2008, at 2:09 AM, Diederick C. Niehorster wrote: > > > Dear Xetex Users, > > > > > > > > I've just discovered XeteX and got very excited by it. So I decided > > to practice and convert a work in progress from plain LateX to > > XeteX (well, just add some fontspec stuff to select a different > > (OpenType) font). I ran into the following problem: > > > > When both the packages apacite and fontspec are loaded and I cite > > more than one paper by the same authors from the same year, I get > > an error message during compilation. > > > > If I don't load either apacite (just use plainnat.bst with natbib) > > or fontspec, this error does not occur. > > > > The error message occurring is: > > > > ------ > > > > ! Undefined control sequence. > > > > \@calc at post@scan ...fi \fi \fi \fi \fi \calc at next > > > > > > > > l.16 ...e item works fine: \citet{Wertheimer1967a} > > > > I've tested your example and found that the incompatibility > is triggered by the use of the calc.sty package, > which is loaded by fontspec.sty . > > > More specifically, calc.sty changes the way \setcounter works. > The programming in apacite.sty does not take this into account. > The problem occurs when using \citet and other \cite command variants > defined by natbib.sty , since these require significant extra parsing > beyond what LaTeX would do without natbib . > > > Here's a simple fix that seems to work: > > > \usepackage[tocbib]{apacite} > %% ---- RRM 2008/10/03 > %% for compatibility with calc.sty > %% we need an extra \protect as below before \setcounter > %% > \renewcommand{\BCnt}[1]{\protect\setcounter{BibCnt}{#1}\protect > \theBibCnt} > \renewcommand{\BCntIP}[1]{\protect\setcounter{BibCnt}{#1}\mbox{- > \protect\theBibCnt}} > \renewcommand{\BCntND}[1]{\protect\setcounter{BibCnt}{#1}\mbox{- > \protect\theBibCnt}} > > \usepackage[sort]{natbib} > %\usepackage{calc} > \usepackage{fontspec} % provides font selecting commands > ... > > > This avoids \setcounter being expanded too early, at a place > where it isn't actually being used. > All still works correctly at the place where it *is* required. > > > > An alternative solution, and perhaps a better one, would be > to have made the commands \BCnt \BCntIP \BCntND robust > in the first place; e.g. apacite.sty should use > > \DeclareRobustCommand{\BCnt}[1]{\setcounter{BibCnt}{#1}\theBibCnt} > \DeclareRobustCommand{\BCntIP}[1]{\setcounter{BibCnt}{#1}\mbox{- > \theBibCnt}} > \DeclareRobustCommand{\BCntND}[1]{\setcounter{BibCnt}{#1}\mbox{- > \theBibCnt}} > > > You can patch this solution cleanly into existing documents, > as follows: > > > \usepackage[tocbib]{apacite} > \DeclareRobustCommand{\robustBCnt}[1]{\setcounter{BibCnt}{#1}\theBibCnt} > \DeclareRobustCommand{\robustBCntIP}[1]{\setcounter{BibCnt}{#1}\mbox{- > \theBibCnt}} > \DeclareRobustCommand{\robustBCntND}[1]{\setcounter{BibCnt}{#1}\mbox{- > \theBibCnt}} > \let\BCnt\robustBCnt > \let\BCntIP\robustBCntIP > \let\BCntND\robustBCntND > > \usepackage[sort]{natbib} > %\usepackage{calc} > \usepackage{fontspec} % provides font selecting commands > ... > > > Furthermore, if a future version of apacite.sty makes its own fix, > as suggested above, then documents with this modification should > continue > to work properly. However, a danger is if \BCnt \BCntIP \BCntND > are changed in a *different way*, to solve this or any other problem. > > > This analysis is based on: > > \ProvidesPackage{apacite} > [2007/09/03 v4.00 APA citation] > > which is the latest version available at CTAN. > > > > > > ------ > > > > > > > > This error is not specific to the two papers I cite in the example, > > it occurs with others also. > > > > Any ideas on how to fix this or is this a bug incompatibility in > > one of the packages that has to be fixed? > > > > > Hope this helps, > > Ross > > > > > > > Thanks, > > > > Diederick > > > > ------------------------------------------------------------------------ > Ross Moore ross at maths.mq.edu.au > Mathematics Department office: E7A-419 > Macquarie University tel: +61 (0)2 9850 8955 > Sydney, Australia 2109 fax: +61 (0)2 9850 8114 > ------------------------------------------------------------------------ > > > > _______________________________________________ > XeTeX mailing list > postmaster at tug.org > http://tug.org/mailman/listinfo/xetex
Home | About | Privacy