]> git.lyx.org Git - lyx.git/blob - src/tex-accent.C
08c9444391deb64f2a9bc7ef22c5dc38c02509dc
[lyx.git] / src / tex-accent.C
1 /**
2  * \file tex-accent.C
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author Lars Gullik Bjønnes
7  * \author Matthias Ettrich
8  *
9  * Full author contact details are available in file CREDITS.
10  */
11
12 #include <config.h>
13
14 #include "tex-accent.h"
15 #include "support/convert.h"
16
17
18 namespace lyx {
19
20 /* the names used by TeX and XWindows for deadkeys/accents are not the same
21    so here follows a table to clearify the differences. Please correct this
22    if I got it wrong
23
24    |------------------|------------------|------------------|--------------|
25    |      TeX         |     XWindows     |   \bind/LFUN     | used by intl |
26    |------------------|------------------|------------------|--------------|
27    |    grave         |    grave         |LFUN_ACCENT_GRAVE        | grave
28    |    acute         |    acute         |LFUN_ACCENT_ACUTE        | acute
29    |    circumflex    |    circumflex    |LFUN_ACCENT_CIRCUMFLEX   | circumflex
30    | umlaut/dieresis  |    diaeresis     |LFUN_ACCENT_UMLAUT       | umlaut
31    |    tilde         |    tilde         |LFUN_ACCENT_TILDE        | tilde
32    |    macron        |    maron         |LFUN_ACCENT_MACRON       | macron
33    |    dot           |    abovedot      |LFUN_ACCENT_DOT          | dot
34    |    cedilla       |    cedilla       |LFUN_ACCENT_CEDILLA      | cedilla
35    |    underdot      |                  |LFUN_ACCENT_UNDERDOT     | underdot
36    |    underbar      |                  |LFUN_ACCENT_UNDERBAR     | underbar
37    |    hácek         |    caron         |LFUN_ACCENT_CARON        | caron
38    |    breve         |    breve         |LFUN_ACCENT_BREVE        | breve
39    |    tie           |                  |LFUN_ACCENT_TIE          | tie
40    | Hungarian umlaut |    doubleacute   |LFUN_ACCENT_HUNGARIAN_UMLAUT  | hungarian umlaut
41    |    circle        |    abovering     |LFUN_ACCENT_CIRCLE       | circle
42    |                  |    ogonek        |                  |
43    |                  |    iota          |                  |
44    |                  |    voiced_sound  |                  |
45    |                  | semivoiced_sound |                  |
46    |                  |                  |LFUN_ACCENT_SPECIAL_CARON| special caron
47    */
48 // I am not sure how some of the XWindows names coresponds to the TeX ones.
49
50 tex_accent_struct lyx_accent_table[18] = {
51         { static_cast<tex_accent>(0), "", /*"",*/ "", static_cast<kb_action>(0)},
52         {TEX_ACUTE,      "\\'",  /*" AEIOUYaeiouySZszRLCNrlcn",*/ "acute",   LFUN_ACCENT_ACUTE},
53         {TEX_GRAVE,      "\\`",  /*" aeiouAEIOU",*/           "grave",    LFUN_ACCENT_GRAVE},
54         {TEX_MACRON,     "\\=",  /*" EeAIOUaiou",*/           "macron",    LFUN_ACCENT_MACRON},
55         {TEX_TILDE,      "\\~",  /*" ANOanoIiUu",*/           "tilde",    LFUN_ACCENT_TILDE},
56         {TEX_UNDERBAR,   "\\b", /*" ",*/                     "underbar", LFUN_ACCENT_UNDERBAR},
57         {TEX_CEDILLA,    "\\c", /*" CcSsTtRLGrlgNKnk",*/     "cedilla",    LFUN_ACCENT_CEDILLA},
58         {TEX_UNDERDOT,   "\\d", /*" ",*/                     "underdot", LFUN_ACCENT_UNDERDOT},
59         {TEX_CIRCUMFLEX, "\\^",  /*" AEIOUaeiouHJhjCGScgs",*/ "circumflex",  LFUN_ACCENT_CIRCUMFLEX},
60         {TEX_CIRCLE,     "\\r", /*" AaUu",*/                 "circle",  LFUN_ACCENT_CIRCLE},
61         {TEX_TIE,        "\\t", /*" ",*/                     "tie",    LFUN_ACCENT_TIE},
62         {TEX_BREVE,      "\\u", /*" AaGgUu",*/               "breve",    LFUN_ACCENT_BREVE},
63         {TEX_CARON,      "\\v", /*" LSTZlstzCEDNRcednr",*/   "caron",    LFUN_ACCENT_CARON},
64 //  {TEX_SPECIAL_CARON, "\\q", "", "ooo",  LFUN_ACCENT_SPECIAL_CARON},
65         {TEX_HUNGUML,    "\\H", /*" OUou",*/                 "hugarian_umlaut",    LFUN_ACCENT_HUNGARIAN_UMLAUT},
66         {TEX_UMLAUT,     "\\\"", /*" AEIOUaeiouy",*/          "umlaut",    LFUN_ACCENT_UMLAUT},
67         {TEX_DOT,        "\\.",  /*" ZzICGicgEe",*/           "dot",    LFUN_ACCENT_DOT},
68         {TEX_OGONEK,     "\\k",  /*" AaEe",*/                 "ogonek",    LFUN_ACCENT_OGONEK},
69         { static_cast<tex_accent>(0), "", /*"",*/ "", static_cast<kb_action>(0)}};
70
71
72 tex_accent_struct get_accent(kb_action action)
73 {
74         int i = 0;
75         while (i <= TEX_MAX_ACCENT) {
76                 if (lyx_accent_table[i].action == action)
77                         return lyx_accent_table[i];
78                 ++i;
79         }
80         struct tex_accent_struct temp = { static_cast<tex_accent>(0), 0,
81                                           0, static_cast<kb_action>(0)};
82         return temp;
83 }
84
85
86 docstring const DoAccent(docstring const & s, tex_accent accent)
87 {
88         docstring res;
89
90         res += lyx_accent_table[accent].cmd;
91         res += '{';
92         if (s == "i" || s == "j") {
93                 res += '\\';
94         }
95         res += s;
96         res += '}';
97         return res;
98 }
99
100
101 docstring const DoAccent(char_type c, tex_accent accent)
102 {
103         return DoAccent(docstring(1, c), accent);
104 }
105
106
107 } // namespace lyx