I often use \S in citations, but it does not get displayed properly in the label. The reason is that unicodesymbols uses \textsection instead, and if I add an extra line:

0x00a7 "\\S" ""

that doesn't work either, because Encodings::fromLaTeXCommand doesn't consider 'extra' LaTeX commands unless it's looking for an exact match. So if it sees \S4 or \S 4, then it won't find it. I tried modifying that routine so it would look at the 'other' commands, but I failed.

This is really a special case, so I'm inclined just to handle it as one via the attached hack-ish patch. But maybe someone else knows how to fix Encodings::fromLaTeXCommand?

Riki

From 6807b77edd286f1d02a9698433b75519cb1d8175 Mon Sep 17 00:00:00 2001
From: Richard Kimberly Heck <rikih...@lyx.org>
Date: Thu, 27 Jul 2023 01:18:55 -0400
Subject: [PATCH] Hack to display section symbol

---
 lib/unicodesymbols |  1 -
 src/BiblioInfo.cpp | 12 ++++++++++++
 2 files changed, 12 insertions(+), 1 deletion(-)

diff --git a/lib/unicodesymbols b/lib/unicodesymbols
index 458a9ee1ea..1b2a88d136 100644
--- a/lib/unicodesymbols
+++ b/lib/unicodesymbols
@@ -68,7 +68,6 @@
 0x00a5 "\\textyen"                "textcomp" "force=cp862;cp1255;cp1256;euc-jp;euc-jp-platex;jis;shift-jis-platex" "\\yen" "amssymb" # YEN SIGN
 0x00a6 "\\textbrokenbar"          "textcomp" "force=cp1255;cp1256;iso8859-7;euc-jp;euc-jp-platex;utf8-platex" # BROKEN BAR
 0x00a7 "\\textsection"            "textcomp" "force=cp1255;cp1256;iso8859-7;euc-cn;euc-jp;euc-kr;euc-tw;gbk;jis;shift-jis-platex" "\\mathsection" "" # SECTION SIGN
-0x00a7 "\\S" ""
 0x00a8 "\\textasciidieresis"      "textcomp" "force=cp1255;cp1256;iso8859-7;euc-cn;euc-jp;euc-kr;gbk;jis;shift-jis-platex" # DIAERESIS
 0x00a9 "\\textcopyright"          "textcomp" "force=cp1255;cp1256;koi8-u;iso8859-7;euc-jp;euc-jp-platex;utf8-platex" # COPYRIGHT SIGN
 0x00a9 "\\copyright" ""
diff --git a/src/BiblioInfo.cpp b/src/BiblioInfo.cpp
index 29ade833ce..14023e38d2 100644
--- a/src/BiblioInfo.cpp
+++ b/src/BiblioInfo.cpp
@@ -333,6 +333,7 @@ docstring convertLaTeXCommands(docstring const & str)
 
 	bool scanning_cmd = false;
 	bool scanning_math = false;
+	bool is_section = false;
 	bool escaped = false; // used to catch \$, etc.
 	while (!val.empty()) {
 		char_type const ch = val[0];
@@ -355,13 +356,24 @@ docstring convertLaTeXCommands(docstring const & str)
 		// discard characters until we hit something that
 		// isn't alpha.
 		if (scanning_cmd) {
+			if (!is_section && ch == 'S') {
+				is_section = true;
+				val = val.substr(1);
+				continue;
+			}
 			if (isAlphaASCII(ch)) {
+				is_section = false;
 				val = val.substr(1);
 				escaped = false;
 				continue;
+			} else if (is_section) {
+				ret.push_back(0x00a7);
+				is_section = false;
+				continue;
 			}
 			// so we're done with this command.
 			// now we fall through and check this character.
+			is_section = false;
 			scanning_cmd = false;
 		}
 
-- 
2.41.0

-- 
lyx-devel mailing list
lyx-devel@lists.lyx.org
http://lists.lyx.org/mailman/listinfo/lyx-devel
  • \S Richard Kimberly Heck

Reply via email to