]> git.lyx.org Git - features.git/commitdiff
tex2lyx: support bibtex inset with \phantomsection
authorUwe Stöhr <uwestoehr@lyx.org>
Sun, 17 Feb 2013 03:17:02 +0000 (04:17 +0100)
committerUwe Stöhr <uwestoehr@lyx.org>
Sun, 17 Feb 2013 03:17:02 +0000 (04:17 +0100)
This is an addendum to [72a44b3c/lyxgit] because depending on the environment, LyX adds a \phantomsection before \addcontentsline.

- also update the test file

src/tex2lyx/test/test-insets.lyx.lyx
src/tex2lyx/test/test-insets.tex
src/tex2lyx/text.cpp

index bfc85c3353f23b7d1539ae54e171e4ec011bc541..cbe373609b8aa9e6c161a19d6de67b8f3ac27ed5 100644 (file)
@@ -6135,8 +6135,14 @@ $
 .
 \end_layout
 
-\begin_layout Standard
+\begin_layout Section
+Lists/Indices
+\end_layout
 
+\begin_layout Standard
+single 
+\backslash
+addcontentsline: 
 \begin_inset ERT
 status collapsed
 
@@ -6152,10 +6158,18 @@ addcontentsline{toc}{section}{test}
 \end_layout
 
 \begin_layout Standard
-  
+with 
+\backslash
+addcontentsline and 
+\backslash
+phantomsection:
+\end_layout
+
+\begin_layout Standard
 \begin_inset CommandInset bibtex
 LatexCommand bibtex
-bibfiles "IEEEexample"
+bibfiles "xampl"
 options "bibtotoc,test"
 
 \end_inset
@@ -6163,11 +6177,15 @@ options "bibtotoc,test"
 
 \end_layout
 
+\begin_layout Standard
+normal:
+\end_layout
+
 \begin_layout Standard
  
 \begin_inset CommandInset bibtex
 LatexCommand bibtex
-bibfiles "IEEEexample"
+bibfiles "xampl"
 options "test"
 
 \end_inset
@@ -6175,6 +6193,12 @@ options "test"
 
 \end_layout
 
+\begin_layout Standard
+with wrong 
+\backslash
+addcontentsline:
+\end_layout
+
 \begin_layout Standard
 
 \begin_inset ERT
@@ -6200,10 +6224,10 @@ addcontentsline{toc}{section}{test}
 
 \end_inset
 
+  
 \begin_inset CommandInset bibtex
 LatexCommand bibtex
-bibfiles "IEEEexample"
+bibfiles "xampl"
 options "test"
 
 \end_inset
@@ -6211,6 +6235,31 @@ options "test"
 
 \end_layout
 
+\begin_layout Standard
+with 
+\backslash
+addcontentsline and 
+\backslash
+nocite{*}:
+\end_layout
+
+\begin_layout Standard
+  
+\begin_inset CommandInset bibtex
+LatexCommand bibtex
+btprint "btPrintAll"
+bibfiles "xampl"
+options "bibtotoc,test"
+
+\end_inset
+
+
+\end_layout
+
+\begin_layout Standard
+normal index:
+\end_layout
+
 \begin_layout Standard
 
 \begin_inset CommandInset index_print
@@ -6222,6 +6271,10 @@ type "idx"
 
 \end_layout
 
+\begin_layout Standard
+normal nomenclature:
+\end_layout
+
 \begin_layout Standard
 
 \begin_inset CommandInset nomencl_print
@@ -6234,7 +6287,7 @@ hello
 \end_layout
 
 \begin_layout Standard
-
+manually set width: 
 \begin_inset ERT
 status collapsed
 
@@ -6258,6 +6311,10 @@ set_width "none"
 
 \end_layout
 
+\begin_layout Standard
+nomenclature with set width:
+\end_layout
+
 \begin_layout Standard
 
 \begin_inset CommandInset nomencl_print
index ff2251a96cb88a9d05e5a67a5acc61e6f0af393b..9d70ad8108a84a381e922b1261e2cb7ade105413 100644 (file)
@@ -541,6 +541,7 @@ or by a page break \pagebreak
 or by a defined page break \pagebreak % again with a comment
        [4]
 
+
 \section{Special characters\index{Special characters}}
 
 Then one has those macros with a long name for a short meaning, like
@@ -570,6 +571,7 @@ builtin \textasciicircum % with a comment
 A sub\textsubscript{sc\emph{ript}} and super\textsuperscript{script
 with $a^2+b^2=c^2$ math}.
 
+
 \section{Mathematics\index{Mathematics}}
 
 Let $f:\left[  a,b\right]  \rightarrow%
@@ -579,25 +581,47 @@ Let $f:\left[  a,b\right]  \rightarrow%
 %EndExpansion
 $.
 
-\addcontentsline{toc}{section}{test}
+
+\section{Lists/Indices}
+
+single \textbackslash{}addcontentsline: \addcontentsline{toc}{section}{test}
+
+with \textbackslash{}addcontentsline and \textbackslash{}phantomsection:
 
 \bibliographystyle{test}
-\addcontentsline{toc}{section}{\refname}
-\bibliography{IEEEexample}
+\phantomsection\addcontentsline{toc}{section}{\refname}\bibliography{xampl}
+
+
+normal:
 
 \bibliographystyle{test}
-\bibliography{IEEEexample}
+\bibliography{xampl}
+
+
+with wrong \textbackslash{}addcontentsline:
+
+\bibliographystyle{test} \addcontentsline{toc}{section}{test} \bibliographystyle{test}
+\bibliography{xampl}
+
+
+with \textbackslash{}addcontentsline and \textbackslash{}nocite\{{*}\}:
 
 \bibliographystyle{test}
-\addcontentsline{toc}{section}{test}
-\bibliography{IEEEexample}
+\addcontentsline{toc}{section}{\refname}\nocite{*}
+\bibliography{xampl}
+
+
+normal index:
 
 \printindex{}
 
+normal nomenclature:
+
 \printnomenclature hello
 
-\settowidth{\nomlabelwidth}{URL2}
-\printnomenclature{}
+manually set width: \settowidth{\nomlabelwidth}{URL2} \printnomenclature{}
+
+nomenclature with set width:
 
 \printnomenclature[0.02\linewidth]{}
 
index 4908e882628f1cae788bc42da903b9341a40572f..6ac1888c849656241f94a4c669e202d810f0cf04 100644 (file)
@@ -3990,6 +3990,10 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer,
                                                continue;
                                } else if (t2.cs() == "bibliography")
                                        output = false;
+                               else if (t2.cs() == "phantomsection") {
+                                       output = false;
+                                       continue;
+                               }
                                else if (t2.cs() == "addcontentsline") {
                                        // get the 3 arguments of \addcontentsline
                                        p.getArg('{', '}');
@@ -4009,6 +4013,13 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer,
                        }
                }
 
+               else if (t.cs() == "phantomsection") {
+                       // we only support this if it occurs between
+                       // \bibliographystyle and \bibliography
+                       if (bibliographystyle.empty())
+                               output_ert_inset(os, "\\phantomsection", context);
+               }
+
                else if (t.cs() == "addcontentsline") {
                        context.check_layout(os);
                        // get the 3 arguments of \addcontentsline
@@ -4046,6 +4057,9 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer,
                                        BibOpts = bibliographystyle;
                                else
                                        BibOpts = BibOpts + ',' + bibliographystyle;
+                               // clear it because each bibtex entry has its style
+                               // and we need an empty string to handle \phantomsection
+                               bibliographystyle.clear();
                        }
                        os << "options " << '"' << BibOpts << '"' << "\n";
                        end_inset(os);