On Tue, Oct 09, 2007 at 05:03:54PM +0200, Jürgen Spitzmüller wrote: > Enrico Forestieri wrote: > > Consider also that babel could be switched off by preference, so this > > would leave us in the cold. So, I propose that when any greek unicode > > character is detected the following lines are added to the preamble: > > > > \DeclareRobustCommand{\greektext}{% > > \fontencoding{LGR}\selectfont > > \def\encodingdefault{LGR}} > > \DeclareRobustCommand{\textgreek}[1]{\leavevmode{\greektext #1}} > > \DeclareFontEncoding{LGR}{}{} > > > > and \textgreek is used to translate the unicode character. > > Of course, it would be good if the implemenattion would work with ranges, > such > that we get \textgreek{abcdef}, not > \textgreek{a}\textgreek{b}\textgreek{c}\textgreek{d}\textgreek{e}\textgreek{f} > > in the output.
The first patch implements the ideas above (without ranges) and works perfectly. You can even mark as greek the chars and get the same behaviour as before. The second patch (to be applied after the first one) implements ranges and works but with caveats. You can only apply font attribute changes (color, shape, etc.) to a whole bunch of consecutive greek chars but not to single ones. Moreover, the attributes set for the first char in a sequence of chars are inherited by all others. I fear that my knowledge of the code dealing with font attributes is currently too limited to let me devise clever solutions in a resonable time. I also attach here the .lyx file I used for testing. > > Note that this is exactly what babel would do and it doesn't > > interfere with babel itself and the use of the greek option, > > as the files I sent before demonstrate. > > Go for it (and then cyrillic) :-). Yeah, but don't hold your breath in the meantime ;-) -- Enrico
Index: src/LaTeXFeatures.cpp =================================================================== --- src/LaTeXFeatures.cpp (revision 20880) +++ src/LaTeXFeatures.cpp (working copy) @@ -186,6 +186,13 @@ static string const changetracking_none_ "\\newcommand{\\lyxadded}[3]{#3}\n" "\\newcommand{\\lyxdeleted}[3]{}\n"; +static string const textgreek_def = + "\\DeclareRobustCommand{\\greektext}{%\n" + " \\fontencoding{LGR}\\selectfont\n" + " \\def\\encodingdefault{LGR}}\n" + "\\DeclareRobustCommand{\\textgreek}[1]{\\leavevmode{\\greektext #1}}\n" + "\\DeclareFontEncoding{LGR}{}{}\n"; + ///////////////////////////////////////////////////////////////////// // @@ -618,6 +625,9 @@ string const LaTeXFeatures::getMacros() if (mustProvide("lyxarrow")) macros << lyxarrow_def << '\n'; + if (mustProvide("textgreek")) + macros << textgreek_def << '\n'; + // quotes. if (mustProvide("quotesinglbase")) macros << quotesinglbase_def << '\n'; Index: lib/unicodesymbols =================================================================== --- lib/unicodesymbols (revision 20880) +++ lib/unicodesymbols (working copy) @@ -684,6 +684,55 @@ #0x036d "" "" "combining" # COMBINING LATIN SMALL LETTER T #0x036e "" "" "combining" # COMBINING LATIN SMALL LETTER V #0x036f "" "" "combining" # COMBINING LATIN SMALL LETTER X +0x0391 "\\textgreek{A}" "textgreek" "" # GREEK CAPITAL LETTER ALPHA +0x0392 "\\textgreek{B}" "textgreek" "" # GREEK CAPITAL LETTER BETA +0x0393 "\\textgreek{G}" "textgreek" "" # GREEK CAPITAL LETTER GAMMA +0x0394 "\\textgreek{D}" "textgreek" "" # GREEK CAPITAL LETTER DELTA +0x0395 "\\textgreek{E}" "textgreek" "" # GREEK CAPITAL LETTER EPSILON +0x0396 "\\textgreek{Z}" "textgreek" "" # GREEK CAPITAL LETTER ZETA +0x0397 "\\textgreek{H}" "textgreek" "" # GREEK CAPITAL LETTER ETA +0x0398 "\\textgreek{J}" "textgreek" "" # GREEK CAPITAL LETTER THETA +0x0399 "\\textgreek{I}" "textgreek" "" # GREEK CAPITAL LETTER IOTA +0x039a "\\textgreek{K}" "textgreek" "" # GREEK CAPITAL LETTER KAPPA +0x039b "\\textgreek{L}" "textgreek" "" # GREEK CAPITAL LETTER LAMDA +0x039c "\\textgreek{M}" "textgreek" "" # GREEK CAPITAL LETTER MU +0x039d "\\textgreek{N}" "textgreek" "" # GREEK CAPITAL LETTER NU +0x039e "\\textgreek{X}" "textgreek" "" # GREEK CAPITAL LETTER XI +0x039f "\\textgreek{O}" "textgreek" "" # GREEK CAPITAL LETTER OMICRON +0x03a0 "\\textgreek{P}" "textgreek" "" # GREEK CAPITAL LETTER PI +0x03a1 "\\textgreek{R}" "textgreek" "" # GREEK CAPITAL LETTER RHO +0x03a3 "\\textgreek{S}" "textgreek" "" # GREEK CAPITAL LETTER SIGMA +0x03a4 "\\textgreek{T}" "textgreek" "" # GREEK CAPITAL LETTER TAU +0x03a5 "\\textgreek{U}" "textgreek" "" # GREEK CAPITAL LETTER UPSILON +0x03a6 "\\textgreek{F}" "textgreek" "" # GREEK CAPITAL LETTER PHI +0x03a7 "\\textgreek{Q}" "textgreek" "" # GREEK CAPITAL LETTER CHI +0x03a8 "\\textgreek{Y}" "textgreek" "" # GREEK CAPITAL LETTER PSI +0x03a9 "\\textgreek{W}" "textgreek" "" # GREEK CAPITAL LETTER OMEGA +0x03b1 "\\textgreek{a}" "textgreek" "" # GREEK SMALL LETTER ALPHA +0x03b2 "\\textgreek{b}" "textgreek" "" # GREEK SMALL LETTER BETA +0x03b3 "\\textgreek{g}" "textgreek" "" # GREEK SMALL LETTER GAMMA +0x03b4 "\\textgreek{d}" "textgreek" "" # GREEK SMALL LETTER DELTA +0x03b5 "\\textgreek{e}" "textgreek" "" # GREEK SMALL LETTER EPSILON +0x03b6 "\\textgreek{z}" "textgreek" "" # GREEK SMALL LETTER ZETA +0x03b7 "\\textgreek{h}" "textgreek" "" # GREEK SMALL LETTER ETA +0x03b8 "\\textgreek{j}" "textgreek" "" # GREEK SMALL LETTER THETA +0x03b9 "\\textgreek{i}" "textgreek" "" # GREEK SMALL LETTER IOTA +0x03ba "\\textgreek{k}" "textgreek" "" # GREEK SMALL LETTER KAPPA +0x03bb "\\textgreek{l}" "textgreek" "" # GREEK SMALL LETTER LAMDA +0x03bc "\\textgreek{m}" "textgreek" "" # GREEK SMALL LETTER MU +0x03bd "\\textgreek{n}" "textgreek" "" # GREEK SMALL LETTER NU +0x03be "\\textgreek{x}" "textgreek" "" # GREEK SMALL LETTER XI +0x03bf "\\textgreek{o}" "textgreek" "" # GREEK SMALL LETTER OMICRON +0x03c0 "\\textgreek{p}" "textgreek" "" # GREEK SMALL LETTER PI +0x03c1 "\\textgreek{r}" "textgreek" "" # GREEK SMALL LETTER RHO +0x03c2 "\\textgreek{c}" "textgreek" "" # GREEK SMALL LETTER FINAL SIGMA +0x03c3 "\\textgreek{s}" "textgreek" "" # GREEK SMALL LETTER SIGMA +0x03c4 "\\textgreek{t}" "textgreek" "" # GREEK SMALL LETTER TAU +0x03c5 "\\textgreek{u}" "textgreek" "" # GREEK SMALL LETTER UPSILON +0x03c6 "\\textgreek{f}" "textgreek" "" # GREEK SMALL LETTER PHI +0x03c7 "\\textgreek{q}" "textgreek" "" # GREEK SMALL LETTER CHI +0x03c8 "\\textgreek{y}" "textgreek" "" # GREEK SMALL LETTER PSI +0x03c9 "\\textgreek{w}" "textgreek" "" # GREEK SMALL LETTER OMEGA 0x0e3f "\\textbaht" "textcomp" "" # THAI CURRENCY SYMBOL BAHT 0x1e00 "\\textsubring{A}" "tipa" "" # LATIN CAPITAL LETTER A WITH RING BELOW 0x1e01 "\\textsubring{a}" "tipa" "" # LATIN SMALL LETTER A WITH RING BELOW
Index: src/Paragraph.cpp =================================================================== --- src/Paragraph.cpp (revision 20880) +++ src/Paragraph.cpp (working copy) @@ -66,8 +66,10 @@ using std::ostream; namespace lyx { using support::contains; +using support::prefixIs; using support::suffixIs; using support::rsplit; +using support::rtrim; ///////////////////////////////////////////////////////////////////// @@ -187,6 +189,10 @@ public: unsigned int & column, Font const & font, Layout const & style); + /// Output consecutive greek chars starting from \p c to \p os. + /// \return the number of characters written. + int greekChars(odocstream & os, value_type c, Encoding const &, + pos_type &); /// void simpleTeXSpecialChars(Buffer const &, BufferParams const &, odocstream &, @@ -627,6 +633,34 @@ bool Paragraph::Pimpl::simpleTeXBlanks(E } +int Paragraph::Pimpl::greekChars(odocstream & os, value_type c, + Encoding const & encoding, pos_type & i) +{ + // The latex command is "\textgreek{x}" and we have to retain + // "\textgreek{x" for the first char but only "x" for all + // subsequent chars. + docstring const latex1 = rtrim(encoding.latexChar(c), "}"); + int length = latex1.length(); + os << latex1; + while (i < size() - 1) { + char_type next = getChar(i + 1); + if (Encodings::isGreekChar(next)) { + docstring const latex = encoding.latexChar(next); + size_t j = latex.find_first_of(from_ascii("{")) + 1; + os << latex.substr(j, 1); + ++length; + ++i; + } else + break; + } + if (prefixIs(latex1, from_ascii("\\textgreek"))) { + os << '}'; + ++length; + } + return length; +} + + bool Paragraph::Pimpl::isTextAt(string const & str, pos_type pos) const { pos_type const len = str.length(); @@ -952,6 +986,10 @@ void Paragraph::Pimpl::simpleTeXSpecialC break; } } + if (Encodings::isGreekChar(c)) { + column += greekChars(os, c, encoding, i) - 1; + break; + } docstring const latex = encoding.latexChar(c); if (latex.length() > 1 && latex[latex.length() - 1] != '}') { Index: src/Encoding.cpp =================================================================== --- src/Encoding.cpp (revision 20880) +++ src/Encoding.cpp (working copy) @@ -401,6 +401,15 @@ bool Encodings::isCombiningChar(char_typ } +bool Encodings::isGreekChar(char_type c) +{ + CharInfoMap::const_iterator const it = unicodesymbols.find(c); + if (it != unicodesymbols.end()) + return it->second.preamble == "textgreek"; + return false; +} + + Encoding const * Encodings::getFromLyXName(string const & name) const { EncodingList::const_iterator it = encodinglist.find(name); Index: src/Encoding.h =================================================================== --- src/Encoding.h (revision 20880) +++ src/Encoding.h (working copy) @@ -142,6 +142,8 @@ public: static char_type transformChar(char_type c, Letter_Form form); /// Is this a combining char? static bool isCombiningChar(char_type c); + /// Is this a greek char? + static bool isGreekChar(char_type c); /** * Add the preamble snippet needed for the output of \p c to * \p features.
#LyX 1.6.0svn created this file. For more info see http://www.lyx.org/ \lyxformat 292 \begin_document \begin_header \textclass article \language english \inputencoding auto \font_roman default \font_sans default \font_typewriter default \font_default_family default \font_sc false \font_osf false \font_sf_scale 100 \font_tt_scale 100 \graphics default \paperfontsize default \use_hyperref false \pdf_store_options false \papersize default \use_geometry false \use_amsmath 1 \use_esint 1 \cite_engine basic \use_bibtopic false \paperorientation portrait \secnumdepth 3 \tocdepth 3 \paragraph_separation indent \defskip medskip \quotes_language english \papercolumns 1 \papersides 1 \paperpagestyle default \tracking_changes false \output_changes false \author "" \author "" \end_header \begin_manifest \end_manifest \begin_body \begin_layout Standard Greek letters alpha α and lambda λ. And now a bunch of them: ÏÏÎΦΣβμ. \end_layout \begin_layout Standard Notice that the greek capital alpha Î is not the same as the latin letter A. \end_layout \begin_layout Standard They are different: ÎA \SpecialChar \ldots{} well, at least for LyX \begin_inset Formula $\smiley$ \end_inset \end_layout \end_body \end_document