commit 1503b8285b066868d8291d4967673e6b6c202bd3
Author: Enrico Forestieri <[email protected]>
Date:   Tue Jul 22 14:11:46 2025 +0200

    Allow including the symbols system file from the user one
    
    Until now, in order to make additions to the lib/symbols file
    one should have copied it to the user dir and modify the copy.
    Of course, when the system file is updated one should transfer
    the modifications to the copy. Of course, this is tedious and
    error prone. This commit introduces the possibility of including
    the system file from the one in the user directory by using the
    directive "include_system_file", which is equivalent to inserting
    the system symbols file at that point. Then, one can make additions
    or modifications as desired.
---
 lib/symbols                |  5 +++++
 src/mathed/MathFactory.cpp | 40 +++++++++++++++++++++++++++++++---------
 status.24x                 |  5 +++++
 3 files changed, 41 insertions(+), 9 deletions(-)

diff --git a/lib/symbols b/lib/symbols
index aac3ee3b6c..48f3abfe57 100644
--- a/lib/symbols
+++ b/lib/symbols
@@ -38,6 +38,11 @@
 # New symbols for font packages may be created using
 # development/tools/generate_symbols_list.py (but may require manual fixes
 # as well).
+#
+# Additions and/or modifications to this file may be performed by creating
+# a file named symbols in the user directory and by adding the directive
+# "include_system_file" (w/o quotes) at the very beginning of a line.
+# This will be equivalent to inserting the system symbols file at that point.
 
 # decorations
 acute               decoration none
diff --git a/src/mathed/MathFactory.cpp b/src/mathed/MathFactory.cpp
index 2a25d8464a..2777489283 100644
--- a/src/mathed/MathFactory.cpp
+++ b/src/mathed/MathFactory.cpp
@@ -140,16 +140,8 @@ bool isUnicodeSymbolAvailable(docstring const & name, 
char_type & c)
 }
 
 
-void initSymbols()
+void initSymbols(ifstream & fs)
 {
-       FileName const filename = libFileSearch(string(), "symbols");
-       LYXERR(Debug::MATHED, "read symbols from " << filename);
-       if (filename.empty()) {
-               lyxerr << "Could not find symbols file" << endl;
-               return;
-       }
-
-       ifstream fs(filename.toFilesystemEncoding().c_str());
        // limit the size of strings we read to avoid memory problems
        fs >> setw(65636);
        string line;
@@ -180,6 +172,23 @@ void initSymbols()
                } else if (skip)
                        continue;
 
+               // special case of include_system_file
+               if (line.size() >= 19 && line.substr(0, 19) == 
"include_system_file") {
+                       string tmp;
+                       istringstream is(line);
+                       is >> setw(65536) >> tmp;
+                       FileName const sysfile = libFileSearch(string(), 
"symbols",
+                                                              string(), 
must_exist, true);
+                       LYXERR(Debug::MATHED, "read symbols from " << sysfile);
+                       if (sysfile.empty()) {
+                               lyxerr << "Could not find system symbols file" 
<< endl;
+                               continue;
+                       }
+                       ifstream sysfs(sysfile.toFilesystemEncoding().c_str());
+                       initSymbols(sysfs);
+                       continue;
+               }
+
                // special case of pre-defined macros
                if (line.size() > 8 && line.substr(0, 5) == "\\def\\") {
                        //lyxerr << "macro definition: '" << line << '\'' << 
endl;
@@ -340,6 +349,19 @@ void initSymbols()
                        << "  requires: " << tmp.required
                        << "  hidden: " << tmp.hidden << '\'');
        }
+}
+
+
+void initSymbols()
+{
+       FileName const filename = libFileSearch(string(), "symbols");
+       LYXERR(Debug::MATHED, "read symbols from " << filename);
+       if (filename.empty()) {
+               lyxerr << "Could not find symbols file" << endl;
+               return;
+       }
+       ifstream fs(filename.toFilesystemEncoding().c_str());
+       initSymbols(fs);
        string tmp = "cmm";
        string tmp2 = "cmsy";
        has_math_fonts = isMathFontAvailable(tmp) && isMathFontAvailable(tmp2);
diff --git a/status.24x b/status.24x
index c53d66fcd8..55a1cd1e72 100644
--- a/status.24x
+++ b/status.24x
@@ -20,6 +20,11 @@ What's new
 
 * MISCELLANEOUS
 
+- It is now possible to include the symbols system file from the corresponding
+  file in the user directory by means of the directive "include_system_file".
+  This will be equivalent to inserting the system symbols file at that point.
+  The symbols file is used in mathed and now it is possible to perform own
+  additions/modifications without the need of making a copy in the user dir.
 
 
 * TEX2LYX IMPROVEMENTS
-- 
lyx-cvs mailing list
[email protected]
https://lists.lyx.org/mailman/listinfo/lyx-cvs

Reply via email to