tex2lyx: support for TIPA \tone

- also simplify the code a bit
- test-insets.tex: add missing preamble code
This commit is contained in:
Uwe Stöhr 2013-02-18 04:50:18 +01:00
parent b25016b613
commit 2e5ba6f3f2
5 changed files with 56 additions and 338 deletions

View File

@ -182,8 +182,8 @@ const char * const known_lyx_packages[] = {"amsbsy", "amsmath", "amssymb",
"amstext", "amsthm", "array", "babel", "booktabs", "calc", "CJK", "color", "amstext", "amsthm", "array", "babel", "booktabs", "calc", "CJK", "color",
"float", "fontspec", "graphicx", "hhline", "ifthen", "longtable", "makeidx", "float", "fontspec", "graphicx", "hhline", "ifthen", "longtable", "makeidx",
"multirow", "nomencl", "pdfpages", "refstyle", "rotating", "rotfloat", "splitidx", "multirow", "nomencl", "pdfpages", "refstyle", "rotating", "rotfloat", "splitidx",
"setspace", "subscript", "textcomp", "tipa", "tipx", "ulem", "url", "varioref", "setspace", "subscript", "textcomp", "tipa", "tipx", "tone", "ulem", "url",
"verbatim", "wrapfig", "xunicode", 0}; "varioref", "verbatim", "wrapfig", "xunicode", 0};
// used for the handling of \newindex // used for the handling of \newindex
int index_number = 0; int index_number = 0;

View File

@ -51,8 +51,7 @@ Format LaTeX feature LyX feature
407 vertical offset for multirows InsetTabular 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) 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 415 automatic undertilde loading \use_package undertilde
438 \tone{51} etc., InsetTIPA 438 \=*{a}, \*r and \*w, \!o InsetTIPA
\=*{a}, \*r and \*w, \!o
and \!b and \!d and \!g and \!G, and \!b and \!d and \!g and \!G,
\textvertline, \t*{ }, \textvertline, \t*{ },
\textdoublevertline, \textglobfall \textdoublevertline, \textglobfall

View File

@ -6176,326 +6176,11 @@ status collapsed
\begin_inset IPA \begin_inset IPA
\begin_layout Standard \begin_layout Standard
˥˦˧˨˩ꜜꜛ\IPAChar \tone{15}
\begin_inset ERT \IPAChar \tone{51}
status collapsed \IPAChar \tone{45}
\IPAChar \tone{12}
\begin_layout Plain Layout \IPAChar \tone{454}
\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
\begin_inset ERT \begin_inset ERT
status collapsed status collapsed

View File

@ -40,6 +40,9 @@
\usepackage{amssymb} \usepackage{amssymb}
\usepackage{color} \usepackage{color}
\usepackage[ps,mover]{lyxskak} \usepackage[ps,mover]{lyxskak}
\usepackage{tipa}
\usepackage{tipx}
\usepackage{tone}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% LyX specific LaTeX commands. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%% LyX specific LaTeX commands.
\providecommand{\LyX}{L\kern-.1667em\lower.25em\hbox{Y}\kern-.125emX\@} \providecommand{\LyX}{L\kern-.1667em\lower.25em\hbox{Y}\kern-.125emX\@}

View File

@ -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}; char const * const known_coded_phrases[] = {"LyX", "TeX", "LaTeX2e", "LaTeX", 0};
int const known_phrase_lengths[] = {3, 5, 7, 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 to store the float type to be able to determine the type of subfloats
string float_type = ""; string float_type = "";
@ -3238,25 +3249,13 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer,
} }
// the TIPA Combining diacritical marks // the TIPA Combining diacritical marks
else if (t.cs() == "textsubwedge" || t.cs() == "textsubumlaut" else if (is_known(t.cs(), known_tipa_marks)) {
|| 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") {
context.check_layout(os); context.check_layout(os);
// try to see whether the string is in unicodesymbols // try to see whether the string is in unicodesymbols
bool termination; bool termination;
docstring rem; docstring rem;
string content = trimSpaceAndEol(p.verbatim_item()); string content = trimSpaceAndEol(p.verbatim_item());
string command = t.asInput() + "{" string command = t.asInput() + "{" + content + "}";
+ trimSpaceAndEol(content)
+ "}";
set<string> req; set<string> req;
docstring s = encodings.fromLaTeXCommand(from_utf8(command), docstring s = encodings.fromLaTeXCommand(from_utf8(command),
Encodings::TEXT_CMD | Encodings::MATH_CMD, 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) << ", result is " << to_utf8(s)
<< "+" << to_utf8(rem) << endl; << "+" << to_utf8(rem) << endl;
os << content << to_utf8(s); 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<string>::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<string> 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<string>::const_iterator it = req.begin(); it != req.end(); ++it) for (set<string>::const_iterator it = req.begin(); it != req.end(); ++it)
preamble.registerAutomaticallyLoadedPackage(*it); preamble.registerAutomaticallyLoadedPackage(*it);
} else } else