Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Memoir's pagenotes fail with Lyx

41 views
Skip to first unread message

stefano

unread,
Dec 3, 2010, 11:47:09 AM12/3/10
to lyx-...@lyx.org
I think I have stumbled upon an incompatibility between memoir and
Lyx. Memoir uses the \pagenote command to produce endnotes. However,
pagenote fails when the text of the pagenote has a comment sign (i.e.
'%') before the closing brace. Which is exactly how Lyx produces
footnotes:
Minimal example:

\documentclass[a4paper,10pt]{memoir}
\usepackage[english]{babel}
\makepagenote
\begin{document}
1. This works\pagenote{This is a pagenote}
2 This fails\pagenote{This is a pagenote%
}
\printpagenotes
\end{document}

The second format is how Lyx exports to latex.

Any idea on how to solve the problem is welcome.


Cheers,

Stefano

Lars Madsen

unread,
Dec 3, 2010, 11:56:34 AM12/3/10
to

hmm, that is interesting, I'll see what I can do

--

/daleif (remove RTFSIGNATURE from email address)

LaTeX FAQ: http://www.tex.ac.uk/faq
LaTeX book: http://www.imf.au.dk/system/latex/bog/ (in Danish)
Remember to post minimal examples, see URL below
http://www.tex.ac.uk/cgi-bin/texfaq2html?label=minxampl
http://www.minimalbeispiel.de/mini-en.html

Lars Madsen

unread,
Dec 3, 2010, 12:08:26 PM12/3/10
to
Lars Madsen wrote:
> stefano wrote:
>> I think I have stumbled upon an incompatibility between memoir and
>> Lyx. Memoir uses the \pagenote command to produce endnotes. However,
>> pagenote fails when the text of the pagenote has a comment sign (i.e.
>> '%') before the closing brace. Which is exactly how Lyx produces
>> footnotes:
>> Minimal example:
>>
>> \documentclass[a4paper,10pt]{memoir}
>> \usepackage[english]{babel}
>> \makepagenote
>> \begin{document}
>> 1. This works\pagenote{This is a pagenote}
>> 2 This fails\pagenote{This is a pagenote%
>> }
>> \printpagenotes
>> \end{document}
>>
>> The second format is how Lyx exports to latex.
>>
>> Any idea on how to solve the problem is welcome.
>>
>>
>> Cheers,
>>
>> Stefano
>>
>
> hmm, that is interesting, I'll see what I can do
>

very interesting it is caused by \@sanitize which is used when we write
the pagenote to file, so we end up with

\noteentry{2}{}{This is a pagenote% }{1}

which of course crashes everything when LaTeX attempts to run the .ent file.

Short term fix

\makeatletter
\renewcommand*{\makepagenote}{%
\newwrite\@notefile
\immediate\openout\@notefile=\jobname.ent
\mempagenotestrue
\def\pagenote{\@bsphack\begingroup
% \@sanitize
\m@m@wrpnote}%
\typeout{Writing note file \jobname.ent}%
\let\makepagenote\@empty}
\makeatother

\makepagenote

stefano

unread,
Dec 3, 2010, 12:25:39 PM12/3/10
to

Thanks Lars.

Problem solved for now, I guess.

Stefano

stefano

unread,
Dec 3, 2010, 2:47:14 PM12/3/10
to
> > Remember to post minimal examples, see URL belowhttp://www.tex.ac.uk/cgi-bin/texfaq2html?label=minxamplhttp://www.min...

>
> Thanks Lars.
>
> Problem solved for now, I guess.
>
> Stefano

I spoke too early. With the \@sanitize line commented out, \pagenote
fails when there is an index command in the note's body. With the
\@sanitize line uncommented, the \index command works fine (but it
fails in Lyx, of course). A \protect command in front of the \index
command seems to work (although it may break something else. I am
never sure with LaTeX).
I confess I have no idea why it fails and why it works with protect.


Stefano

Example:


\documentclass[a4paper,10pt]{memoir}
\usepackage[english]{babel}

\makeatletter
\renewcommand*{\makepagenote}{%
\newwrite\@notefile
\immediate\openout\@notefile=\jobname.ent
\mempagenotestrue
\def\pagenote{\@bsphack\begingroup
% \@sanitize
\m@m@wrpnote}%
\typeout{Writing note file \jobname.ent}%
\let\makepagenote\@empty}
\makeatother

\makeindex
\makepagenote
\begin{document}
1. This note fails unless a protect command is placed in forn of the
index command \pagenote{This is a pagenote\index{instruments, logical}
%
}

\printpagenotes
\printindex
\end{document}

Error:

No file pagenote-test.aux.
! Use of \\m@m@wrpnote doesn't match its definition.
\@ifnextchar ... \reserved@d =#1\def \reserved@a {
#2}\def \reserved@b
{#3}\f...
l.20 }


