The attached patch switches from \newcommand to \providecommand for all LyX-specific command definitions. (For some efinitons we already use \providecomand.) It turned out that \newcommand definition could break TeX-LyX roundtrips when the user modifies the TeX file, see the recent tex2lyx discussion.

The patch will go in when nobody objects.

regards Uwe
Index: LaTeXFeatures.cpp
===================================================================
--- LaTeXFeatures.cpp	(revision 30994)
+++ LaTeXFeatures.cpp	(working copy)
@@ -58,12 +58,12 @@
 	"\\providecommand{\\lyx}{l\\kern-.1667em\\lower.25em\\hbox{y}\\kern-.125em...@}");
 
 static docstring const lyxline_def = from_ascii(
-	"\\newcommand{\\lyxline}[1][1pt]{%\n"
+	"\\providecommand{\\lyxline}[1][1pt]{%\n"
 	"  \\par\\noindent%\n"
 	"  \\rule[.5ex]{\\linewidth}{#1}\\par}");
 
 static docstring const noun_def = from_ascii(
-	"\\newcommand{\\noun}[1]{\\textsc{#1}}");
+	"\\providecommand{\\noun}[1]{\\textsc{#1}}");
 
 static docstring const lyxarrow_def = from_ascii(
 	"\\DeclareRobustCommand*{\\lyxarrow}{%\n"
@@ -148,11 +148,11 @@
 
 static docstring const binom_def = from_ascii(
 	"%% Binom macro for standard LaTeX users\n"
-	"\\newcommand{\\binom}[2]{{#1 \\choose #2}}\n");
+	"\\providecommand{\\binom}[2]{{#1 \\choose #2}}\n");
 
 static docstring const mathcircumflex_def = from_ascii(
 	"%% For printing a cirumflex inside a formula\n"
-	"\\newcommand{\\mathcircumflex}[0]{\\mbox{\\^{}}}\n");
+	"\\providecommand{\\mathcircumflex}[0]{\\mbox{\\^{}}}\n");
 
 static docstring const tabularnewline_def = from_ascii(
 	"%% Because html converters don't know tabularnewline\n"
@@ -167,7 +167,7 @@
 // Idea from http://www.tex.ac.uk/cgi-bin/texfaq2html?label=unkgrfextn
 static docstring const lyxdot_def = from_ascii(
 	"%% A simple dot to overcome graphicx limitations\n"
-	"\\newcommand{\\lyxdot}{.}\n");
+	"\\providecommand{\\lyxdot}{.}\n");
 
 static docstring const changetracking_dvipost_def = from_ascii(
 	"%% Change tracking with dvipost\n"
@@ -176,23 +176,23 @@
 	"\\dvipost{osend color pop}\n"
 	"\\dvipost{cbstart color push Blue}\n"
 	"\\dvipost{cbend color pop}\n"
-	"\\newcommand{\\lyxadded}[3]{\\changestart#3\\changeend}\n"
-	"\\newcommand{\\lyxdeleted}[3]{%\n"
+	"\\providecommand{\\lyxadded}[3]{\\changestart#3\\changeend}\n"
+	"\\providecommand{\\lyxdeleted}[3]{%\n"
 	"\\changestart\\overstrikeon#3\\overstrikeoff\\changeend}\n");
 
 static docstring const changetracking_xcolor_ulem_def = from_ascii(
 	"%% Change tracking with ulem\n"
-	"\\newcommand{\\lyxadded}[3]{{\\color{lyxadded}#3}}\n"
-	"\\newcommand{\\lyxdeleted}[3]{{\\color{lyxdeleted}\\sout{#3}}}\n");
+	"\\providecommand{\\lyxadded}[3]{{\\color{lyxadded}#3}}\n"
+	"\\providecommand{\\lyxdeleted}[3]{{\\color{lyxdeleted}\\sout{#3}}}\n");
 
 static docstring const changetracking_xcolor_ulem_hyperref_def = from_ascii(
 	"%% Change tracking with ulem\n"
-	"\\newcommand{\\lyxadded}[3]{{\\texorpdfstring{\\color{lyxadded}}{}#3}}\n"
-	"\\newcommand{\\lyxdeleted}[3]{{\\texorpdfstring{\\color{lyxdeleted}\\sout{#3}}{}}}\n");
+	"\\providecommand{\\lyxadded}[3]{{\\texorpdfstring{\\color{lyxadded}}{}#3}}\n"
+	"\\providecommand{\\lyxdeleted}[3]{{\\texorpdfstring{\\color{lyxdeleted}\\sout{#3}}{}}}\n");
 
 static docstring const changetracking_none_def = from_ascii(
-	"\\newcommand{\\lyxadded}[3]{#3}\n"
-	"\\newcommand{\\lyxdeleted}[3]{}\n");
+	"\\providecommand{\\lyxadded}[3]{#3}\n"
+	"\\providecommand{\\lyxdeleted}[3]{}\n");
 
 static docstring const textgreek_def = from_ascii(
 	"\\providecommand*{\\perispomeni}{\\char126}\n"
@@ -210,7 +210,7 @@
 	"\\AtBeginDocument{\\DeclareFontEncoding{T2A}{}{}}\n");
 
 static docstring const lyxmathsym_def = from_ascii(
-	"\\newcommand{\\lyxmathsym}[1]{\\ifmmode\\begingroup\\def...@ld{bold}\n"
+	"\\providecommand{\\lyxmathsym}[1]{\\ifmmode\\begingroup\\def...@ld{bold}\n"
 	"  \\text{\\ifx\\m...@version\\b@ld\\bfseries\\fi#1}\\endgroup\\else#1\\fi}\n");
 
 static docstring const papersizedvi_def = from_ascii(
@@ -221,24 +221,24 @@
 	"\\pdfpagewidth\\paperwidth\n");
 
 static docstring const cedilla_def = from_ascii(
-	"\\newcommand{\\docedilla}[2]{\\underaccent{#1\\mathchar'30}{#2}}\n"
-	"\\newcommand{\\cedilla}[1]{\\mathpalette\\docedilla{#1}}\n");
+	"\\providecommand{\\docedilla}[2]{\\underaccent{#1\\mathchar'30}{#2}}\n"
+	"\\providecommand{\\cedilla}[1]{\\mathpalette\\docedilla{#1}}\n");
 
 static docstring const subring_def = from_ascii(
-	"\\newcommand{\\dosubring}[2]{\\underaccent{#1\\mathchar'27}{#2}}\n"
-	"\\newcommand{\\subring}[1]{\\mathpalette\\dosubring{#1}}\n");
+	"\\providecommand{\\dosubring}[2]{\\underaccent{#1\\mathchar'27}{#2}}\n"
+	"\\providecommand{\\subring}[1]{\\mathpalette\\dosubring{#1}}\n");
 
 static docstring const subdot_def = from_ascii(
-	"\\newcommand{\\dosubdot}[2]{\\underaccent{#1.}{#2}}\n"
-	"\\newcommand{\\subdot}[1]{\\mathpalette\\dosubdot{#1}}\n");
+	"\\providecommand{\\dosubdot}[2]{\\underaccent{#1.}{#2}}\n"
+	"\\providecommand{\\subdot}[1]{\\mathpalette\\dosubdot{#1}}\n");
 
 static docstring const subhat_def = from_ascii(
-	"\\newcommand{\\dosubhat}[2]{\\underaccent{#1\\mathchar'136}{#2}}\n"
-	"\\newcommand{\\subhat}[1]{\\mathpalette\\dosubhat{#1}}\n");
+	"\\providecommand{\\dosubhat}[2]{\\underaccent{#1\\mathchar'136}{#2}}\n"
+	"\\providecommand{\\subhat}[1]{\\mathpalette\\dosubhat{#1}}\n");
 
 static docstring const subtilde_def = from_ascii(
-	"\\newcommand{\\dosubtilde}[2]{\\underaccent{#1\\mathchar'176}{#2}}\n"
-	"\\newcommand{\\subtilde}[1]{\\mathpalette\\dosubtilde{#1}}\n");
+	"\\providecommand{\\dosubtilde}[2]{\\underaccent{#1\\mathchar'176}{#2}}\n"
+	"\\providecommand{\\subtilde}[1]{\\mathpalette\\dosubtilde{#1}}\n");
 
 static docstring const dacute_def = from_ascii(
 	"\\DeclareMathAccent{\\dacute}{\\mathalpha}{operators}{'175}\n");
