From: Georg Baum Date: Wed, 9 Jan 2013 21:23:07 +0000 (+0100) Subject: Handle text-only wasy symbols correctly. X-Git-Tag: 2.1.0beta1~948 X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=45052f56ab092ae826c9d8dfec3c66ce82fccad7;p=features.git Handle text-only wasy symbols correctly. 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. --- diff --git a/development/tools/generate_symbols_images.py b/development/tools/generate_symbols_images.py index a043c9c94e..e04962e4e0 100644 --- a/development/tools/generate_symbols_images.py +++ b/development/tools/generate_symbols_images.py @@ -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])) diff --git a/lib/symbols b/lib/symbols index a0e30a9b32..ad5424a40e 100644 --- a/lib/symbols +++ b/lib/symbols @@ -658,21 +658,20 @@ lyxleft msa 76 0 mathord ← male wasy 26 0 x ♂ female wasy 25 0 x ♀ -currency wasy 27 0 x ¤ -phone wasy 7 0 x ☎ -recorder wasy 6 0 x ⌕ -clock wasy 28 0 x &clock; +currency wasy 27 0 textmode ¤ wasysym # works in text mode only (produces \oe in math mode) +phone wasy 7 0 textmode ☎ wasysym # works in text mode only (produces \Upsilon in math mode) +recorder wasy 6 0 textmode ⌕ 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 ☇ -pointer wasy 9 0 x x -RIGHTarrow wasy 17 0 x ▶ -LEFTarrow wasy 16 0 x ◀ -UParrow wasy 75 0 x ▲ -DOWNarrow wasy 76 0 x ▼ -#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 ▶ wasysym # works in text mode only (produces \jmath in math mode) +LEFTarrow wasy 16 0 textmode ◀ wasysym # works in text mode only (produces \imath in math mode) +UParrow wasy 75 0 textmode ▲ wasysym # works in text mode only (produces K in math mode) +DOWNarrow wasy 76 0 textmode ▼ 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 □ #CheckedBox wasy 50\hss}\hbox{\wasyfamily\char8 0 x XBox wasy 52 0 x ⊠ @@ -763,8 +762,8 @@ sagittarius wasy 99 0 x ♐ capricornus wasy 100 0 x ♑ aquarius wasy 101 0 x ♒ pisces wasy 102 0 x ♓ -conjunction wasy 86 0 x ☌ -opposition wasy 87 0 x ☍ +conjunction wasy 86 0 textmode ☌ wasysym # works in text mode only (produces V in math mode) +opposition wasy 87 0 textmode ☍ wasysym # works in text mode only (produces W in math mode) # APL characters APLstar wasy 69 0 x ⍟ APLlog wasy 22 0 x x @@ -790,11 +789,11 @@ rightturn wasy 33 0 x ⟳ # special characters cent wasy 103 0 x �A2; permil wasy 104 0 x ‰ -agemO wasy 48 0 x ℧ -thorn wasy 105 0 x þ -Thorn wasy 106 0 x Þ -openo wasy 108 0 x ɔ -inve wasy 85 0 x ə +agemO wasy 48 0 textmode ℧ wasysym # works in text mode only (produces 0 in math mode) +thorn wasy 105 0 textmode þ wasysym # works in text mode only (produces i in math mode) +Thorn wasy 106 0 textmode Þ wasysym # works in text mode only (produces j in math mode) +openo wasy 108 0 textmode ɔ wasysym # works in text mode only (produces l in math mode) +inve wasy 85 0 textmode ə wasysym # works in text mode only (produces U in math mode) #mho wasy 48 0 mathord ℧ # already in amsfonts #Join wasy 49 0 mathrel x diff --git a/src/mathed/InsetMathSymbol.cpp b/src/mathed/InsetMathSymbol.cpp index ed6c155784..1999846729 100644 --- a/src/mathed/InsetMathSymbol.cpp +++ b/src/mathed/InsetMathSymbol.cpp @@ -23,6 +23,8 @@ #include "support/docstream.h" #include "support/textutils.h" +#include + 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 ensurer; + if (currentMode() != TEXT_MODE) + ensurer.reset(new MathEnsurer(os)); os << '\\' << name(); // $,#, etc. In theory the restriction based on catcodes, but then diff --git a/src/mathed/InsetMathSymbol.h b/src/mathed/InsetMathSymbol.h index 4730513dec..bb18217a84 100644 --- a/src/mathed/InsetMathSymbol.h +++ b/src/mathed/InsetMathSymbol.h @@ -37,6 +37,8 @@ public: /// int kerning(BufferView const *) const { return kerning_; } + /// + mode_type currentMode() const; /// bool isRelOp() const; ///