Lars Madsen

unread,
Dec 5, 2010, 11:22:35 AM12/5/10
to

better solution: sanitize, but not %

\renewcommand*{\makepagenote}{%
\newwrite\@notefile
\immediate\openout\@notefile=\jobname.ent
\mempagenotestrue
\def\pagenote{\@bsphack\begingroup

\rem@special{\%}% <--- added
\@sanitize
\m@m@wrpnote}%

/daleif


stefano

unread,
Dec 7, 2010, 10:38:06 AM12/7/10
to

Thanks Dale,

that works. I think I have stumbled upon a possibly related
problem, though.
While pagenote works fine if an unprotected \index command is in the
text of the note,
the combinaiton of \foottopagenote and \footnote does not work in the
same situation.


Cheers,

Stefano
Example:
\documentclass[a4paper,10pt]{memoir}
\usepackage[english]{babel}

\usepackage{lipsum}
%Fix to Lyx export problem, suggested by Lars Madsen on c.t.t. on
12/6/2010


\makeatletter
\renewcommand*{\makepagenote}{%
\newwrite\@notefile
\immediate\openout\@notefile=\jobname.ent
\mempagenotestrue
\def\pagenote{\@bsphack\begingroup

\rem@special{\%}% <--- added
\@sanitize
\m@m@wrpnote}%

\typeout{Writing note file \jobname.ent}%
\let\makepagenote\@empty}

\foottopagenote
\makeindex
\makepagenote
\begin{document}
1. This note works fine\pagenote{\index{word}\lipsum[1]%
}

2. This one fails unless I protect the index command
\footnote{\index{word}\lipsum[2]%
}
\printpagenotes
\end{document}


Writing note file pagenote-test.ent
(./pagenote-test.aux)


! Use of \\m@m@wrpnote doesn't match its definition.
\@ifnextchar ... \reserved@d =#1\def \reserved@a {
#2}\def \reserved@b
{#3}\f...

l.25 }

Lars Madsen

unread,
Dec 7, 2010, 10:56:17 AM12/7/10
to
interesting

--

/daleif (remove RTFSIGNATURE from email address)

stefano

unread,
Dec 7, 2010, 2:28:32 PM12/7/10
to
> >>>>> LaTeX book:    http://www.imf.au.dk/system/latex/bog/(in Danish)

Something even more interesting
multiparagraph footnotes now fail.
:-(

\documentclass[a4paper,10pt]{memoir}
\usepackage[english]{babel}

\usepackage{lipsum}
%Fix to Lyx export problem, suggested by Lars Madsen on c.t.t. on
12/6/2010

\makeatletter
\renewcommand*{\makepagenote}{%
\newwrite\@notefile
\immediate\openout\@notefile=\jobname.ent
\mempagenotestrue
\def\pagenote{\@bsphack\begingroup

\rem@special{\%}% <--- added
\@sanitize
\m@m@wrpnote}%

\typeout{Writing note file \jobname.ent}%
\let\makepagenote\@empty}

\foottopagenote
\makeindex
\makepagenote
\begin{document}


1. This note works fine\pagenote{\index{word}\lipsum[1]%
}

2. This one fails unless I protect the index command\footnote{\protect


\index{word}\lipsum[2]%

\lipsum[3]}
\printpagenotes
\end{document}

output:

{\protect \index {word}\lipsum [2]
! Paragraph ended before \\footnote was complete.
<to be read again>
\par
l.25

Lars Madsen

unread,
Dec 7, 2010, 5:22:12 PM12/7/10
to

that one is because \foottopagenote mistakenly does not redefine
\footnote as \long, I'll fix that

still wondering about the \index stuff


stefano

unread,
Dec 8, 2010, 2:53:44 PM12/8/10
to

Hi Lars,

I am trying to fix the \long issue. Would the following be sufficient
(it seems to work) or am I in dager of breaking something else:


\renewcommand{\foottopagenote}{%
\let\memsavefootnote\footnote
\renewcommand{\footnote}[2][]{\pagenote{##2}}}

As you can see, I simply removed the stars> Not sure if that's all
that's needed.

Cheers,

Stefano

Lars Madsen

unread,
Dec 8, 2010, 4:45:59 PM12/8/10
to
> Hi Lars,
>
> I am trying to fix the \long issue. Would the following be sufficient
> (it seems to work) or am I in dager of breaking something else:
>
>
> \renewcommand{\foottopagenote}{%
> \let\memsavefootnote\footnote
> \renewcommand{\footnote}[2][]{\pagenote{##2}}}
>
> As you can see, I simply removed the stars> Not sure if that's all
> that's needed.
>

it will fix the long issue, thus allowing multiple paragraphs again. But
it will not help with the other problems.

In our case we want to kill off the optional argument for \footnote (as
it does not make much sense in this context). But because of the
\@santize inside \pagenote we cannot make a construction like the one
above (thanks to Joseph Wright for exaplaining that for me).

I'm done some testing test and it seems that a special internal version
of \pagenote is needed, one that takes an optional argument but ignores it.

Then this seems to work

\renewcommand\footnote{\mem@special@pagenote}

(a \let might be enough)

I'll implement this approach and plan to release this coming weekend.

There will still be some open issues with longtable captions that will
not make it for this release.

/daleif

stefano

unread,
Dec 9, 2010, 12:18:50 AM12/9/10
to

Great, thanks. I'll be waiting for the release, then.

Cheers,

Stefano

Lars Madsen

unread,
Dec 9, 2010, 3:36:38 PM12/9/10
to

There is more or less what I'm going to do (with better names), please test

\documentclass[a4paper,10pt,oneside]{memoir}
\usepackage{lipsum}
\makeatletter
% special version that ignores the optional argument
\newcommand{\m@m@wrpnote@special}[2][]{%
\refstepcounter{pagenote}%
\mem@multiple@marker{\notenumintext{\thepagenote}}%
\ifm@mpn@new@chap
\global\m@mpn@new@chapfalse
\addtonotes{\string\pagenotesubhead{\@chapapp}{\thechapter}{\pnchap}}%
\fi
\ifm@mpn@new@schap
\global\m@mpn@new@schapfalse
\addtonotes{\string\pagenotesubhead{\@chapapp}{}{\pnschap}}%
\fi
\m@m@pnwrite\@notefile{}
{\string\noteentry{\thepagenote}{}{#2}{\thepage}}%
\endgroup
\@esphack}

\renewcommand*{\makepagenote}{%
\newwrite\@notefile
\immediate\openout\@notefile=\jobname.ent
\mempagenotestrue
\def\pagenote{\@bsphack\begingroup
\rem@special{\%}% <--- added
\@sanitize
\m@m@wrpnote}%

\def\mem@special@pagenote{\@bsphack\begingroup


\rem@special{\%}% <--- added
\@sanitize

\m@m@wrpnote@special}%


\typeout{Writing note file \jobname.ent}%
\let\makepagenote\@empty}

\def\pagenote{\@bsphack\begingroup \@sanitize\m@m@pagenote}
\def\mem@special@pagenote{\@bsphack\begingroup \@sanitize\m@m@pagenote}

\renewcommand*{\foottopagenote}{%
\let\memsavefootnote\footnote
\renewcommand\footnote\mem@special@pagenote
}

\makeatother


\foottopagenote

\makepagenote
\makeindex

\begin{document}

A\footnote{No1 xxx}

X\footnote{No2 \lipsum[1-2]\index{test}}


Y\footnote{No3 \lipsum[1]%
}

XX\pagenote{No4 \lipsum[1-2]\index{test2}}

YY\pagenote{No5 \lipsum[1]%
}

\printpagenotes
\printindex

\end{document}

stefano

unread,
Dec 10, 2010, 9:06:45 AM12/10/10
to

Hi Lars,

the example you enclosed does not compile on my system. Perhaps there
is a misspelling or syntax error somewhere I cannot spot?
Output:

! Undefined control sequence.
\\m@m@wrpnote@special ...ote}\mem@multiple@marker
{\notenumintext
{\thepagen...
l.47 A\footnote{No1 xxx}

Lars Madsen

unread,
Dec 10, 2010, 9:24:29 AM12/10/10
to

My bad

\makeatletter
\newcommand{\mem@multiple@marker}[1]{%
\leavevmode
\ifhmode
\edef\@x@sf{\the\spacefactor}%
\m@mmf@check
\nobreak
\fi
#1%
\m@mmf@prepare
\ifhmode\spacefactor\@x@sf\fi
\relax}
\makeatother

it will ensure that X\pagenote{..}\pagenote{..} result in X^{1,2} and
not X^{12}


--

/daleif (remove RTFSIGNATURE from email address)

stefano

unread,
Dec 10, 2010, 10:02:26 AM12/10/10
to

Hi Lars,

I tested the patch on my book (about 200,000 words) after removing all
the \protect commands in front of \index and it compiled without a
flaw. There are several multi-paragraphs footnotes.

I haven't had time to check page py page yet. I'll let you know if
anything comes up. But it looks reat so far.

Many thanks,

Stefano

stefano

unread,
Dec 10, 2010, 12:47:30 PM12/10/10
to
> > Remember to post minimal examples, see URL belowhttp://www.tex.ac.uk/cgi-bin/texfaq2html?label=minxamplhttp://www.min...

>
> Hi Lars,
>
> I tested the patch on my book (about 200,000 words) after removing all
> the \protect commands in front of \index and it compiled without a
> flaw. There are several multi-paragraphs footnotes.
>
> I haven't had time to check page py page yet. I'll let you know if
> anything comes up. But it looks reat so far.
>
> Many thanks,
>
> Stefano

Well, I found a problem. The percent sign (that is, \%) throws an
error.
Try a footnote (or pagenote, I tried both) as simple as:

\footnote{1\%}

Result:

Runaway argument?
{1\X\footnote{No2 \lipsum[1-2]\index{test}} Y\footnote{No3
\lipsum[1]\ETC.
! File ended while scanning use of \\m@m@wrpnote@special.
<inserted text>
\par
<*> pagenote-test-L-M.tex


Lars Madsen

unread,
Dec 12, 2010, 11:18:45 AM12/12/10
to

sigh

/daleif

Lars Madsen

unread,
Dec 13, 2010, 4:27:39 AM12/13/10
to

>
> sigh
>
> /daleif

in order to not delay the memoir update even further, I think I'll have
to remove the 'fix' for your

\pagenote{test%
test}

problem.

In general I think it is more likely that someone writes \% than % in a
footnote or pagenote.

The problem (verbatim writing) is not easy to solve (not without help
anyway).

So the problem will properly need quite a lot of recooding which takes
takes. Sorry.


--

/daleif (remove RTFSIGNATURE from email address)

stefano

unread,
Dec 13, 2010, 10:44:05 AM12/13/10
to

Well, I guess you are right about the relative frequencies of % and \%
However, that means memoir's pagenotes will not be usable from within
LyX.
I am happy with the intermediate step in your fixes, namely the one
that let me use Lyx's footnotes, althuogh it requires \protect
commands before \index in the footnotes. I am referring to this piece
of code, which is what I am currently using:


% % Fix to Lyx export problem, suggested by Lars Madsen on c.t.t. on
12/6/2010


\renewcommand*{\makepagenote}{%
\newwrite\@notefile
\immediate\openout\@notefile=\jobname.ent
\mempagenotestrue
\def\pagenote{\@bsphack\begingroup
\rem@special{\%}% <--- added
\@sanitize
\m@m@wrpnote}%

\typeout{Writing note file \jobname.ent}%
\let\makepagenote\@empty}

\makepagenote


\renewcommand{\foottopagenote}{%
\let\memsavefootnote\footnote
\renewcommand{\footnote}[2][]{\pagenote{##2}}}

\foottopagenote % Comment out for
separate endnotes and footnotes


I have two questions:

1. Will it still work with the fix to memoir you are preparing?

2. If so, is it ok if I post it on the Lyx wiki as temporary patch to
the memoir/LyX/pagenote problem?

Cheers,

Stefano

Lars Madsen

unread,
Dec 13, 2010, 5:40:10 PM12/13/10
to
On 2010-12-13 16:44, stefano wrote:

the \rem@special{\%} is the one giving the problem

for now I would prefer to wait publishing anything.

I will delay the release until next week and see if we can come up with
something, perhaps even reimplementing the entire system. The endnotes
package use a different approach that is rather interesting. I think it
will be adaptable for memoir.

/daleif


stefano

unread,
Dec 13, 2010, 6:16:34 PM12/13/10
to
On Dec 13, 4:40 pm, Lars Madsen <dal...@imf.au.dk> wrote:
> On 2010-12-13 16:44, stefano wrote:
>
>
>
>
>
>
>
>
>
> > On Dec 13, 3:27 am, Lars Madsen<dal...@RTFMSIGNATUREimf.au.dk>  wrote:
> >>> sigh
>
> >>> /daleif
>
> >> in order to not delay the memoir update even further, I think I'll have
> >> to remove the 'fix' for your
>
> >> \pagenote{test%
> >> test}
>
> >> problem.
>
> >> In general I think it is more likely that someone writes \% than % in a
> >> footnote or pagenote.
>
> >> The problem (verbatim writing) is not easy to solve (not without help
> >> anyway).
>
> >> So the problem will properly need quite a lot of recooding which takes
> >> takes. Sorry.
>
> >> --
>
> >> /daleif (remove RTFSIGNATURE from email address)
>
> >> LaTeX FAQ:      http://www.tex.ac.uk/faq
> >> LaTeX book:    http://www.imf.au.dk/system/latex/bog/  (in Danish)
> >> Remember to post minimal examples, see URL belowhttp://www.tex.ac.uk/cgi-bin/texfaq2html?label=minxamplhttp://www.min...

Ok. I'll wait, it sounds wiser.

Cheers,

Stefano

Lars Madsen

unread,
Dec 13, 2010, 6:25:52 PM12/13/10
to

there might not be much reason in continuing this discussion on this
list. Drop me an email, then I can use you for testing ideas.

/daleif

0 new messages