From 2e5ba6f3f2339c549e13afff77ff059483790fd3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Uwe=20St=C3=B6hr?= Date: Mon, 18 Feb 2013 04:50:18 +0100 Subject: [PATCH] tex2lyx: support for TIPA \tone - also simplify the code a bit - test-insets.tex: add missing preamble code --- src/tex2lyx/Preamble.cpp | 4 +- src/tex2lyx/TODO.txt | 3 +- src/tex2lyx/test/test-insets.lyx.lyx | 325 +-------------------------- src/tex2lyx/test/test-insets.tex | 3 + src/tex2lyx/text.cpp | 59 +++-- 5 files changed, 56 insertions(+), 338 deletions(-) diff --git a/src/tex2lyx/Preamble.cpp b/src/tex2lyx/Preamble.cpp index 4b4bb73217..56be6a1808 100644 --- a/src/tex2lyx/Preamble.cpp +++ b/src/tex2lyx/Preamble.cpp @@ -182,8 +182,8 @@ const char * const known_lyx_packages[] = {"amsbsy", "amsmath", "amssymb", "amstext", "amsthm", "array", "babel", "booktabs", "calc", "CJK", "color", "float", "fontspec", "graphicx", "hhline", "ifthen", "longtable", "makeidx", "multirow", "nomencl", "pdfpages", "refstyle", "rotating", "rotfloat", "splitidx", -"setspace", "subscript", "textcomp", "tipa", "tipx", "ulem", "url", "varioref", -"verbatim", "wrapfig", "xunicode", 0}; +"setspace", "subscript", "textcomp", "tipa", "tipx", "tone", "ulem", "url", +"varioref", "verbatim", "wrapfig", "xunicode", 0}; // used for the handling of \newindex int index_number = 0; diff --git a/src/tex2lyx/TODO.txt b/src/tex2lyx/TODO.txt index 42a37085c1..8754a29aa1 100644 --- a/src/tex2lyx/TODO.txt +++ b/src/tex2lyx/TODO.txt @@ -51,8 +51,7 @@ Format LaTeX feature LyX feature 407 vertical offset for multirows InsetTabular 411 support for polyglossia \language_package (the cases of no package, of babel and of custom package is supported) 415 automatic undertilde loading \use_package undertilde -438 \tone{51} etc., InsetTIPA - \=*{a}, \*r and \*w, \!o +438 \=*{a}, \*r and \*w, \!o InsetTIPA and \!b and \!d and \!g and \!G, \textvertline, \t*{ }, \textdoublevertline, \textglobfall diff --git a/src/tex2lyx/test/test-insets.lyx.lyx b/src/tex2lyx/test/test-insets.lyx.lyx index 1013460bd7..b4e67c0fd8 100644 --- a/src/tex2lyx/test/test-insets.lyx.lyx +++ b/src/tex2lyx/test/test-insets.lyx.lyx @@ -6176,326 +6176,11 @@ status collapsed \begin_inset IPA \begin_layout Standard - -\begin_inset ERT -status collapsed - -\begin_layout Plain Layout - -\backslash -tone -\end_layout - -\end_inset - - -\begin_inset ERT -status collapsed - -\begin_layout Plain Layout -{ -\end_layout - -\end_inset - -55 -\begin_inset ERT -status collapsed - -\begin_layout Plain Layout -} -\end_layout - -\end_inset - - -\begin_inset ERT -status collapsed - -\begin_layout Plain Layout - -\backslash -tone -\end_layout - -\end_inset - - -\begin_inset ERT -status collapsed - -\begin_layout Plain Layout -{ -\end_layout - -\end_inset - -44 -\begin_inset ERT -status collapsed - -\begin_layout Plain Layout -} -\end_layout - -\end_inset - - -\begin_inset ERT -status collapsed - -\begin_layout Plain Layout - -\backslash -tone -\end_layout - -\end_inset - - -\begin_inset ERT -status collapsed - -\begin_layout Plain Layout -{ -\end_layout - -\end_inset - -33 -\begin_inset ERT -status collapsed - -\begin_layout Plain Layout -} -\end_layout - -\end_inset - - -\begin_inset ERT -status collapsed - -\begin_layout Plain Layout - -\backslash -tone -\end_layout - -\end_inset - - -\begin_inset ERT -status collapsed - -\begin_layout Plain Layout -{ -\end_layout - -\end_inset - -22 -\begin_inset ERT -status collapsed - -\begin_layout Plain Layout -} -\end_layout - -\end_inset - - -\begin_inset ERT -status collapsed - -\begin_layout Plain Layout - -\backslash -tone -\end_layout - -\end_inset - - -\begin_inset ERT -status collapsed - -\begin_layout Plain Layout -{ -\end_layout - -\end_inset - -11 -\begin_inset ERT -status collapsed - -\begin_layout Plain Layout -} -\end_layout - -\end_inset - -ꜜꜛ -\begin_inset ERT -status collapsed - -\begin_layout Plain Layout - -\backslash -tone -\end_layout - -\end_inset - - -\begin_inset ERT -status collapsed - -\begin_layout Plain Layout -{ -\end_layout - -\end_inset - -15 -\begin_inset ERT -status collapsed - -\begin_layout Plain Layout -} -\end_layout - -\end_inset - - -\begin_inset ERT -status collapsed - -\begin_layout Plain Layout - -\backslash -tone -\end_layout - -\end_inset - - -\begin_inset ERT -status collapsed - -\begin_layout Plain Layout -{ -\end_layout - -\end_inset - -51 -\begin_inset ERT -status collapsed - -\begin_layout Plain Layout -} -\end_layout - -\end_inset - - -\begin_inset ERT -status collapsed - -\begin_layout Plain Layout - -\backslash -tone -\end_layout - -\end_inset - - -\begin_inset ERT -status collapsed - -\begin_layout Plain Layout -{ -\end_layout - -\end_inset - -45 -\begin_inset ERT -status collapsed - -\begin_layout Plain Layout -} -\end_layout - -\end_inset - - -\begin_inset ERT -status collapsed - -\begin_layout Plain Layout - -\backslash -tone -\end_layout - -\end_inset - - -\begin_inset ERT -status collapsed - -\begin_layout Plain Layout -{ -\end_layout - -\end_inset - -12 -\begin_inset ERT -status collapsed - -\begin_layout Plain Layout -} -\end_layout - -\end_inset - - -\begin_inset ERT -status collapsed - -\begin_layout Plain Layout - -\backslash -tone -\end_layout - -\end_inset - - -\begin_inset ERT -status collapsed - -\begin_layout Plain Layout -{ -\end_layout - -\end_inset - -454 -\begin_inset ERT -status collapsed - -\begin_layout Plain Layout -} -\end_layout - -\end_inset - +˥˦˧˨˩ꜜꜛ\IPAChar \tone{15} +\IPAChar \tone{51} +\IPAChar \tone{45} +\IPAChar \tone{12} +\IPAChar \tone{454} ↗ \begin_inset ERT status collapsed diff --git a/src/tex2lyx/test/test-insets.tex b/src/tex2lyx/test/test-insets.tex index d84657273c..09e6dc4ae4 100644 --- a/src/tex2lyx/test/test-insets.tex +++ b/src/tex2lyx/test/test-insets.tex @@ -40,6 +40,9 @@ \usepackage{amssymb} \usepackage{color} \usepackage[ps,mover]{lyxskak} +\usepackage{tipa} +\usepackage{tipx} +\usepackage{tone} %%%%%%%%%%%%%%%%%%%%%%%%%%%%%% LyX specific LaTeX commands. \providecommand{\LyX}{L\kern-.1667em\lower.25em\hbox{Y}\kern-.125emX\@} diff --git a/src/tex2lyx/text.cpp b/src/tex2lyx/text.cpp index 474fcb18e6..df06be1b2f 100644 --- a/src/tex2lyx/text.cpp +++ b/src/tex2lyx/text.cpp @@ -285,6 +285,17 @@ char const * const known_phrases[] = {"LyX", "TeX", "LaTeXe", "LaTeX", 0}; char const * const known_coded_phrases[] = {"LyX", "TeX", "LaTeX2e", "LaTeX", 0}; int const known_phrase_lengths[] = {3, 5, 7, 0}; +/// known TIPA combining diacritical marks +char const * const known_tipa_marks[] = {"textsubwedge", "textsubumlaut", +"textsubtilde", "textseagull", "textsubbridge", "textinvsubbridge", +"textsubsquare", "textsubrhalfring", "textsublhalfring", "textsubplus", +"textovercross", "textsubarch", "textsuperimposetilde", "textraising", +"textlowering", "textadvancing", "textretracting", "textdoublegrave", +"texthighrise", "textlowrise", "textrisefall", "textsyllabic", 0}; + +/// tones that need special handling +char const * const known_tones[] = {"15", "51", "45", "12", "454", 0}; + // string to store the float type to be able to determine the type of subfloats string float_type = ""; @@ -3238,25 +3249,13 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer, } // the TIPA Combining diacritical marks - else if (t.cs() == "textsubwedge" || t.cs() == "textsubumlaut" - || t.cs() == "textsubtilde" || t.cs() == "textseagull" - || t.cs() == "textsubbridge" || t.cs() == "textinvsubbridge" - || t.cs() == "textsubsquare" || t.cs() == "textsubrhalfring" - || t.cs() == "textsublhalfring" || t.cs() == "textsubplus" - || t.cs() == "textovercross" || t.cs() == "textsubarch" - || t.cs() == "textsuperimposetilde" || t.cs() == "textraising" - || t.cs() == "textlowering" || t.cs() == "textadvancing" - || t.cs() == "textretracting" || t.cs() == "textdoublegrave" - || t.cs() == "texthighrise" || t.cs() == "textlowrise" - || t.cs() == "textrisefall" || t.cs() == "textsyllabic") { + else if (is_known(t.cs(), known_tipa_marks)) { context.check_layout(os); // try to see whether the string is in unicodesymbols bool termination; docstring rem; string content = trimSpaceAndEol(p.verbatim_item()); - string command = t.asInput() + "{" - + trimSpaceAndEol(content) - + "}"; + string command = t.asInput() + "{" + content + "}"; set req; docstring s = encodings.fromLaTeXCommand(from_utf8(command), Encodings::TEXT_CMD | Encodings::MATH_CMD, @@ -3267,6 +3266,38 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer, << ", result is " << to_utf8(s) << "+" << to_utf8(rem) << endl; os << content << to_utf8(s); + // tipa is already registered because of the surrounding IPA environment + // or \textipa but it does not harm to register it again if necessary + for (set::const_iterator it = req.begin(); it != req.end(); ++it) + preamble.registerAutomaticallyLoadedPackage(*it); + } else + // we did not find a non-ert version + output_ert_inset(os, command, context); + } + + else if (t.cs() == "tone" ) { + context.check_layout(os); + // try to see whether the string is in unicodesymbols + string content = trimSpaceAndEol(p.verbatim_item()); + string command = t.asInput() + "{" + content + "}"; + // some tones can be detected by unicodesymbols, some need special code + if (is_known(content, known_tones)) { + os << "\\IPAChar " << command << "\n"; + continue; + } + bool termination; + docstring rem; + set req; + docstring s = encodings.fromLaTeXCommand(from_utf8(command), + Encodings::TEXT_CMD | Encodings::MATH_CMD, + termination, rem, &req); + if (!s.empty()) { + if (!rem.empty()) + cerr << "When parsing " << command + << ", result is " << to_utf8(s) + << "+" << to_utf8(rem) << endl; + os << to_utf8(s); + // thiw will register the package "tone" for (set::const_iterator it = req.begin(); it != req.end(); ++it) preamble.registerAutomaticallyLoadedPackage(*it); } else