]> git.lyx.org Git - lyx.git/commitdiff
Simplify preamble code when using listings
authorEnrico Forestieri <forenr@lyx.org>
Thu, 8 Jun 2017 02:24:29 +0000 (04:24 +0200)
committerEnrico Forestieri <forenr@lyx.org>
Thu, 8 Jun 2017 02:25:53 +0000 (04:25 +0200)
Following an idea from Guillame.

lib/layouts/stdinsets.inc
src/insets/InsetListings.cpp
src/insets/InsetListings.h
src/insets/InsetTOC.cpp

index 1ef2c524b706d79e917033775b1299dc6c52bfaa..6ee56de25ba2ee9ae198c8648400c3fabb5b78d1 100644 (file)
@@ -274,21 +274,42 @@ InsetLayout TOC:Listings
        # We need the [[List of Listings]] context, since "Listings" is also
        # the name of the inset and translated differently.
        # "Listings[[List of Listings]]" is the name of the "List of listings"
-       # ("Listings" is the predefined english name) in listings.sty and
-       # minted.sty, so it must be used here as well.
+       # ("Listings" is the predefined english name) in listings.sty, so it
+       # must be used here as well.
        BabelPreamble
-               \ifx\minted\undefined
-               \addto\captions$$lang{\renewcommand{\lstlistlistingname}{_(Listings[[List of Listings]])}}\else
-               \addto\captions$$lang{\renewcommand{\listoflistingscaption}{_(Listings[[List of Listings]])}}\fi
+               \addto\captions$$lang{\renewcommand{\lstlistlistingname}{_(Listings[[List of Listings]])}}
        EndBabelPreamble
-       # Either commands do not need to be defined in LangPreamble, since
-       # listings.sty or minted.sty do that already. However they need to be
-       # redefined in order to be used for non-english single-language
-       # documents.
+       # The command does not need to be defined in LangPreamble, since
+       # listings.sty does that already. However it needs to be redefined
+       # in order to be used for non-english single-language documents.
        LangPreamble
-               \ifx\minted\undefined
-               \renewcommand{\lstlistlistingname}{_(Listings[[List of Listings]])}\else
-               \renewcommand{\listoflistingscaption}{_(Listings[[List of Listings]])}\fi
+               \renewcommand{\lstlistlistingname}{_(Listings[[List of Listings]])}
+       EndLangPreamble
+       FixedWidthPreambleEncoding true
+  HTMLTag h2
+  HTMLStyle
+    div.lyxtoc-flat {
+      margin: 0em 0em 0em 1em;
+      font-size: large;
+      font-weight: normal;
+    }
+  EndHTMLStyle
+End
+
+InsetLayout TOC:MintedListings
+       # We need the [[List of Listings]] context, since "Listings" is also
+       # the name of the inset and translated differently.
+       # "Listings[[List of Listings]]" is the name of the "List of listings"
+       # ("Listings" is the predefined english name) in minted.sty so it
+       # must be used here as well.
+       BabelPreamble
+               \addto\captions$$lang{\renewcommand{\listoflistingscaption}{_(Listings[[List of Listings]])}}
+       EndBabelPreamble
+       # The command does not need to be defined in LangPreamble, since
+       # minted.sty does that already. However it needs to be redefined
+       # in order to be used for non-english single-language documents.
+       LangPreamble
+               \renewcommand{\listoflistingscaption}{_(Listings[[List of Listings]])}
        EndLangPreamble
        FixedWidthPreambleEncoding true
   HTMLTag h2
@@ -303,18 +324,13 @@ End
 
 InsetLayout Include:Listings
        BabelPreamble
-               \ifx\minted\undefined
-               \addto\captions$$lang{\renewcommand{\lstlistingname}{_(Listing)}}\else
-               \addto\captions$$lang{\renewcommand{\listingscaption}{_(Listing)}}\fi
+               \addto\captions$$lang{\renewcommand{\lstlistingname}{_(Listing)}}
        EndBabelPreamble
-       # Either commands do not need to be defined in LangPreamble, since
-       # listings.sty or minted.sty do that already. However they need to be
-       # redefined in order to be used for non-english single-language
-       # documents.
+       # The command does not need to be defined in LangPreamble, since
+       # listings.sty does that already. However it needs to be redefined
+       # in order to be used for non-english single-language documents.
        LangPreamble
-               \ifx\minted\undefined
-               \renewcommand{\lstlistingname}{_(Listing)}\else
-               \renewcommand{\listingscaption}{_(Listing)}\fi
+               \renewcommand{\lstlistingname}{_(Listing)}
        EndLangPreamble
        FixedWidthPreambleEncoding true
 End
@@ -356,6 +372,20 @@ InsetLayout Listings
        EndHTMLStyle
 End
 
+InsetLayout MintedListings
+       CopyStyle Listings
+       BabelPreamble
+               \addto\captions$$lang{\renewcommand{\listingscaption}{_(Listing)}}
+       EndBabelPreamble
+       # The command does not need to be defined in LangPreamble, since
+       # minted.sty does that already. However it needs to be redefined
+       # in order to be used for non-english single-language documents.
+       LangPreamble
+               \renewcommand{\listingscaption}{_(Listing)}
+       EndLangPreamble
+       FixedWidthPreambleEncoding true
+End
+
 InsetLayout Branch
        Decoration            classic
        LabelFont
index 033b72ea2cba69eacd55871a73c58a238f529a22..7be13bcfbdc211868be1af509b01f6686a410ec0 100644 (file)
@@ -72,6 +72,15 @@ Inset::DisplayType InsetListings::display() const
 }
 
 
+docstring InsetListings::layoutName() const
+{
+       if (buffer().params().use_minted)
+               return from_ascii("MintedListings");
+       else
+               return from_ascii("Listings");
+}
+
+
 void InsetListings::write(ostream & os) const
 {
        os << "listings" << "\n";
index 902fa0437e64009770293859e2540322c3b53fd9..aa46765c59c55ea730ac37858062f077289f6f71 100644 (file)
@@ -48,7 +48,7 @@ private:
        /// lstinline is inlined, normal listing is displayed
        DisplayType display() const;
        ///
-       docstring layoutName() const { return from_ascii("Listings"); }
+       docstring layoutName() const;
        ///
        void write(std::ostream & os) const;
        ///
index dabfd211c3e31f444e045ba4e1ab6cdfc8ac6c45..d617b081667ce7f1335dbbdbc8c50b0a9a142431 100644 (file)
@@ -96,8 +96,12 @@ void InsetTOC::doDispatch(Cursor & cur, FuncRequest & cmd) {
 
 docstring InsetTOC::layoutName() const
 {
-       if (getCmdName() == "lstlistoflistings")
-               return from_ascii("TOC:Listings");
+       if (getCmdName() == "lstlistoflistings") {
+               if (buffer().params().use_minted)
+                       return from_ascii("TOC:MintedListings");
+               else
+                       return from_ascii("TOC:Listings");
+       }
        return from_ascii("TOC");
 }