]> git.lyx.org Git - lyx.git/commitdiff
tex2lyx: support for \addcontentsline in BibTeX inset
authorUwe Stöhr <uwestoehr@lyx.org>
Sat, 16 Feb 2013 04:51:23 +0000 (05:51 +0100)
committerUwe Stöhr <uwestoehr@lyx.org>
Sat, 16 Feb 2013 04:51:23 +0000 (05:51 +0100)
src/tex2lyx/TODO.txt
src/tex2lyx/test/Dummy Document.lyx
src/tex2lyx/test/DummyDocument.lyx
src/tex2lyx/test/Dummy~Document.lyx
src/tex2lyx/test/test-insets.lyx.lyx
src/tex2lyx/test/test-insets.tex
src/tex2lyx/text.cpp

index 0ac04bf78d3ba15e2949eee2b1e8098d7c3c9349..70e4c07638eb36178a2b89bc887f2d9080c68993 100644 (file)
@@ -53,7 +53,6 @@ Format LaTeX feature                        LyX feature
 392    new beamer format                    InsetLayout
 396    nameref.sty                          InsetRef
 399    automatic mathdots loading           \use_mathdots
-402    \addcontentsline                     InsetBibtex bibtotoc option
 407    vertical offset for multirows        InsetTabular
 411    support for polyglossia              \language_package  (the cases of no package, of babel and of custom package is supported)
 415    automatic undertilde loading         \use_package undertilde
index 5721713b9e2be6604c696ecac5c7b9f553517919..22e0ee63d8320106537148e2b00166faa6edc847 100644 (file)
@@ -1,5 +1,5 @@
 #LyX file created by tex2lyx 2.1.0dev
-\lyxformat 459
+\lyxformat 462
 \begin_document
 \begin_header
 \textclass article
index 494fcd459e4719e4c8f6a46d53e430b4f6911bf4..948e95981df015662fcb78f1735f9a14ffbb54c5 100644 (file)
@@ -1,5 +1,5 @@
 #LyX file created by tex2lyx 2.1.0dev
-\lyxformat 459
+\lyxformat 462
 \begin_document
 \begin_header
 \textclass article
@@ -63,7 +63,7 @@
 \secnumdepth 3
 \tocdepth 3
 \paragraph_separation indent
-\paragraph_indentation default
+\paragraph_indentation 3mm
 \quotes_language english
 \papercolumns 1
 \papersides 1
index 53ca775a6f7959f24d6a09de791b9aabbc7d3f88..a879813206c63fc632a30868690750c43954df78 100644 (file)
@@ -1,5 +1,5 @@
 #LyX file created by tex2lyx 2.1.0dev
-\lyxformat 459
+\lyxformat 462
 \begin_document
 \begin_header
 \textclass article
@@ -63,7 +63,7 @@
 \secnumdepth 3
 \tocdepth 3
 \paragraph_separation indent
-\paragraph_indentation default
+\paragraph_indentation 3mm
 \quotes_language english
 \papercolumns 1
 \papersides 1
index 910d8afa15294c276b7b686121b6b4d6b508612b..a1d923641252571609b788c6cc453cfccb96d831 100644 (file)
@@ -1019,11 +1019,7 @@ inline false
 status collapsed
 
 \begin_layout Plain Layout
-#
-\end_layout
-
-\begin_layout Plain Layout
- Example listing float
+# Example listing float
 \end_layout
 
 \begin_layout Plain Layout
@@ -1107,11 +1103,7 @@ inline false
 status collapsed
 
 \begin_layout Plain Layout
-d
-\end_layout
-
-\begin_layout Plain Layout
-ef func(param):
+def func(param):
 \end_layout
 
 \begin_layout Plain Layout
@@ -1159,11 +1151,7 @@ inline false
 status collapsed
 
 \begin_layout Plain Layout
-h
-\end_layout
-
-\begin_layout Plain Layout
-ello
+hello
 \end_layout
 
 \end_inset
@@ -6115,6 +6103,82 @@ $
 
 \begin_layout Standard
 
+\begin_inset ERT
+status collapsed
+
+\begin_layout Plain Layout
+
+\backslash
+addcontentsline{toc}{section}{test}
+\end_layout
+
+\end_inset
+
+
+\end_layout
+
+\begin_layout Standard
+  
+\begin_inset CommandInset bibtex
+LatexCommand bibtex
+bibfiles "IEEEexample"
+options "bibtotoc,test"
+
+\end_inset
+
+
+\end_layout
+
+\begin_layout Standard
+\begin_inset CommandInset bibtex
+LatexCommand bibtex
+bibfiles "IEEEexample"
+options "test"
+
+\end_inset
+
+
+\end_layout
+
+\begin_layout Standard
+
+\begin_inset ERT
+status collapsed
+
+\begin_layout Plain Layout
+
+\backslash
+bibliographystyle{test}
+\end_layout
+
+\end_inset
+
+\begin_inset ERT
+status collapsed
+
+\begin_layout Plain Layout
+
+\backslash
+addcontentsline{toc}{section}{test}
+\end_layout
+
+\end_inset
+
+\begin_inset CommandInset bibtex
+LatexCommand bibtex
+bibfiles "IEEEexample"
+options "test"
+
+\end_inset
+
+
+\end_layout
+
+\begin_layout Standard
+
 \begin_inset CommandInset index_print
 LatexCommand printindex
 type "idx"
