From 229052b29a5116e263fbc380cc4fa0f34c837e75 Mon Sep 17 00:00:00 2001 From: Juergen Spitzmueller Date: Mon, 12 Aug 2019 13:00:54 +0200 Subject: [PATCH] Extend endnotes support Support native solution for Endnotes list rather than having to use \\theendnotes via ERT File format change --- development/FORMAT | 4 ++++ lib/layouts/endnotes.module | 15 +++++++++++++-- lib/layouts/foottoend.module | 15 +++++++++++++-- lib/lyx2lyx/lyx_2_4.py | 25 +++++++++++++++++++++++-- src/tex2lyx/text.cpp | 8 ++++++++ src/version.h | 4 ++-- 6 files changed, 63 insertions(+), 8 deletions(-) diff --git a/development/FORMAT b/development/FORMAT index 77d6813575..8bb4a3ae3e 100644 --- a/development/FORMAT +++ b/development/FORMAT @@ -7,6 +7,10 @@ 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. + 2019-08-07 Jürgen Spitzmüller * Format incremented to 587: Use more generic paper names as LyX names (rather than LaTeXisms; e.g., "a4" rather than "a4paper"). diff --git a/lib/layouts/endnotes.module b/lib/layouts/endnotes.module index c63e935879..5ab73c9333 100644 --- a/lib/layouts/endnotes.module +++ b/lib/layouts/endnotes.module @@ -1,8 +1,9 @@ #\DeclareLyXModule[endnotes.sty]{Endnotes} #\DeclareCategory{Foot- and Endnotes} #DescriptionBegin -#Adds an endnote inset, in addition to footnotes. You will need to add -#\theendnotes in TeX-code where you want the endnotes to appear. +#Adds an endnote inset, in addition to footnotes. You will need to add an +#endnotes list (Insert > List/Contents/References > Endnotes) where you +#want the endnotes to appear. #DescriptionEnd Format 79 @@ -24,3 +25,13 @@ InsetLayout Flex:Endnote LabelString endnote Requires endnotes End + +# We are only interested in the list +Float + Type endnote + ListName "Endnotes" + IsPredefined true + UsesFloatPkg false + ListCommand theendnotes + Requires endnotes +End diff --git a/lib/layouts/foottoend.module b/lib/layouts/foottoend.module index 9bbc5af18c..ab28844478 100644 --- a/lib/layouts/foottoend.module +++ b/lib/layouts/foottoend.module @@ -1,8 +1,9 @@ #\DeclareLyXModule[endnotes.sty]{Footnotes as Endnotes} #\DeclareCategory{Foot- and Endnotes} #DescriptionBegin -#Sets all footnotes as endnotes. You will need to add \theendnotes -#in TeX-code where you want the endnotes to appear. +#Sets all footnotes as endnotes. You will need to add an +#endnotes list (Insert > List/Contents/References > Endnotes) where you +#want the endnotes to appear. #DescriptionEnd Format 79 @@ -12,3 +13,13 @@ Requires endnotes AddToPreamble \let\footnote=\endnote EndPreamble + +# We are only interested in the list +Float + Type endnote + ListName "Endnotes" + IsPredefined true + UsesFloatPkg false + ListCommand theendnotes + Requires endnotes +End diff --git a/lib/lyx2lyx/lyx_2_4.py b/lib/lyx2lyx/lyx_2_4.py index 90ce08eca3..147ff91da8 100644 --- a/lib/lyx2lyx/lyx_2_4.py +++ b/lib/lyx2lyx/lyx_2_4.py @@ -3389,6 +3389,25 @@ def revert_pagesizenames(document): if val in newnames: newval = val + "paper" document.header[i] = "\\papersize " + newval + + +def revert_theendnotes(document): + " Reverts native support of \\theendnotes to TeX-code " + + if not "endnotes" in document.get_module_list() and not "foottoend" in document.get_module_list(): + return + + i = 0 + while True: + i = find_token(document.body, "\\begin_inset FloatList endnote", i + 1) + if i == -1: + return + j = find_end_of_inset(document.body, i) + if j == -1: + document.warning("Malformed LyX document: Can't find end of FloatList inset") + continue + + document.body[i : j + 1] = put_cmd_in_ert("\\theendnotes") ## @@ -3439,10 +3458,12 @@ convert = [ [584, []], [585, [convert_pagesizes]], [586, []], - [587, [convert_pagesizenames]] + [587, [convert_pagesizenames]], + [588, []] ] -revert = [[586, [revert_pagesizenames]], +revert = [[587, [revert_theendnotes]], + [586, [revert_pagesizenames]], [585, [revert_dupqualicites]], [584, [revert_pagesizes,revert_komafontsizes]], [583, [revert_vcsinfo_rev_abbrev]], diff --git a/src/tex2lyx/text.cpp b/src/tex2lyx/text.cpp index b66ef7f44a..abc25f274f 100644 --- a/src/tex2lyx/text.cpp +++ b/src/tex2lyx/text.cpp @@ -3931,6 +3931,14 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer, continue; } + if (t.cs() == "theendnotes") { + context.check_layout(os); + begin_inset(os, "FloatList endnote\n"); + end_inset(os); + skip_spaces_braces(p); + continue; + } + if ((where = is_known(t.cs(), known_text_font_families))) { parse_text_attributes(p, os, FLAG_ITEM, outer, context, "\\family", context.font.family, diff --git a/src/version.h b/src/version.h index 13f06a39cd..110ba804cb 100644 --- a/src/version.h +++ b/src/version.h @@ -32,8 +32,8 @@ extern char const * const lyx_version_info; // Do not remove the comment below, so we get merge conflict in // independent branches. Instead add your own. -#define LYX_FORMAT_LYX 587 // spitz: generic paper size names -#define LYX_FORMAT_TEX2LYX 587 +#define LYX_FORMAT_LYX 588 // spitz: support \theendnotes +#define LYX_FORMAT_TEX2LYX 588 #if LYX_FORMAT_TEX2LYX != LYX_FORMAT_LYX #ifndef _MSC_VER