]> git.lyx.org Git - features.git/commitdiff
Handle text-only wasy symbols correctly.
authorGeorg Baum <baum@lyx.org>
Wed, 9 Jan 2013 21:23:07 +0000 (22:23 +0100)
committerGeorg Baum <baum@lyx.org>
Thu, 10 Jan 2013 20:22:54 +0000 (21:22 +0100)
Some macros defined by wasysym.sty work only in text mode: They either
produce an error in math mode, or wrong output. These symbols are now marked
as text symbols, so that no \ensuremath is created for LaTeX export if they
appear inside \text{}, and the correct images are created.

development/tools/generate_symbols_images.py
lib/symbols
src/mathed/InsetMathSymbol.cpp
src/mathed/InsetMathSymbol.h

index a043c9c94ec97edb46e0eec4259c25661736eeed..e04962e4e07bb124828bc71814a4fb481e446b51 100644 (file)
@@ -38,19 +38,23 @@ def getlist(lyxexe, lyxfile):
     cmd = "%s %s -dbg mathed -x lyx-quit" % (lyxexe, lyxfile)
     proc = subprocess.Popen(cmd, shell=True, stderr=subprocess.PIPE)
     (stdout, stderr) = proc.communicate()
-    regexp = re.compile(r'.*: read symbol \'(\S+)\s+inset:\s+(\S+)')
+    regexp = re.compile(r'.*: read symbol \'(\S+)\s+inset:\s+(\S+)\s+draw:\s+(\S*)\s+extra:\s+(\S+)')
     # These insets are more complex than simply symbols, so the images need to
     # be created manually
     skipinsets = ['big', 'font', 'lyxblacktext', 'matrix', 'mbox', 'oldfont', \
                   'ref', 'split', 'space', 'style']
-    symbols = []
+    mathsymbols = []
+    textsymbols = []
     for line in stderr.split('\n'):
         m = regexp.match(line)
         if m:
             inset = m.group(2)
             if not inset in skipinsets:
-                symbols.append(m.group(1))
-    return symbols
+                if m.group(4) == 'textmode':
+                    textsymbols.append(m.group(1))
+                else:
+                    mathsymbols.append(m.group(1))
+    return (mathsymbols, textsymbols)
 
 
 def getreplacements(filename):
@@ -98,7 +102,7 @@ def getmakefileentries(filename):
     return items
 
 
-def createimage(name, path, template, lyxexe, tempdir, replacements, toolbaritems, makefileentries):
+def createimage(name, path, template, lyxexe, tempdir, math, replacements, toolbaritems, makefileentries):
     """ Create the image file for symbol name in path. """
 
     if name in replacements.keys():
