From: Georg Baum Date: Fri, 22 Feb 2013 21:21:56 +0000 (+0100) Subject: Fix bug #8552 X-Git-Tag: 2.1.0beta1~613 X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=48c9926d87aa1b6e1b2e9e3f7d9be7a673a27484;p=features.git Fix bug #8552 tex2lyx skips LyX preamble code only if it thinks that the file was created by LyX (i.e. special comments are found). I don't like that, but this is how it works and therefore the special comment neds to be added if the theorem commands are to be skipped. This header makes also the temporary setting of in_lyx_preamble obsolete, which caused skipping of user preamble commands, which were not re-added by LyX. --- diff --git a/src/tex2lyx/Preamble.cpp b/src/tex2lyx/Preamble.cpp index 72800eca95..b6155da9a8 100644 --- a/src/tex2lyx/Preamble.cpp +++ b/src/tex2lyx/Preamble.cpp @@ -1410,16 +1410,11 @@ void Preamble::parse(Parser & p, string const & forceclass, string const name = p.verbatim_item(); string const body1 = p.verbatim_item(); string const body2 = p.verbatim_item(); - // store the in_lyx_preamble setting - bool const was_in_lyx_preamble = in_lyx_preamble; - if (name == "subref" - || name == "thmref" - || name == "lemref") { - p.skip_spaces(); - in_lyx_preamble = true; - } // only non-lyxspecific stuff - if (!in_lyx_preamble) { + if (in_lyx_preamble && + (name == "subref" || name == "thmref" || name == "lemref")) + p.skip_spaces(); + else { ostringstream ss; ss << '\\' << t.cs(); ss << '{' << name << '}' @@ -1427,15 +1422,13 @@ void Preamble::parse(Parser & p, string const & forceclass, << '{' << body2 << '}'; h_preamble << ss.str(); } - // restore the in_lyx_preamble setting - in_lyx_preamble = was_in_lyx_preamble; } else if (t.cs() == "AtBeginDocument") { string const name = p.verbatim_item(); - // store the in_lyx_preamble setting - bool const was_in_lyx_preamble = in_lyx_preamble; - if (name == "\\providecommand\\partref[1]{\\ref{part:#1}}" + // only non-lyxspecific stuff + if (in_lyx_preamble && + (name == "\\providecommand\\partref[1]{\\ref{part:#1}}" || name == "\\providecommand\\chapref[1]{\\ref{chap:#1}}" || name == "\\providecommand\\secref[1]{\\ref{sec:#1}}" || name == "\\providecommand\\subref[1]{\\ref{sub:#1}}" @@ -1449,19 +1442,14 @@ void Preamble::parse(Parser & p, string const & forceclass, || name == "\\providecommand\\lemref[1]{\\ref{lem:#1}}" || name == "\\providecommand\\thmref[1]{\\ref{thm:#1}}" || name == "\\providecommand\\corref[1]{\\ref{cor:#1}}" - || name == "\\providecommand\\propref[1]{\\ref{prop:#1}}") { + || name == "\\providecommand\\propref[1]{\\ref{prop:#1}}")) p.skip_spaces(); - in_lyx_preamble = true; - } - // only non-lyxspecific stuff - if (!in_lyx_preamble) { + else { ostringstream ss; ss << '\\' << t.cs(); ss << '{' << name << '}'; h_preamble << ss.str(); } - // restore the in_lyx_preamble setting - in_lyx_preamble = was_in_lyx_preamble; } else if (t.cs() == "newcommand" || t.cs() == "newcommandx" diff --git a/src/tex2lyx/test/test-insets.lyx.lyx b/src/tex2lyx/test/test-insets.lyx.lyx index 3d58cd7455..5f2554cbe0 100644 --- a/src/tex2lyx/test/test-insets.lyx.lyx +++ b/src/tex2lyx/test/test-insets.lyx.lyx @@ -8,6 +8,7 @@ % Load refstyle before prettyref so that prettyref wins. % The real refstyle tests are in test-refstyle-theorems.tex. \usepackage{refstyle} +\AtBeginDocument{\providecommand\secref[1]{\ref{sec:#1}}} \def\mycommand{\textquestiondown} diff --git a/src/tex2lyx/test/test-refstyle-theorems.lyx.lyx b/src/tex2lyx/test/test-refstyle-theorems.lyx.lyx index e8cb4499d7..01d1b1b5dc 100644 --- a/src/tex2lyx/test/test-refstyle-theorems.lyx.lyx +++ b/src/tex2lyx/test/test-refstyle-theorems.lyx.lyx @@ -4,60 +4,7 @@ \begin_header \textclass book \begin_preamble - - - - -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% LyX specific LaTeX commands. - -\floatstyle{ruled} -\newfloat{algorithm}{tbp}{loa}[chapter] -\providecommand{\algorithmname}{Algorithm} -\floatname{algorithm}{\protect\algorithmname} - - - -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Textclass specific LaTeX commands. -\theoremstyle{plain} -\newtheorem{thm}{}\theoremstyle{plain} -\newtheorem{lem}[thm]{}\theoremstyle{plain} -\newtheorem{cor}[thm]{}\theoremstyle{plain} -\newtheorem{prop}[thm]{}\theoremstyle{plain} -\newtheorem{conjecture}[thm]{}\theoremstyle{plain} -\newtheorem{fact}[thm]{}\theoremstyle{definition} -\newtheorem{defn}[thm]{}\theoremstyle{definition} -\newtheorem{example}[thm]{}\theoremstyle{definition} -\newtheorem{problem}[thm]{}\theoremstyle{definition} -\newtheorem{xca}[thm]{}\theoremstyle{remark} -\newtheorem{rem}[thm]{}\theoremstyle{remark} -\newtheorem{claim}[thm]{}\ifx\proof\undefined -\newenvironment{proof}[1][\protect\proofname]{\par -\normalfont\topsep6\p@\@plus6\p@\relax -\trivlist -\itemindent\parindent -\item[\hskip\labelsep\scshape #1]\ignorespaces -}{% -\endtrivlist\@endpefalse -} -\providecommand{\proofname}{Proof} -\fi - - - \usepackage{babel} -\providecommand{\claimname}{Claim} -\providecommand{\conjecturename}{Conjecture} -\providecommand{\corollaryname}{Corollary} -\providecommand{\definitionname}{Definition} -\providecommand{\examplename}{Example} -\providecommand{\exercisename}{Exercise} -\providecommand{\factname}{Fact} -\providecommand{\lemmaname}{Lemma} -\providecommand{\problemname}{Problem} -\providecommand{\propositionname}{Proposition} -\providecommand{\remarkname}{Remark} -\providecommand{\theoremname}{Theorem} - \end_preamble \use_default_options false diff --git a/src/tex2lyx/test/test-refstyle-theorems.tex b/src/tex2lyx/test/test-refstyle-theorems.tex index 70ad4c6501..e0e2944e19 100644 --- a/src/tex2lyx/test/test-refstyle-theorems.tex +++ b/src/tex2lyx/test/test-refstyle-theorems.tex @@ -1,3 +1,5 @@ +%% LyX trick_preamble_code_into_believing_that_this_was_created_by_lyx created this file. For more info, see http://www.lyx.org/. +%% Do not edit unless you really know what you are doing. \documentclass[english]{book} \usepackage[T1]{fontenc} \usepackage[latin9]{inputenc}