On Fri, Aug 11, 2023 at 8:09 PM Jürgen Spitzmüller <jspi...@gmail.com> wrote:
>
> Am Freitag, dem 11.08.2023 um 17:39 +0200 schrieb Jürgen Spitzmüller:
> > Should be fixed now.
>
> Not yet. It does compile, but the references are broken.

Jürgen, your code should work, you just forgot
to  change the category code of @.
See the patch prettyref-detokenize.patch.

But I think we should note it could potentially
change the behaviour of the package, If you'll
export the file newfile1.lyx after applying prettyref-detokenize.patch,
you will get different results if the language of the document
 is english or french.

I propose a different approach. see the patch prettyref.patch.
I'm not sure what is the best way to stream strings into the latex source,
so feel free to change things, and if you have the patience to explain
what I should have done, I'll appreciate it :)

> lyx-devel mailing list
> lyx-devel@lists.lyx.org
> http://lists.lyx.org/mailman/listinfo/lyx-devel
diff --git a/src/LaTeXFeatures.cpp b/src/LaTeXFeatures.cpp
index 0e678ea62a..ffddef2b85 100644
--- a/src/LaTeXFeatures.cpp
+++ b/src/LaTeXFeatures.cpp
@@ -1289,7 +1289,9 @@ string const LaTeXFeatures::getPackages() const
 	if (!runparams_.isFullUnicode() && useBabel()
 	    && mustProvide("prettyref") && contains(getActiveChars(), ':')) {
 		packages << "% Make prettyref compatible with babel active colon\n"
-			 << "\\def\\prettyref#1{\\expandafter\\@prettyref\\detokenize{#1:}}\n";
+			 << "\\makeatletter\n"
+			 << "\\def\\prettyref#1{\\expandafter\\@prettyref\\detokenize{#1:}}\n"
+			 << "\\makeatother\n";
 	}
 
 	if (mustProvide("changebar")) {
diff --git a/src/LaTeXFeatures.cpp b/src/LaTeXFeatures.cpp
index 0e678ea62a..6c53e19e23 100644
--- a/src/LaTeXFeatures.cpp
+++ b/src/LaTeXFeatures.cpp
@@ -1289,7 +1289,18 @@ string const LaTeXFeatures::getPackages() const
 	if (!runparams_.isFullUnicode() && useBabel()
 	    && mustProvide("prettyref") && contains(getActiveChars(), ':')) {
 		packages << "% Make prettyref compatible with babel active colon\n"
-			 << "\\def\\prettyref#1{\\expandafter\\@prettyref\\detokenize{#1:}}\n";
+			    "\\bgroup\n"
+			    "\\makeatletter\n"
+			    "\\catcode`:=13\n"
+			    "\\gdef\\prettyref#1{\\@prettyref#1:}\n"
+			    "\\gdef\\@prettyref#1:#2:{%\n"
+			    " 	\\expandafter\\ifx\\csname pr@#1\\endcsname\\relax\n"
+			    "		\\PackageWarning{prettyref}{Reference format #1\\space undefined}%\n"
+			    "		\\ref{#1:#2}%\n"
+			    "	\\else\n"
+			    "		\\csname pr@#1\\endcsname{#1:#2}%\n"
+			    "	\\fi}\n"
+			    "\\egroup\n";
 	}
 
 	if (mustProvide("changebar")) {

Attachment: newfile1.lyx
Description: application/lyx

-- 
lyx-devel mailing list
lyx-devel@lists.lyx.org
http://lists.lyx.org/mailman/listinfo/lyx-devel

Reply via email to