3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
7 * \author Lars Gullik Bjønnes
9 * Full author contact details are available in file CREDITS.
17 #include "FuncRequest.h"
18 #include "FuncStatus.h"
19 #include "InsetLayout.h"
23 #include "ParagraphParameters.h"
24 #include "Paragraph.h"
25 #include "output_docbook.h"
27 #include "support/docstream.h"
28 #include "support/gettext.h"
29 #include "support/lstrings.h"
30 #include "support/TempFile.h"
37 using namespace lyx::support;
41 InsetERT::InsetERT(Buffer * buf, CollapseStatus status)
42 : InsetCollapsible(buf)
48 InsetERT::InsetERT(InsetERT const & old)
49 : InsetCollapsible(old)
53 void InsetERT::write(ostream & os) const
56 InsetCollapsible::write(os);
60 int InsetERT::plaintext(odocstringstream & os,
61 OutputParams const & rp, size_t max_length) const
64 // do not output TeX code
67 ParagraphList::const_iterator par = paragraphs().begin();
68 ParagraphList::const_iterator end = paragraphs().end();
70 while (par != end && os.str().size() <= max_length) {
71 pos_type siz = par->size();
72 for (pos_type i = 0; i < siz; ++i) {
73 char_type const c = par->getChar(i);
74 // output the active characters
91 static const std::map<docstring, docstring> raw_latex_encoding_to_unicode_xml{
93 {from_ascii("\\textquotesingle"), from_ascii("'")},
94 {from_ascii("!`"), from_ascii("¡")}, // inverted exclamation mark
95 {from_ascii("?`"), from_ascii("¿")}, // inverted interrogation mark
98 {from_ascii("\\LaTeX"), from_ascii("LaTeX")},
99 {from_ascii("\\LaTeXe"), from_ascii("LaTeX2ε")}, // LaTeX 2 epsilon
100 {from_ascii("\\LyX"), from_ascii("LyX")},
101 {from_ascii("\\TeX"), from_ascii("TeX")},
103 // Accentuated letters (alphabetical order of description, ligatures after accents).
104 // Missing letters are only indicated for vowels (only few consonants have diacritics).
105 // Only symbols that can be expressed as one Unicode characters are present; symbols with more than one
106 // diacritic are also omitted.
107 {from_ascii("\\`{a}"), from_ascii("á")}, // a acute
108 {from_ascii("\\` a"), from_ascii("á")},
109 {from_ascii("\\`{A}"), from_ascii("Á")}, // A acute
110 {from_ascii("\\` A"), from_ascii("Á")},
111 {from_ascii("\\u{a}"), from_ascii("ă")}, // a breve
112 {from_ascii("\\u a"), from_ascii("ă")},
113 {from_ascii("\\u{A}"), from_ascii("Ă")}, // A breve
114 {from_ascii("\\u A"), from_ascii("Ă")},
115 {from_ascii("\\v{a}"), from_ascii("ǎ")}, // a caron
116 {from_ascii("\\v a"), from_ascii("ǎ")},
117 {from_ascii("\\v{A}"), from_ascii("Ǎ")}, // A caron
118 {from_ascii("\\v A"), from_ascii("Ǎ")},
120 {from_ascii("\\^{a}"), from_ascii("â")}, // a circumflex
121 {from_ascii("\\^ a"), from_ascii("â")},
122 {from_ascii("\\^{A}"), from_ascii("Â")}, // A circumflex
123 {from_ascii("\\^ A"), from_ascii("Â")},
124 {from_ascii("\\\"{a}"), from_ascii("ä")}, // a diaeresis
125 {from_ascii("\\\" a"), from_ascii("ä")},
126 {from_ascii("\\\"{A}"), from_ascii("Ä")}, // A diaeresis
127 {from_ascii("\\\" A"), from_ascii("Ä")},
128 // No a double acute.
129 {from_ascii("\\`{a}"), from_ascii("à")}, // a grave
130 {from_ascii("\\` a"), from_ascii("à")},
131 {from_ascii("\\`{A}"), from_ascii("À")}, // A grave
132 {from_ascii("\\` A"), from_ascii("À")},
133 {from_ascii("\\~{a}"), from_ascii("ã")}, // a tilde
134 {from_ascii("\\~ a"), from_ascii("ã")},
135 {from_ascii("\\~{A}"), from_ascii("Ã")}, // A tilde
136 {from_ascii("\\~ A"), from_ascii("Ã")},
137 {from_ascii("\\aa"), from_ascii("å")}, // a ring
138 {from_ascii("\\r{a}"), from_ascii("å")},
139 {from_ascii("\\r a"), from_ascii("å")},
140 {from_ascii("\\AA"), from_ascii("Å")}, // A ring
141 {from_ascii("\\r{A}"), from_ascii("Å")},
142 {from_ascii("\\r A"), from_ascii("Å")},
143 {from_ascii("\\ae"), from_ascii("æ")}, // ae ligature
144 {from_ascii("\\AE"), from_ascii("Æ")}, // AE ligature
145 {from_ascii("\\v{c}"), from_ascii("č")}, // c caron
146 {from_ascii("\\v c"), from_ascii("č")},
147 {from_ascii("\\v{C}"), from_ascii("Č")}, // C caron
148 {from_ascii("\\v C"), from_ascii("Č")},
149 {from_ascii("\\c{c}"), from_ascii("Ç")}, // c cedilla
150 {from_ascii("\\c c"), from_ascii("Ç")},
151 {from_ascii("\\c{C}"), from_ascii("ç")}, // C cedilla
152 {from_ascii("\\c C"), from_ascii("ç")},
153 {from_ascii("\\v{d}"), from_ascii("ď")}, // d caron
154 {from_ascii("\\v d"), from_ascii("ď")},
155 {from_ascii("\\v{D}"), from_ascii("Ď")}, // D caron
156 {from_ascii("\\v D"), from_ascii("Ď")},
157 {from_ascii("\\`{e}"), from_ascii("é")}, // e acute
158 {from_ascii("\\` e"), from_ascii("é")},
159 {from_ascii("\\`{E}"), from_ascii("É")}, // E acute
160 {from_ascii("\\` E"), from_ascii("É")},
161 {from_ascii("\\u{e}"), from_ascii("ĕ")}, // e breve
162 {from_ascii("\\u e"), from_ascii("ĕ")},
163 {from_ascii("\\u{E}"), from_ascii("Ĕ")}, // E breve
164 {from_ascii("\\u E"), from_ascii("Ĕ")},
165 {from_ascii("\\v{e}"), from_ascii("ě")}, // e caron
166 {from_ascii("\\v e"), from_ascii("ě")},
167 {from_ascii("\\v{E}"), from_ascii("Ě")}, // E caron
168 {from_ascii("\\v E"), from_ascii("Ě")},
169 {from_ascii("\\c{e}"), from_ascii("ȩ")}, // e cedilla
170 {from_ascii("\\c e"), from_ascii("ȩ")},
171 {from_ascii("\\c{E}"), from_ascii("Ȩ")}, // E cedilla
172 {from_ascii("\\c E"), from_ascii("Ȩ")},
173 {from_ascii("\\^{e}"), from_ascii("ê")}, // e circumflex
174 {from_ascii("\\^ e"), from_ascii("ê")},
175 {from_ascii("\\^{E}"), from_ascii("Ê")}, // E circumflex
176 {from_ascii("\\^ E"), from_ascii("Ê")},
177 {from_ascii("\\\"{e}"), from_ascii("ë")}, // e diaeresis
178 {from_ascii("\\\" e"), from_ascii("ë")},
179 {from_ascii("\\\"{E}"), from_ascii("Ë")}, // E diaeresis
180 {from_ascii("\\\" E"), from_ascii("Ë")},
181 // No e double acute.
182 {from_ascii("\\`{e}"), from_ascii("è")}, // e grave
183 {from_ascii("\\` e"), from_ascii("è")},
184 {from_ascii("\\`{E}"), from_ascii("È")}, // E grave
185 {from_ascii("\\` E"), from_ascii("È")},
186 {from_ascii("\\~{e}"), from_ascii("ẽ")}, // e tilde
187 {from_ascii("\\~ e"), from_ascii("ẽ")},
188 {from_ascii("\\~{E}"), from_ascii("Ẽ")}, // E tilde
189 {from_ascii("\\~ E"), from_ascii("Ẽ")},
191 {from_ascii("\\u{g}"), from_ascii("ğ")}, // g breve
192 {from_ascii("\\u g"), from_ascii("ğ")},
193 {from_ascii("\\u{G}"), from_ascii("Ğ")}, // G breve
194 {from_ascii("\\u G"), from_ascii("Ğ")},
195 {from_ascii("\\v{g}"), from_ascii("ǧ")}, // g caron
196 {from_ascii("\\v g"), from_ascii("ǧ")},
197 {from_ascii("\\v{G}"), from_ascii("Ǧ")}, // G caron
198 {from_ascii("\\v G"), from_ascii("Ǧ")},
199 {from_ascii("\\c{g}"), from_ascii("ģ")}, // g cedilla
200 {from_ascii("\\c g"), from_ascii("ģ")},
201 {from_ascii("\\c{G}"), from_ascii("Ģ")}, // G cedilla
202 {from_ascii("\\c G"), from_ascii("Ģ")},
203 {from_ascii("\\i"), from_ascii("ı")}, // i dotless
204 {from_ascii("\\`{i}"), from_ascii("í")}, // i acute
205 {from_ascii("\\` i"), from_ascii("í")},
206 {from_ascii("\\`{I}"), from_ascii("Í")}, // I acute
207 {from_ascii("\\` I"), from_ascii("Í")},
208 {from_ascii("\\u{i}"), from_ascii("ĭ")}, // i breve
209 {from_ascii("\\u i"), from_ascii("ĭ")},
210 {from_ascii("\\u{I}"), from_ascii("Ĭ")}, // I breve
211 {from_ascii("\\u I"), from_ascii("Ĭ")},
212 {from_ascii("\\v{i}"), from_ascii("ǐ")}, // i caron
213 {from_ascii("\\v i"), from_ascii("ǐ")},
214 {from_ascii("\\v{I}"), from_ascii("Ǐ")}, // I caron
215 {from_ascii("\\v I"), from_ascii("Ǐ")},
217 {from_ascii("\\^{i}"), from_ascii("î")}, // i circumflex
218 {from_ascii("\\^ i"), from_ascii("î")},
219 {from_ascii("\\^{I}"), from_ascii("Î")}, // I circumflex
220 {from_ascii("\\^ I"), from_ascii("ï")},
221 {from_ascii("\\\"{i}"), from_ascii("ï")}, // i diaeresis
222 {from_ascii("\\\" i"), from_ascii("ë")},
223 {from_ascii("\\\"{I}"), from_ascii("ë")}, // I diaeresis
224 {from_ascii("\\\" I"), from_ascii("Ï")},
225 // No i double acute.
226 {from_ascii("\\`{i}"), from_ascii("ì")}, // i grave
227 {from_ascii("\\` i"), from_ascii("ì")},
228 {from_ascii("\\`{I}"), from_ascii("Ì")}, // I grave
229 {from_ascii("\\` I"), from_ascii("Ì")},
230 {from_ascii("\\~{i}"), from_ascii("ĩ")}, // i tilde
231 {from_ascii("\\~ i"), from_ascii("ĩ")},
232 {from_ascii("\\~{I}"), from_ascii("Ĩ")}, // I tilde
233 {from_ascii("\\~ I"), from_ascii("Ĩ")},
235 {from_ascii("\\j"), from_ascii("ȷ")}, // j dotless
236 {from_ascii("\\v{k}"), from_ascii("Ǩ")}, // k caron
237 {from_ascii("\\v k"), from_ascii("Ǩ")},
238 {from_ascii("\\v{K}"), from_ascii("ǩ")}, // K caron
239 {from_ascii("\\v K"), from_ascii("ǩ")},
240 {from_ascii("\\c{k}"), from_ascii("ķ")}, // k cedilla
241 {from_ascii("\\c k"), from_ascii("ķ")},
242 {from_ascii("\\c{K}"), from_ascii("Ķ")}, // K cedilla
243 {from_ascii("\\c K"), from_ascii("Ķ")},
244 {from_ascii("\\v{l}"), from_ascii("ľ")}, // l caron
245 {from_ascii("\\v l"), from_ascii("ľ")},
246 {from_ascii("\\v{L}"), from_ascii("Ľ")}, // L caron
247 {from_ascii("\\v L"), from_ascii("Ľ")},
248 {from_ascii("\\c{l}"), from_ascii("ļ")}, // l cedilla
249 {from_ascii("\\c l"), from_ascii("ļ")},
250 {from_ascii("\\c{L}"), from_ascii("Ļ")}, // L cedilla
251 {from_ascii("\\c L"), from_ascii("Ļ")},
252 {from_ascii("\\l"), from_ascii("ł")}, // l stroke
253 {from_ascii("\\L"), from_ascii("Ł")}, // L stroke
254 {from_ascii("\\v{n}"), from_ascii("ň")}, // n caron
255 {from_ascii("\\v n"), from_ascii("ň")},
256 {from_ascii("\\v{N}"), from_ascii("Ň")}, // N caron
257 {from_ascii("\\v N"), from_ascii("Ň")},
258 {from_ascii("\\c{n}"), from_ascii("ņ")}, // n cedilla
259 {from_ascii("\\c n"), from_ascii("ņ")},
260 {from_ascii("\\c{N}"), from_ascii("Ņ")}, // N cedilla
261 {from_ascii("\\c N"), from_ascii("Ņ")},
262 {from_ascii("\\~{n}"), from_ascii("ñ")}, // n tilde
263 {from_ascii("\\~ n"), from_ascii("ñ")},
264 {from_ascii("\\~{N}"), from_ascii("Ñ")}, // N tilde
265 {from_ascii("\\~ N"), from_ascii("Ñ")},
266 {from_ascii("\\`{o}"), from_ascii("ó")}, // o acute
267 {from_ascii("\\` o"), from_ascii("ó")},
268 {from_ascii("\\`{O}"), from_ascii("Ó")}, // O acute
269 {from_ascii("\\` O"), from_ascii("Ó")},
270 {from_ascii("\\u{o}"), from_ascii("ŏ")}, // o breve
271 {from_ascii("\\u o"), from_ascii("ŏ")},
272 {from_ascii("\\u{O}"), from_ascii("Ŏ")}, // O breve
273 {from_ascii("\\u O"), from_ascii("Ŏ")},
274 {from_ascii("\\v{o}"), from_ascii("ǒ")}, // o caron
275 {from_ascii("\\v o"), from_ascii("ǒ")},
276 {from_ascii("\\v{O}"), from_ascii("Ǒ")}, // O caron
277 {from_ascii("\\v O"), from_ascii("Ǒ")},
279 {from_ascii("\\^{o}"), from_ascii("ô")}, // o circumflex
280 {from_ascii("\\^ o"), from_ascii("ô")},
281 {from_ascii("\\^{O}"), from_ascii("Ô")}, // O circumflex
282 {from_ascii("\\^ O"), from_ascii("Ô")},
283 {from_ascii("\\\"{o}"), from_ascii("ö")}, // o diaeresis
284 {from_ascii("\\\" o"), from_ascii("ö")},
285 {from_ascii("\\\"{O}"), from_ascii("Ö")}, // O diaeresis
286 {from_ascii("\\\" O"), from_ascii("Ö")},
287 {from_ascii("\\H{o}"), from_ascii("ő")}, // o double acute
288 {from_ascii("\\H o"), from_ascii("ő")},
289 {from_ascii("\\H{O}"), from_ascii("Ő")}, // O double acute
290 {from_ascii("\\H O"), from_ascii("Ő")},
291 {from_ascii("\\`{o}"), from_ascii("ò")}, // o grave
292 {from_ascii("\\` o"), from_ascii("ò")},
293 {from_ascii("\\`{O}"), from_ascii("Ò")}, // O grave
294 {from_ascii("\\` O"), from_ascii("Ò")},
295 {from_ascii("\\o"), from_ascii("ø")}, // o stroke
296 {from_ascii("\\O"), from_ascii("Ø")}, // O stroke
297 {from_ascii("\\~{o}"), from_ascii("õ")}, // o tilde
298 {from_ascii("\\~ o"), from_ascii("õ")},
299 {from_ascii("\\~{O}"), from_ascii("Õ")}, // O tilde
300 {from_ascii("\\~ O"), from_ascii("Õ")},
302 {from_ascii("\\oe"), from_ascii("œ")}, // oe ligature
303 {from_ascii("\\OE"), from_ascii("Œ")}, // OE ligature
304 {from_ascii("\\v{r}"), from_ascii("ř")}, // r caron
305 {from_ascii("\\v r"), from_ascii("ř")},
306 {from_ascii("\\v{R}"), from_ascii("Ř")}, // R caron
307 {from_ascii("\\v R"), from_ascii("Ř")},
308 {from_ascii("\\c{r}"), from_ascii("ŗ")}, // r cedilla
309 {from_ascii("\\c r"), from_ascii("ŗ")},
310 {from_ascii("\\c{R}"), from_ascii("Ŗ")}, // R cedilla
311 {from_ascii("\\c R"), from_ascii("Ŗ")},
312 {from_ascii("\\v{s}"), from_ascii("š")}, // s caron
313 {from_ascii("\\v s"), from_ascii("š")},
314 {from_ascii("\\v{S}"), from_ascii("Š")}, // S caron
315 {from_ascii("\\v S"), from_ascii("Š")},
316 {from_ascii("\\c{s}"), from_ascii("ş")}, // s cedilla
317 {from_ascii("\\c s"), from_ascii("ş")},
318 {from_ascii("\\c{S}"), from_ascii("Ş")}, // S cedilla
319 {from_ascii("\\c S"), from_ascii("Ş")},
320 {from_ascii("\\v{t}"), from_ascii("ť")}, // t caron
321 {from_ascii("\\v t"), from_ascii("ť")},
322 {from_ascii("\\v{T}"), from_ascii("Ť")}, // T caron
323 {from_ascii("\\v T"), from_ascii("Ť")},
324 {from_ascii("\\c{t}"), from_ascii("ţ")}, // t cedilla
325 {from_ascii("\\c t"), from_ascii("ţ")},
326 {from_ascii("\\c{T}"), from_ascii("Ţ")}, // T cedilla
327 {from_ascii("\\c T"), from_ascii("Ţ")},
328 {from_ascii("\\`{u}"), from_ascii("ú")}, // u acute
329 {from_ascii("\\` u"), from_ascii("ú")},
330 {from_ascii("\\`{U}"), from_ascii("Ú")}, // U acute
331 {from_ascii("\\` U"), from_ascii("Ú")},
332 {from_ascii("\\u{u}"), from_ascii("ŭ")}, // u breve
333 {from_ascii("\\u u"), from_ascii("ŭ")},
334 {from_ascii("\\u{U}"), from_ascii("Ŭ")}, // U breve
335 {from_ascii("\\u U"), from_ascii("Ŭ")},
336 {from_ascii("\\v{u}"), from_ascii("ǔ")}, // u caron
337 {from_ascii("\\v u"), from_ascii("ǔ")},
338 {from_ascii("\\v{U}"), from_ascii("Ǔ")}, // U caron
339 {from_ascii("\\v U"), from_ascii("Ǔ")},
341 {from_ascii("\\^{u}"), from_ascii("û")}, // u circumflex
342 {from_ascii("\\^ u"), from_ascii("û")},
343 {from_ascii("\\^{U}"), from_ascii("Û")}, // U circumflex
344 {from_ascii("\\^ U"), from_ascii("Û")},
345 {from_ascii("\\\"{u}"), from_ascii("ü")}, // u diaeresis
346 {from_ascii("\\\" u"), from_ascii("ü")},
347 {from_ascii("\\\"{U}"), from_ascii("Ü")}, // U diaeresis
348 {from_ascii("\\\" U"), from_ascii("Ü")},
349 {from_ascii("\\H{u}"), from_ascii("ű")}, // u double acute
350 {from_ascii("\\H u"), from_ascii("ű")},
351 {from_ascii("\\H{U}"), from_ascii("Ű")}, // U double acute
352 {from_ascii("\\H U"), from_ascii("Ű")},
353 {from_ascii("\\`{u}"), from_ascii("ù")}, // u grave
354 {from_ascii("\\` u"), from_ascii("ù")},
355 {from_ascii("\\`{U}"), from_ascii("Ù")}, // U grave
356 {from_ascii("\\` U"), from_ascii("Ù")},
357 {from_ascii("\\~{u}"), from_ascii("ũ")}, // u tilde
358 {from_ascii("\\~ u"), from_ascii("ũ")},
359 {from_ascii("\\~{U}"), from_ascii("Ũ")}, // U tilde
360 {from_ascii("\\~ U"), from_ascii("Ũ")},
361 {from_ascii("\\r{u}"), from_ascii("å")}, // u ring
362 {from_ascii("\\r u"), from_ascii("ů")},
363 {from_ascii("\\r{U}"), from_ascii("ů")}, // U ring
364 {from_ascii("\\r U"), from_ascii("Ů")},
365 {from_ascii("\\`{y}"), from_ascii("ý")}, // y acute
366 {from_ascii("\\` y"), from_ascii("ý")},
367 {from_ascii("\\`{Y}"), from_ascii("Ý")}, // Y acute
368 {from_ascii("\\` Y"), from_ascii("Ý")},
369 {from_ascii("\\v{z}"), from_ascii("ž")}, // z caron
370 {from_ascii("\\v z"), from_ascii("ž")},
371 {from_ascii("\\v{Z}"), from_ascii("Ž")}, // Z caron
372 {from_ascii("\\v Z"), from_ascii("Ž")},
375 {from_ascii("\\^{y}"), from_ascii("ŷ")}, // y circumflex
376 {from_ascii("\\^ y"), from_ascii("ŷ")},
377 {from_ascii("\\^{Y}"), from_ascii("Ŷ")}, // Y circumflex
378 {from_ascii("\\^ Y"), from_ascii("Ŷ")},
379 {from_ascii("\\\"{y}"), from_ascii("ÿ")}, // y diaeresis
380 {from_ascii("\\\" y"), from_ascii("ÿ")},
381 {from_ascii("\\\"{Y}"), from_ascii("Ÿ")}, // Y diaeresis
382 {from_ascii("\\\" Y"), from_ascii("Ÿ")},
383 // No y double acute.
384 {from_ascii("\\`{y}"), from_ascii("ỳ")}, // y grave
385 {from_ascii("\\` y"), from_ascii("ỳ")},
386 {from_ascii("\\`{Y}"), from_ascii("Ỳ")}, // Y grave
387 {from_ascii("\\` Y"), from_ascii("Ỳ")},
388 {from_ascii("\\~{y}"), from_ascii("ỹ")}, // y tilde
389 {from_ascii("\\~ y"), from_ascii("ỹ")},
390 {from_ascii("\\~{Y}"), from_ascii("Ỹ")}, // Y tilde
391 {from_ascii("\\~ Y"), from_ascii("Ỹ")},
396 void InsetERT::docbook(XMLStream & xs, OutputParams const & runparams) const
398 auto const begin = paragraphs().begin();
400 auto const end = paragraphs().end();
402 odocstringstream os; // No need for XML handling here.
404 // Recreate the logic of makeParagraph in output_docbook.cpp, but much simplified: never open <para>
405 // in an ERT, use simple line breaks.
406 // New line after each paragraph of the ERT, save the last one.
407 while (true) { // For each paragraph in the ERT...
408 std::vector<docstring> pars_prepend;
409 std::vector<docstring> pars;
410 std::vector<docstring> pars_append;
411 tie(pars_prepend, pars, pars_append) = par->simpleDocBookOnePar(buffer(), runparams, text().outerFont(distance(begin, par)), 0, false, true);
413 for (docstring const & parXML : pars_prepend)
414 xs << XMLStream::ESCAPE_NONE << parXML;
415 auto p = pars.begin();
416 while (true) { // For each line of this ERT paragraph...
424 for (docstring const & parXML : pars_append)
425 xs << XMLStream::ESCAPE_NONE << parXML;
434 // // Implement the special case of \and: split the current item.
435 // if (os.str() == "\\and" || os.str() == "\\and ") {
436 // auto lay = getLayout();
439 // Try to recognise some commands to have a nicer DocBook output.
440 bool output_as_comment = true;
442 // First step: some commands have a direct mapping to DocBook, mostly because the mapping is simply text or
445 docstring os_trimmed = trim(os.str());
447 auto command_raw_translation = raw_latex_encoding_to_unicode_xml.find(os_trimmed);
448 if (command_raw_translation != raw_latex_encoding_to_unicode_xml.end()) {
449 xs << command_raw_translation->second;
450 output_as_comment = false;
452 // If the trimmed ERT ends with {}, try a mapping without it.
453 auto os_braces = os_trimmed.find(from_ascii("{}"));
455 if (os_braces != lyx::docstring::npos) {
456 auto key = os_trimmed.substr(0, os_braces);
457 auto command_braces_translation = raw_latex_encoding_to_unicode_xml.find(key);
459 if (command_braces_translation != raw_latex_encoding_to_unicode_xml.end()) {
460 xs << command_braces_translation->second;
461 output_as_comment = false;
467 // Second step: the command \string can be ignored. If that's the only command in the ERT, then done.
468 // There may be several occurrences. (\string is 7 characters long.)
469 if (os.str().length() >= 7) {
470 docstring os_str = os.str();
472 while (os_str.length() >= 7) {
473 auto os_text = os_str.find(from_ascii("\\string"));
475 if (os_text != lyx::docstring::npos && !std::isalpha(static_cast<int>(os_str[os_text + 7]))) {
476 os_str = os_str.substr(0, os_text) + os_str.substr(os_text + 7, os_str.length());
478 if (os_str.find('\\') == std::string::npos) {
480 output_as_comment = false;
489 // Otherwise, output the ERT as a comment with the appropriate escaping if the command is not recognised.
490 if (output_as_comment) {
491 xs << XMLStream::ESCAPE_NONE << "<!-- ";
492 xs << XMLStream::ESCAPE_COMMENTS << os.str();
493 xs << XMLStream::ESCAPE_NONE << " -->";
498 void InsetERT::doDispatch(Cursor & cur, FuncRequest & cmd)
500 switch (cmd.action()) {
501 case LFUN_INSET_MODIFY:
502 if (cmd.getArg(0) == "ert") {
503 cur.recordUndoInset(this);
504 setStatus(cur, string2params(to_utf8(cmd.argument())));
509 InsetCollapsible::doDispatch(cur, cmd);
516 bool InsetERT::getStatus(Cursor & cur, FuncRequest const & cmd,
517 FuncStatus & status) const
519 switch (cmd.action()) {
520 case LFUN_INSET_INSERT:
521 status.setEnabled(false);
523 case LFUN_INSET_MODIFY:
524 if (cmd.getArg(0) == "ert") {
525 status.setEnabled(true);
531 return InsetCollapsible::getStatus(cur, cmd, status);
537 docstring const InsetERT::buttonLabel(BufferView const & bv) const
540 docstring const locked = tempfile_ ? docstring(1, 0x1F512) : docstring();
541 if (decoration() == InsetDecoration::CLASSIC)
542 return locked + (isOpen(bv) ? _("ERT") : getNewLabel(_("ERT")));
543 return locked + getNewLabel(_("ERT"));
547 InsetCollapsible::CollapseStatus InsetERT::string2params(string const & in)
551 istringstream data(in);
554 lex.setContext("InsetERT::string2params");
558 return static_cast<CollapseStatus>(s);
562 string InsetERT::params2string(CollapseStatus status)
565 data << "ert" << ' ' << status;
570 docstring InsetERT::xhtml(XMLStream &, OutputParams const &) const