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