@@ -130,7 +134,10 @@ def createimage(name, path, template, lyxexe, tempdir, replacements, toolbaritem
     print 'Generating ' + name + suffix
     lyxname = os.path.join(tempdir, filename)
     lyxfile = open(lyxname + '.lyx', 'wt')
-    lyxfile.write(template.replace('$a$', '$\\' + name + '$'))
+    if math:
+        lyxfile.write(template.replace('$a$', '$\\' + name + '$'))
+    else:
+        lyxfile.write(template.replace('$a$', '$\\text{\\' + name + '}$'))
     lyxfile.close()
     cmd = "%s %s.lyx -e dvi" % (lyxexe, lyxname)
     proc = subprocess.Popen(cmd, shell=True)
@@ -170,7 +177,7 @@ def main(argv):
 
     if len(argv) == 3:
         (base, ext) = os.path.splitext(argv[0])
-        symbols = getlist(argv[1], base)
+        (mathsymbols, textsymbols) = getlist(argv[1], base)
         cppfile = os.path.join(os.path.dirname(base), '../../src/frontends/qt4/GuiApplication.cpp')
         replacements = getreplacements(cppfile)
         uifile = os.path.join(os.path.dirname(base), '../../lib/ui/stdtoolbars.inc')
@@ -182,8 +189,10 @@ def main(argv):
         template = templatefile.read()
         templatefile.close()
         tempdir = tempfile.mkdtemp()
-        for i in symbols:
-            createimage(i, argv[2], template, argv[1], tempdir, replacements, toolbaritems, makefileentries)
+        for i in mathsymbols:
+            createimage(i, argv[2], template, argv[1], tempdir, True, replacements, toolbaritems, makefileentries)
+        for i in textsymbols:
+            createimage(i, argv[2], template, argv[1], tempdir, False, replacements, toolbaritems, makefileentries)
         shutil.rmtree(tempdir)
     else:
         error(usage(argv[0]))
index a0e30a9b32d3975b2942f650bac047a2ecf6b26f..ad5424a40edcb925939f963b2cf1e5ba0ee2b641 100644 (file)
@@ -658,21 +658,20 @@ lyxleft            msa          76   0 mathord  &larr;
 
 male               wasy          26  0 x        &male;
 female             wasy          25  0 x        &female;
-currency           wasy          27  0 x        &curren;
-phone              wasy          7   0 x        &phone;
-recorder           wasy          6   0 x        &telrec;
-clock              wasy          28  0 x        &clock;
+currency           wasy          27  0 textmode &curren; wasysym # works in text mode only (produces \oe in math mode)
+phone              wasy          7   0 textmode &phone;  wasysym # works in text mode only (produces \Upsilon in math mode)
+recorder           wasy          6   0 textmode &telrec; wasysym # works in text mode only (produces \Sigma in math mode)
+clock              wasy          28  0 textmode &clock;  wasysym # works in text mode only (produces \o in math mode)
 lightning          wasy          18  0 x        &#x2607;
-pointer            wasy          9   0 x        x
-RIGHTarrow         wasy          17  0 x        &#x25B6;
-LEFTarrow          wasy          16  0 x        &#x25C0;
-UParrow            wasy          75  0 x        &#x25B2;
-DOWNarrow          wasy          76  0 x        &#x25BC;
-#AC                 wasy          n0.5pt\wasyfamily\char58\kern0.5pt}}
-#HF         {\leavevmode
-#   \lower0.9pt\hbox to 0pt{\kern0.5pt\wasyfamily\char58\hss}%
-#   \raise0.9pt\hbox{\kern0.5pt\wasyfamily\char58\kern0.5pt}}
-#VHF                wasy          64  0 x        x
+# FIXME Display is wrong: qt does not display characters at the \t position (0x09)
+pointer            wasy          9   0 textmode x        wasysym # works in text mode only (produces \Psi in math mode)
+RIGHTarrow         wasy          17  0 textmode &#x25B6; wasysym # works in text mode only (produces \jmath in math mode)
+LEFTarrow          wasy          16  0 textmode &#x25C0; wasysym # works in text mode only (produces \imath in math mode)
+UParrow            wasy          75  0 textmode &#x25B2; wasysym # works in text mode only (produces K in math mode)
+DOWNarrow          wasy          76  0 textmode &#x25BC; wasysym # works in text mode only (produces L in math mode)
+AC                 wasy          58  0 textmode x        wasysym # works in text mode only
+# \def\HF{\leavevmode \lower0.9pt\hbox to 0pt{\kern0.5pt\wasyfamily\char58\hss}\raise0.9pt\hbox{\kern0.5pt\wasyfamily\char58\kern0.5pt}} wasysym
+VHF                wasy          64  0 x        x
 Square             wasy          50  0 x        &square;
 #CheckedBox         wasy          50\hss}\hbox{\wasyfamily\char8  0 x
 XBox               wasy          52  0 x        &timesb;
@@ -763,8 +762,8 @@ sagittarius        wasy          99  0 x        &#x2650;
 capricornus        wasy          100 0 x        &#x2651;
 aquarius           wasy          101 0 x        &#x2652;
 pisces             wasy          102 0 x        &#x2653;
-conjunction        wasy          86  0 x        &#x260C;
-opposition         wasy          87  0 x        &#x260D;
+conjunction        wasy          86  0 textmode &#x260C; wasysym # works in text mode only (produces V in math mode)
+opposition         wasy          87  0 textmode &#x260D; wasysym # works in text mode only (produces W in math mode)
 # APL characters
 APLstar            wasy          69  0 x        &#x235F;
 APLlog             wasy          22  0 x        x
@@ -790,11 +789,11 @@ rightturn          wasy          33  0 x        &#x27F3;
 # special characters
 cent               wasy         103   0 x        &#00A2;
 permil             wasy         104   0 x        &#x2030;
-agemO              wasy          48   0 x        &mho;
-thorn              wasy         105   0 x        &#x00FE;
-Thorn              wasy         106   0 x        &#x00DE;
-openo              wasy         108   0 x        &#x0254;
-inve               wasy          85   0 x        &#x0259;
+agemO              wasy          48   0 textmode &mho;    wasysym # works in text mode only (produces 0 in math mode)
+thorn              wasy         105   0 textmode &#x00FE; wasysym # works in text mode only (produces i in math mode)
+Thorn              wasy         106   0 textmode &#x00DE; wasysym # works in text mode only (produces j in math mode)
+openo              wasy         108   0 textmode &#x0254; wasysym # works in text mode only (produces l in math mode)
+inve               wasy          85   0 textmode &#x0259; wasysym # works in text mode only (produces U in math mode)
 
 #mho               wasy          48    0  mathord &mho; # already in amsfonts
 #Join              wasy          49    0  mathrel x
index ed6c155784b6471fcc5fe69665fd50bda11dd467..1999846729868998005b1f628e392481e63257d1 100644 (file)
@@ -23,6 +23,8 @@
 #include "support/docstream.h"
 #include "support/textutils.h"
 
+#include <boost/scoped_ptr.hpp>
+
 
 namespace lyx {
 
@@ -111,6 +113,12 @@ void InsetMathSymbol::draw(PainterInfo & pi, int x, int y) const
 }
 
 
+InsetMath::mode_type InsetMathSymbol::currentMode() const
+{
+       return sym_->extra == "textmode" ? TEXT_MODE : MATH_MODE;
+}
+
+
 bool InsetMathSymbol::isRelOp() const
 {
        return sym_->extra == "mathrel";
@@ -235,7 +243,9 @@ void InsetMathSymbol::octave(OctaveStream & os) const
 
 void InsetMathSymbol::write(WriteStream & os) const
 {
-       MathEnsurer ensurer(os);
+       boost::scoped_ptr<MathEnsurer> ensurer;
+       if (currentMode() != TEXT_MODE)
+               ensurer.reset(new MathEnsurer(os));
        os << '\\' << name();
 
        // $,#, etc. In theory the restriction based on catcodes, but then
index 4730513dec0bd7ce5b52be3ab13066a7468d9e06..bb18217a8416dbd9b112e84bbd4ea539760dfdef 100644 (file)
@@ -37,6 +37,8 @@ public:
        ///
        int kerning(BufferView const *) const { return kerning_; }
 
+       ///
+       mode_type currentMode() const;
        ///
        bool isRelOp() const;
        ///