tex2lyx: support bibtex inset with \phantomsection

This is an addendum to [72a44b3c/lyxgit] because depending on the environment, LyX adds a \phantomsection before \addcontentsline.

- also update the test file
This commit is contained in:
Uwe Stöhr 2013-02-17 04:17:02 +01:00
parent 3a201976b7
commit a2022d457b
3 changed files with 110 additions and 15 deletions

View File

@ -6135,8 +6135,14 @@ $
. .
\end_layout \end_layout
\begin_layout Standard \begin_layout Section
Lists/Indices
\end_layout
\begin_layout Standard
single
\backslash
addcontentsline:
\begin_inset ERT \begin_inset ERT
status collapsed status collapsed
@ -6151,11 +6157,19 @@ addcontentsline{toc}{section}{test}
\end_layout \end_layout
\begin_layout Standard
with
\backslash
addcontentsline and
\backslash
phantomsection:
\end_layout
\begin_layout Standard \begin_layout Standard
\begin_inset CommandInset bibtex \begin_inset CommandInset bibtex
LatexCommand bibtex LatexCommand bibtex
bibfiles "IEEEexample" bibfiles "xampl"
options "bibtotoc,test" options "bibtotoc,test"
\end_inset \end_inset
@ -6163,11 +6177,15 @@ options "bibtotoc,test"
\end_layout \end_layout
\begin_layout Standard
normal:
\end_layout
\begin_layout Standard \begin_layout Standard
\begin_inset CommandInset bibtex \begin_inset CommandInset bibtex
LatexCommand bibtex LatexCommand bibtex
bibfiles "IEEEexample" bibfiles "xampl"
options "test" options "test"
\end_inset \end_inset
@ -6175,6 +6193,12 @@ options "test"
\end_layout \end_layout
\begin_layout Standard
with wrong
\backslash
addcontentsline:
\end_layout
\begin_layout Standard \begin_layout Standard
\begin_inset ERT \begin_inset ERT
@ -6203,7 +6227,7 @@ addcontentsline{toc}{section}{test}
\begin_inset CommandInset bibtex \begin_inset CommandInset bibtex
LatexCommand bibtex LatexCommand bibtex
bibfiles "IEEEexample" bibfiles "xampl"
options "test" options "test"
\end_inset \end_inset
@ -6211,6 +6235,31 @@ options "test"
\end_layout \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_layout Standard
\begin_inset CommandInset index_print \begin_inset CommandInset index_print
@ -6222,6 +6271,10 @@ type "idx"
\end_layout \end_layout
\begin_layout Standard
normal nomenclature:
\end_layout
\begin_layout Standard \begin_layout Standard
\begin_inset CommandInset nomencl_print \begin_inset CommandInset nomencl_print
@ -6234,7 +6287,7 @@ hello
\end_layout \end_layout
\begin_layout Standard \begin_layout Standard
manually set width:
\begin_inset ERT \begin_inset ERT
status collapsed status collapsed
@ -6258,6 +6311,10 @@ set_width "none"
\end_layout \end_layout
\begin_layout Standard
nomenclature with set width:
\end_layout
\begin_layout Standard \begin_layout Standard
\begin_inset CommandInset nomencl_print \begin_inset CommandInset nomencl_print

View File

@ -541,6 +541,7 @@ or by a page break \pagebreak
or by a defined page break \pagebreak % again with a comment or by a defined page break \pagebreak % again with a comment
[4] [4]
\section{Special characters\index{Special characters}} \section{Special characters\index{Special characters}}
Then one has those macros with a long name for a short meaning, like 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 A sub\textsubscript{sc\emph{ript}} and super\textsuperscript{script
with $a^2+b^2=c^2$ math}. with $a^2+b^2=c^2$ math}.
\section{Mathematics\index{Mathematics}} \section{Mathematics\index{Mathematics}}
Let $f:\left[ a,b\right] \rightarrow% Let $f:\left[ a,b\right] \rightarrow%
@ -579,25 +581,47 @@ Let $f:\left[ a,b\right] \rightarrow%
%EndExpansion %EndExpansion
$. $.
\addcontentsline{toc}{section}{test}
\section{Lists/Indices}
single \textbackslash{}addcontentsline: \addcontentsline{toc}{section}{test}
with \textbackslash{}addcontentsline and \textbackslash{}phantomsection:
\bibliographystyle{test} \bibliographystyle{test}
\addcontentsline{toc}{section}{\refname} \phantomsection\addcontentsline{toc}{section}{\refname}\bibliography{xampl}
\bibliography{IEEEexample}
normal:
\bibliographystyle{test} \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} \bibliographystyle{test}
\addcontentsline{toc}{section}{test} \addcontentsline{toc}{section}{\refname}\nocite{*}
\bibliography{IEEEexample} \bibliography{xampl}
normal index:
\printindex{} \printindex{}
normal nomenclature:
\printnomenclature hello \printnomenclature hello
\settowidth{\nomlabelwidth}{URL2} manually set width: \settowidth{\nomlabelwidth}{URL2} \printnomenclature{}
\printnomenclature{}
nomenclature with set width:
\printnomenclature[0.02\linewidth]{} \printnomenclature[0.02\linewidth]{}

View File

@ -3990,6 +3990,10 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer,
continue; continue;
} else if (t2.cs() == "bibliography") } else if (t2.cs() == "bibliography")
output = false; output = false;
else if (t2.cs() == "phantomsection") {
output = false;
continue;
}
else if (t2.cs() == "addcontentsline") { else if (t2.cs() == "addcontentsline") {
// get the 3 arguments of \addcontentsline // get the 3 arguments of \addcontentsline
p.getArg('{', '}'); 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") { else if (t.cs() == "addcontentsline") {
context.check_layout(os); context.check_layout(os);
// get the 3 arguments of \addcontentsline // get the 3 arguments of \addcontentsline
@ -4046,6 +4057,9 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer,
BibOpts = bibliographystyle; BibOpts = bibliographystyle;
else else
BibOpts = BibOpts + ',' + bibliographystyle; 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"; os << "options " << '"' << BibOpts << '"' << "\n";
end_inset(os); end_inset(os);