@@ -254,11 +254,11 @@
 	"\\DeclareMathAccent{\\rcap}{\\mathord}{tipasymb}{'20}\n");
 
 static docstring const ogonek_def = from_ascii(
-	"\\newcommand{\\doogonek}[2]{\\setbox0=\\hbox{$#1#2$}\\underaccent{#1\\mkern-6mu\n"
+	"\\providecommand{\\doogonek}[2]{\\setbox0=\\hbox{$#1#2$}\\underaccent{#1\\mkern-6mu\n"
 	"  \\ifx#2O\\hskip0.5\\wd0\\else\\ifx#2U\\hskip0.5\\wd0\\else\\hskip\\wd0\\fi\\fi\n"
 	"  \\ifx#2o\\mkern-2mu\\else\\ifx#2e\\mkern-1mu\\fi\\fi\n"
 	"  \\mathchar\"0\\hexnum...@\\symtipasymb0c}{#2}}\n"
-	"\\newcommand{\\ogonek}[1]{\\mathpalette\\doogonek{#1}}\n");
+	"\\providecommand{\\ogonek}[1]{\\mathpalette\\doogonek{#1}}\n");
 
 /////////////////////////////////////////////////////////////////////
 //
@@ -1000,7 +1000,7 @@
 {
 	odocstringstream os;
 	os << "\\addto\\captions" << lang
-	   << "{\\renewcommand{\\" << type << "name}{" << name << "}}\n";
+	   << "{\\providecommand{\\" << type << "name}{" << name << "}}\n";
 	return os.str();
 }
 }

Reply via email to