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
\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

View 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]{}

View 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);