]> git.lyx.org Git - lyx.git/blob - src/tex-accent.C
Small clean-up.
[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/tostr.h"
16
17 /* the names used by TeX and XWindows for deadkeys/accents are not the same
18    so here follows a table to clearify the differences. Please correct this
19    if I got it wrong
20
21    |------------------|------------------|------------------|--------------|
22    |      TeX         |     XWindows     |   \bind/LFUN     | used by intl |
23    |------------------|------------------|------------------|--------------|
24    |    grave         |    grave         |LFUN_GRAVE        | grave
25    |    acute         |    acute         |LFUN_ACUTE        | acute
26    |    circumflex    |    circumflex    |LFUN_CIRCUMFLEX   | circumflex
27    | umlaut/dieresis  |    diaeresis     |LFUN_UMLAUT       | umlaut
28    |    tilde         |    tilde         |LFUN_TILDE        | tilde
29    |    macron        |    maron         |LFUN_MACRON       | macron
30    |    dot           |    abovedot      |LFUN_DOT          | dot
31    |    cedilla       |    cedilla       |LFUN_CEDILLA      | cedilla
32    |    underdot      |                  |LFUN_UNDERDOT     | underdot
33    |    underbar      |                  |LFUN_UNDERBAR     | underbar
34    |    hácek         |    caron         |LFUN_CARON        | caron
35    |    breve         |    breve         |LFUN_BREVE        | breve
36    |    tie           |                  |LFUN_TIE          | tie
37    | Hungarian umlaut |    doubleacute   |LFUN_HUNG_UMLAUT  | hungarian umlaut
38    |    circle        |    abovering     |LFUN_CIRCLE       | circle
39    |                  |    ogonek        |                  |
40    |                  |    iota          |                  |
41    |                  |    voiced_sound  |                  |
42    |                  | semivoiced_sound |                  |
43    |                  |                  |LFUN_SPECIAL_CARON| special caron
44    */
45 // I am not sure how some of the XWindows names coresponds to the TeX ones.
46
47 tex_accent_struct lyx_accent_table[18] = {
48         { static_cast<tex_accent>(0), "", /*"",*/ "", static_cast<kb_action>(0)},
49         {TEX_ACUTE,      "\\'",  /*" AEIOUYaeiouySZszRLCNrlcn",*/ "acute",   LFUN_ACUTE},
50         {TEX_GRAVE,      "\\`",  /*" aeiouAEIOU",*/           "grave",    LFUN_GRAVE},
51         {TEX_MACRON,     "\\=",  /*" EeAIOUaiou",*/           "macron",    LFUN_MACRON},
52         {TEX_TILDE,      "\\~",  /*" ANOanoIiUu",*/           "tilde",    LFUN_TILDE},
53         {TEX_UNDERBAR,   "\\b", /*" ",*/                     "underbar", LFUN_UNDERBAR},
54         {TEX_CEDILLA,    "\\c", /*" CcSsTtRLGrlgNKnk",*/     "cedilla",    LFUN_CEDILLA},
55         {TEX_UNDERDOT,   "\\d", /*" ",*/                     "underdot", LFUN_UNDERDOT},
56         {TEX_CIRCUMFLEX, "\\^",  /*" AEIOUaeiouHJhjCGScgs",*/ "circumflex",  LFUN_CIRCUMFLEX},
57         {TEX_CIRCLE,     "\\r", /*" AaUu",*/                 "circle",  LFUN_CIRCLE},
58         {TEX_TIE,        "\\t", /*" ",*/                     "tie",    LFUN_TIE},
59         {TEX_BREVE,      "\\u", /*" AaGgUu",*/               "breve",    LFUN_BREVE},
60         {TEX_CARON,      "\\v", /*" LSTZlstzCEDNRcednr",*/   "caron",    LFUN_CARON},
61 //  {TEX_SPECIAL_CARON, "\\q", "", "ooo",  LFUN_SPECIAL_CARON},
62         {TEX_HUNGUML,    "\\H", /*" OUou",*/                 "hugarian_umlaut",    LFUN_HUNG_UMLAUT},
63         {TEX_UMLAUT,     "\\\"", /*" AEIOUaeiouy",*/          "umlaut",    LFUN_UMLAUT},
64         {TEX_DOT,        "\\.",  /*" ZzICGicgEe",*/           "dot",    LFUN_DOT},
65         {TEX_OGONEK,     "\\k",  /*" AaEe",*/                 "ogonek",    LFUN_OGONEK},
66         { static_cast<tex_accent>(0), "", /*"",*/ "", static_cast<kb_action>(0)}};
67
68
69 tex_accent_struct get_accent(kb_action action)
70 {
71         int i = 0;
72         while (i <= TEX_MAX_ACCENT) {
73                 if (lyx_accent_table[i].action == action)
74                         return lyx_accent_table[i];
75                 ++i;
76         }
77         struct tex_accent_struct temp = { static_cast<tex_accent>(0), 0,
78                                           0, static_cast<kb_action>(0)};
79         return temp;
80 }
81
82
83 string const DoAccent(string const & s, tex_accent accent)
84 {
85         string res;
86
87         res += lyx_accent_table[accent].cmd;
88         res += '{';
89         if (s == "i" || s == "j") {
90                 res += '\\';
91         }
92         res += s;
93         res += '}';
94         return res;
95 }
96
97
98 string const DoAccent(char c, tex_accent accent)
99 {
100         return DoAccent(tostr(c), accent);
101 }