From 579393fbc807c3162619b3e366e74d12c1004d96 Mon Sep 17 00:00:00 2001 From: Juergen Spitzmueller Date: Tue, 13 Aug 2019 07:30:20 +0200 Subject: [PATCH] Add support for the enotez package This is a modern implementation of endnotes building on LaTeX3 tools which gets away with deficiencies of the endnotes package, has some extra features, is localized, supports hyperref and is better customizable. As this is a fairly new package requiring l3, we keep the old endnotes module and provide this as an alternative. --- development/FORMAT | 5 +- lib/Makefile.am | 2 + lib/chkconfig.ltx | 1 + lib/doc/LaTeXConfig.lyx | 188 +++++++++++++++++++++++++++++++- lib/layouts/endnotes.module | 9 +- lib/layouts/enotez.module | 40 +++++++ lib/layouts/foottoend.module | 9 +- lib/layouts/foottoenotez.module | 30 +++++ lib/lyx2lyx/lyx_2_4.py | 33 +++++- src/LaTeX.cpp | 4 + src/LaTeXFeatures.cpp | 1 + src/tex2lyx/text.cpp | 5 +- 12 files changed, 316 insertions(+), 11 deletions(-) create mode 100644 lib/layouts/enotez.module create mode 100644 lib/layouts/foottoenotez.module diff --git a/development/FORMAT b/development/FORMAT index 8bb4a3ae3e..ffecd54693 100644 --- a/development/FORMAT +++ b/development/FORMAT @@ -8,8 +8,9 @@ changes happened in particular if possible. A good example would be ----------------------- 2019-08-12 Jürgen Spitzmüller - * Format incremented to 588: Support \theendnotes of endnotes package via a faked - float list. + * Format incremented to 588: + - Support \theendnotes of endnotes package via a faked float list. + - Support enotez package via enotez and foottoenotez modules. 2019-08-07 Jürgen Spitzmüller * Format incremented to 587: Use more generic paper names as LyX names diff --git a/lib/Makefile.am b/lib/Makefile.am index 4b5e6a7149..d0b0b7b5a1 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am @@ -2341,6 +2341,7 @@ dist_layouts_DATA =\ layouts/elsart.layout \ layouts/elsarticle.layout \ layouts/endnotes.module \ + layouts/enotez.module \ layouts/entcs.layout \ layouts/enumitem.module \ layouts/eqs-within-sections.module \ @@ -2356,6 +2357,7 @@ dist_layouts_DATA =\ layouts/fix-cm.module \ layouts/foils.layout \ layouts/foottoend.module \ + layouts/foottoenotez.module \ layouts/frletter.layout \ layouts/g-brief.layout \ layouts/g-brief2.layout \ diff --git a/lib/chkconfig.ltx b/lib/chkconfig.ltx index dd015bda8e..069d3a5cec 100644 --- a/lib/chkconfig.ltx +++ b/lib/chkconfig.ltx @@ -337,6 +337,7 @@ \TestPackage[koi8-r.def]{cyrillic} \TestPackage{dvipost} \TestPackage{endnotes} +\TestPackage{enotez} \TestPackage{enumitem} \TestPackage{environ} % required by tcolorbox \TestPackage{esint} diff --git a/lib/doc/LaTeXConfig.lyx b/lib/doc/LaTeXConfig.lyx index dd6c02e475..f98488fae9 100644 --- a/lib/doc/LaTeXConfig.lyx +++ b/lib/doc/LaTeXConfig.lyx @@ -1,5 +1,5 @@ #LyX 2.4 created this file. For more info see https://www.lyx.org/ -\lyxformat 583 +\lyxformat 588 \begin_document \begin_header \save_transient_properties true @@ -6480,10 +6480,14 @@ Packages required by modules \end_layout \begin_layout Subsection + +\change_deleted -712698321 1565673310 endnotes \end_layout \begin_layout Description + +\change_deleted -712698321 1565673310 Found: \begin_inset Info type "package" @@ -6494,18 +6498,24 @@ arg "endnotes" \end_layout \begin_layout Description + +\change_deleted -712698321 1565673310 CTAN: \family typewriter macros/latex/contrib/misc/endnotes.sty \end_layout \begin_layout Description + +\change_deleted -712698321 1565673310 Notes: The package \family sans endnotes \family default is needed by several modules to place footnotes at the end of sections, that are then so called endnotes. +\change_unchanged + \end_layout \begin_layout Subsection @@ -6540,6 +6550,150 @@ braille makes it possible to typeset Braille, a character system for blind people. \end_layout +\begin_layout Subsection + +\change_inserted -712698321 1565673326 +Endnotes (Basic) module +\end_layout + +\begin_layout Subsubsection + +\change_inserted -712698321 1565673326 +endnotes +\end_layout + +\begin_layout Description + +\change_inserted -712698321 1565673326 +Found: +\begin_inset Info +type "package" +arg "endnotes" +\end_inset + + +\end_layout + +\begin_layout Description + +\change_inserted -712698321 1565673326 +CTAN: +\family typewriter +macros/latex/contrib/endnotes/ +\end_layout + +\begin_layout Description + +\change_inserted -712698321 1565673631 +Notes: The package +\family sans +endnotes +\family default +is needed by the +\emph on +Endnotes (Basic) +\emph default + and +\emph on +Footnotes as Endnotes (Basic) +\emph default + modules to place footnotes at the end of sections, that are then so called + endnotes. + It is more limited, but also more established, than +\family sans +enotez +\family default + [cf. + Endnotes (Extended) module]. +\change_unchanged + +\end_layout + +\begin_layout Subsection + +\change_inserted -712698321 1565673348 +Endnotes (Extended) module +\end_layout + +\begin_layout Subsubsection + +\change_inserted -712698321 1565673326 +enotez +\end_layout + +\begin_layout Description + +\change_inserted -712698321 1565673326 +Found: +\begin_inset Info +type "package" +arg "enotez" +\end_inset + + +\end_layout + +\begin_layout Description + +\change_inserted -712698321 1565673326 +CTAN: +\family typewriter +macros/latex/contrib/enotez/ +\end_layout + +\begin_layout Description + +\change_inserted -712698321 1565673326 +Notes: The package +\family sans +enotez +\family default +is needed by the +\emph on +Endnotes (Extended) +\emph default + and +\emph on +Footnotes as Endnotes (Extended) +\emph default + modules to produce endnotes; +\family sans +enotez +\family default + is a new implementation of endnotes for \SpecialChar LaTeX2e + since the +\family sans +endnotes +\family default + package (used by the +\emph on +Basic +\emph default + endnotes modules) has some deficiencies. + As opposed to the latter, +\family sans +enotez +\family default + supports nested endnotes, hyper- and backlinks ( +\family sans +hyperref +\family default +) and a split list of endnotes in which the notes are automatically separated + by the sections or chapters they were set in. + Several languages are supported, and the output is easier customizable + than that of the +\family sans +endnotes +\family default + package. + However, +\family sans +enotez +\family default + requires a fairly modern \SpecialChar LaTeX + distribution. +\end_layout + \begin_layout Subsection FIXME module \end_layout @@ -6581,6 +6735,38 @@ FIXME notes into documents. \end_layout +\begin_layout Subsection + +\change_inserted -712698321 1565673411 +Footnotes as Endnotes (Basic) +\end_layout + +\begin_layout Standard + +\change_inserted -712698321 1565673436 +See +\emph on +Endnotes (Basic) +\emph default +. +\end_layout + +\begin_layout Subsection + +\change_inserted -712698321 1565673439 +Footnotes as Endnotes (Extended) +\end_layout + +\begin_layout Standard + +\change_inserted -712698321 1565673442 +See +\emph on +Endnotes (Extended) +\emph default +. +\end_layout + \begin_layout Subsection Hazard and Precautionary Statements module \end_layout diff --git a/lib/layouts/endnotes.module b/lib/layouts/endnotes.module index e5ad7a2574..dd3a77c4dc 100644 --- a/lib/layouts/endnotes.module +++ b/lib/layouts/endnotes.module @@ -1,10 +1,13 @@ -#\DeclareLyXModule[endnotes.sty]{Endnotes} +#\DeclareLyXModule[endnotes.sty]{Endnotes (Basic)} #\DeclareCategory{Foot- and Endnotes} #DescriptionBegin -#Adds an endnote inset, in addition to footnotes. You will need to add an -#endnotes list (Insert > List/Contents/References > Endnotes) where you +#Adds an endnote inset, in addition to footnotes. This uses the endnotes +#package, which has some limitations but works with older LaTeX distributions +#as well. You will need to add an endnotes list +#(Insert > List/Contents/References > Endnotes) where you #want the endnotes to appear. #DescriptionEnd +#Excludes: enotez | foottoenotez Format 80 diff --git a/lib/layouts/enotez.module b/lib/layouts/enotez.module new file mode 100644 index 0000000000..1d3ab301da --- /dev/null +++ b/lib/layouts/enotez.module @@ -0,0 +1,40 @@ +#\DeclareLyXModule[enotez.sty]{Endnotes (Extended)} +#\DeclareCategory{Foot- and Endnotes} +#DescriptionBegin +#Adds an endnote inset, in addition to footnotes. This uses the enotez package +#which is more powerful and customitable than then endnotes package (module 'Endnotes (Basic)'), +#but requires a fairly modern LaTeX distribution (with LaTeX3). +#You will need to add an endnotes list (Insert > List/Contents/References > Endnotes) +#where you want the endnotes to appear. +#DescriptionEnd +#Excludes: endnotes | foottoend + +Format 80 + +Counter endnotes + PrettyFormat "Endnote ##" +End + +InsetLayout Flex:Endnote + LyXType custom + LatexName endnote + LatexType command + Counter endnotes + Decoration classic + Font + Size Small + EndFont + MultiPar true + LabelString endnote + Requires enotez +End + +# We are only interested in the list +Float + Type endnote + ListName "Endnotes" + IsPredefined true + UsesFloatPkg false + ListCommand printendnotes + Requires enotez +End diff --git a/lib/layouts/foottoend.module b/lib/layouts/foottoend.module index 1c53c737bd..cfa6aa53dd 100644 --- a/lib/layouts/foottoend.module +++ b/lib/layouts/foottoend.module @@ -1,10 +1,13 @@ -#\DeclareLyXModule[endnotes.sty]{Footnotes as Endnotes} +#\DeclareLyXModule[endnotes.sty]{Footnotes as Endnotes (Basic)} #\DeclareCategory{Foot- and Endnotes} #DescriptionBegin -#Sets all footnotes as endnotes. You will need to add an -#endnotes list (Insert > List/Contents/References > Endnotes) where you +#Sets all footnotes as endnotes. This uses the endnotes +#package, which has some limitations but works with older LaTeX distributions +#as well. You will need to add an endnotes list +#(Insert > List/Contents/References > Endnotes) where you #want the endnotes to appear. #DescriptionEnd +#Excludes: enotez | foottoenotez Format 80 diff --git a/lib/layouts/foottoenotez.module b/lib/layouts/foottoenotez.module new file mode 100644 index 0000000000..d575f5112c --- /dev/null +++ b/lib/layouts/foottoenotez.module @@ -0,0 +1,30 @@ +#\DeclareLyXModule[enotez.sty]{Footnotes as Endnotes (Extended)} +#\DeclareCategory{Foot- and Endnotes} +#DescriptionBegin +#Sets all footnotes as endnotes. This uses the enotez package +#which is more powerful and customitable than then endnotes package +#(module 'Footnotes as Endnotes (Basic)'), but requires a fairly modern +#LaTeX distribution (with LaTeX3).You will need to add an +#endnotes list (Insert > List/Contents/References > Endnotes) where you +#want the endnotes to appear. +#DescriptionEnd +#Excludes: endnotes | foottoend + +Format 80 + + +InsetLayout Foot + LabelString Endnote + LatexName endnote + Requires enotez +End + +# We are only interested in the list +Float + Type endnote + ListName "Endnotes" + IsPredefined true + UsesFloatPkg false + ListCommand printendnotes + Requires enotez +End diff --git a/lib/lyx2lyx/lyx_2_4.py b/lib/lyx2lyx/lyx_2_4.py index 15d83b8145..064a07b085 100644 --- a/lib/lyx2lyx/lyx_2_4.py +++ b/lib/lyx2lyx/lyx_2_4.py @@ -3409,6 +3409,37 @@ def revert_theendnotes(document): continue document.body[i : j + 1] = put_cmd_in_ert("\\theendnotes") + + +def revert_enotez(document): + " Reverts native support of enotez package to TeX-code " + + if not "enotez" in document.get_module_list() and not "foottoenotez" in document.get_module_list(): + return + + use = False + if find_token(document.body, "\\begin_inset Flex Endnote", 0) != -1: + use = True + + revert_flex_inset(document.body, "Endnote", "\\endnote") + + i = 0 + while True: + i = find_token(document.body, "\\begin_inset FloatList endnote", i + 1) + if i == -1: + break + j = find_end_of_inset(document.body, i) + if j == -1: + document.warning("Malformed LyX document: Can't find end of FloatList inset") + continue + + use = True + document.body[i : j + 1] = put_cmd_in_ert("\\printendnotes") + + if use: + add_to_preamble(document, ["\\usepackage{enotez}"]) + document.del_module("enotez") + document.del_module("foottoenotez") ## @@ -3463,7 +3494,7 @@ convert = [ [588, []] ] -revert = [[587, [revert_theendnotes]], +revert = [[587, [revert_enotez,revert_theendnotes]], [586, [revert_pagesizenames]], [585, [revert_dupqualicites]], [584, [revert_pagesizes,revert_komafontsizes]], diff --git a/src/LaTeX.cpp b/src/LaTeX.cpp index e68e07c71f..4606ed3f45 100644 --- a/src/LaTeX.cpp +++ b/src/LaTeX.cpp @@ -799,6 +799,10 @@ int LaTeX::scanLogFile(TeXErrors & terr) } else if (contains(token, "Etaremune labels have changed")) { retval |= ERROR_RERUN; LYXERR(Debug::LATEX, "Force rerun."); + // package enotez + } else if (contains(token, "Endnotes may have changed. Rerun")) { + retval |= RERUN; + LYXERR(Debug::LATEX, "We should rerun."); //"Citation `cit' on page X undefined on input line X." } else if (contains(token, "Citation") //&& contains(token, "on input line") //often split to newline diff --git a/src/LaTeXFeatures.cpp b/src/LaTeXFeatures.cpp index 3b7519ae9f..cd9db06930 100644 --- a/src/LaTeXFeatures.cpp +++ b/src/LaTeXFeatures.cpp @@ -978,6 +978,7 @@ char const * simplefeatures[] = { "csquotes", "enumitem", "endnotes", + "enotez", "hhline", "ifthen", // listings is handled in BufferParams.cpp diff --git a/src/tex2lyx/text.cpp b/src/tex2lyx/text.cpp index abc25f274f..764cffa988 100644 --- a/src/tex2lyx/text.cpp +++ b/src/tex2lyx/text.cpp @@ -3931,7 +3931,10 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer, continue; } - if (t.cs() == "theendnotes") { + if (t.cs() == "theendnotes" + || (t.cs() == "printendnotes" + && p.next_token().asInput() != "*" + && !p.hasOpt())) { context.check_layout(os); begin_inset(os, "FloatList endnote\n"); end_inset(os); -- 2.39.5