index 2a476a2601d3515eb946e733aa01cf59b0825186..95bfebdd5e1cbd317757e062b3827b95a10420bc 100644 (file)
@@ -572,6 +572,19 @@ Let $f:\left[  a,b\right]  \rightarrow%
 %EndExpansion
 $.
 
+\addcontentsline{toc}{section}{test}
+
+\bibliographystyle{test}
+\addcontentsline{toc}{section}{\refname}
+\bibliography{IEEEexample}
+
+\bibliographystyle{test}
+\bibliography{IEEEexample}
+
+\bibliographystyle{test}
+\addcontentsline{toc}{section}{test}
+\bibliography{IEEEexample}
+
 \printindex{}
 
 \printnomenclature hello
index fb09aa8c9fcc00b6af839c2c4a477d085876bfc7..07cb0775bdd4f2f8e75cd645f16a6f857739624d 100644 (file)
@@ -2162,9 +2162,10 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer,
        Layout const * newlayout = 0;
        InsetLayout const * newinsetlayout = 0;
        char const * const * where = 0;
-       // Store the latest bibliographystyle and nocite{*} option
-       // (needed for bibtex inset)
+       // Store the latest bibliographystyle, addcontentslineContent and
+       // nocite{*} option (needed for bibtex inset)
        string btprint;
+       string contentslineContent;
        string bibliographystyle = "default";
        bool const use_natbib = isProvided("natbib");
        bool const use_jurabib = isProvided("jurabib");
@@ -3963,8 +3964,8 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer,
                else if (t.cs() == "bibliographystyle") {
                        // store new bibliographystyle
                        bibliographystyle = p.verbatim_item();
-                       // If any other command than \bibliography and
-                       // \nocite{*} follows, we need to output the style
+                       // If any other command than \bibliography, \addcontentsline
+                       // and \nocite{*} follows, we need to output the style
                        // (because it might be used by that command).
                        // Otherwise, it will automatically be output by LyX.
                        p.pushPosition();
@@ -3979,6 +3980,15 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer,
                                                continue;
                                } else if (t2.cs() == "bibliography")
                                        output = false;
+                               else if (t2.cs() == "addcontentsline") {
+                                       // get the 3 arguments of \addcontentsline
+                                       p.getArg('{', '}');
+                                       p.getArg('{', '}');
+                                       contentslineContent = p.getArg('{', '}');
+                                       // if the last argument is not \refname we must output
+                                       if (contentslineContent == "\\refname")
+                                               output = false;
+                               }
                                break;
                        }
                        p.popPosition();
@@ -3989,8 +3999,23 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer,
                        }
                }
 
+               else if (t.cs() == "addcontentsline") {
+                       context.check_layout(os);
+                       // get the 3 arguments of \addcontentsline
+                       string const one = p.getArg('{', '}');
+                       string const two = p.getArg('{', '}');
+                       string const three = p.getArg('{', '}');
+                       // only if it is a \refname, we support if for the bibtex inset
+                       if (contentslineContent != "\\refname") {
+                               output_ert_inset(os,
+                                       "\\addcontentsline{" + one + "}{" + two + "}{"+ three + '}',
+                                       context);
+                       }
+               }
+
                else if (t.cs() == "bibliography") {
                        context.check_layout(os);
+                       string BibOpts;
                        begin_command_inset(os, "bibtex", "bibtex");
                        if (!btprint.empty()) {
                                os << "btprint " << '"' << "btPrintAll" << '"' << "\n";
@@ -3999,9 +4024,20 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer,
                                btprint.clear();
                        }
                        os << "bibfiles " << '"' << p.verbatim_item() << '"' << "\n";
+                       // Do we have addcontentsline?
+                       if (contentslineContent == "\\refname") {
+                               BibOpts = "bibtotoc";
+                               // clear string because next BibTeX inset can be without addcontentsline
+                               contentslineContent.clear();
+                       }
                        // Do we have a bibliographystyle set?
-                       if (!bibliographystyle.empty())
-                               os << "options " << '"' << bibliographystyle << '"' << "\n";
+                       if (!bibliographystyle.empty()) {
+                               if (BibOpts.empty())
+                                       BibOpts = bibliographystyle;
+                               else
+                                       BibOpts = BibOpts + ',' + bibliographystyle;
+                       }
+                       os << "options " << '"' << BibOpts << '"' << "\n";
                        end_inset(os);
                }