From 72a44b3c75f8a078f796b973f93617b0339800cc Mon Sep 17 00:00:00 2001 From: =?utf8?q?Uwe=20St=C3=B6hr?= Date: Sat, 16 Feb 2013 05:51:23 +0100 Subject: [PATCH] tex2lyx: support for \addcontentsline in BibTeX inset --- src/tex2lyx/TODO.txt | 1 - src/tex2lyx/test/Dummy Document.lyx | 2 +- src/tex2lyx/test/DummyDocument.lyx | 4 +- src/tex2lyx/test/Dummy~Document.lyx | 4 +- src/tex2lyx/test/test-insets.lyx.lyx | 94 +++++++++++++++++++++++----- src/tex2lyx/test/test-insets.tex | 13 ++++ src/tex2lyx/text.cpp | 48 ++++++++++++-- 7 files changed, 139 insertions(+), 27 deletions(-) diff --git a/src/tex2lyx/TODO.txt b/src/tex2lyx/TODO.txt index 0ac04bf78d..70e4c07638 100644 --- a/src/tex2lyx/TODO.txt +++ b/src/tex2lyx/TODO.txt @@ -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 diff --git a/src/tex2lyx/test/Dummy Document.lyx b/src/tex2lyx/test/Dummy Document.lyx index 5721713b9e..22e0ee63d8 100644 --- a/src/tex2lyx/test/Dummy Document.lyx +++ b/src/tex2lyx/test/Dummy Document.lyx @@ -1,5 +1,5 @@ #LyX file created by tex2lyx 2.1.0dev -\lyxformat 459 +\lyxformat 462 \begin_document \begin_header \textclass article diff --git a/src/tex2lyx/test/DummyDocument.lyx b/src/tex2lyx/test/DummyDocument.lyx index 494fcd459e..948e95981d 100644 --- a/src/tex2lyx/test/DummyDocument.lyx +++ b/src/tex2lyx/test/DummyDocument.lyx @@ -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 diff --git a/src/tex2lyx/test/Dummy~Document.lyx b/src/tex2lyx/test/Dummy~Document.lyx index 53ca775a6f..a879813206 100644 --- a/src/tex2lyx/test/Dummy~Document.lyx +++ b/src/tex2lyx/test/Dummy~Document.lyx @@ -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 diff --git a/src/tex2lyx/test/test-insets.lyx.lyx b/src/tex2lyx/test/test-insets.lyx.lyx index 910d8afa15..a1d9236412 100644 --- a/src/tex2lyx/test/test-insets.lyx.lyx +++ b/src/tex2lyx/test/test-insets.lyx.lyx @@ -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" diff --git a/src/tex2lyx/test/test-insets.tex b/src/tex2lyx/test/test-insets.tex index 2a476a2601..95bfebdd5e 100644 --- a/src/tex2lyx/test/test-insets.tex +++ b/src/tex2lyx/test/test-insets.tex @@ -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 diff --git a/src/tex2lyx/text.cpp b/src/tex2lyx/text.cpp index fb09aa8c9f..07cb0775bd 100644 --- a/src/tex2lyx/text.cpp +++ b/src/tex2lyx/text.cpp @@ -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); } -- 2.39.2