- Timestamp:
- 06/27/20 23:14:01 (4 years ago)
- Location:
- cpp/frams/genetics
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
cpp/frams/genetics/genman.cpp
r955 r965 86 86 static ParamEntry GMparam_tab[] = 87 87 { 88 { "Genetics", 1, 1 0, "GenMan", },88 { "Genetics", 1, 11, "GenMan", }, 89 89 { "gen_hist", 0, PARAM_DONTSAVE, "Remember history of genetic operations", "d 0 1 0", FIELD(history), "Required for phylogenetic analysis", }, 90 90 { "gen_hilite", 0, 0, "Use syntax highlighting", "d 0 1 1", FIELD(hilite), "Use colors for genes?\n(slows down viewing/editing of huge genotypes)", }, … … 92 92 { "operReport", 0, PARAM_DONTSAVE, "Operators report", "p()", PROCEDURE(p_report), "Show available genetic operators", }, 93 93 { "toHTML", 0, PARAM_DONTSAVE, "HTMLize a genotype", "p s(s)", PROCEDURE(p_htmlize), "returns genotype expressed as colored HTML", }, 94 { "toHTMLshort", 0, PARAM_DONTSAVE, "HTMLize a genotype, shorten if needed", "p s(s)", PROCEDURE(p_htmlizeshort), "returns genotype (abbreviated if needed) expressed as colored HTML", }, 94 { "toHTMLshort", 0, PARAM_DONTSAVE, "HTMLize a genotype, shorten if needed", "p s(s)", PROCEDURE(p_htmlizeshort), "returns genotype (abbreviated if needed) in colored HTML format", }, 95 { "toLaTeX", 0, PARAM_DONTSAVE, "LaTeXize a genotype", "p s(s)", PROCEDURE(p_latexize), "returns genotype in colored LaTeX format", }, 95 96 { "validate", 0, PARAM_DONTSAVE | PARAM_USERHIDDEN, "Validate", "p oGeno(oGeno)", PROCEDURE(p_validate), "returns validated (if possible) Geno object from supplied Geno", }, 96 97 { "mutate", 0, PARAM_DONTSAVE | PARAM_USERHIDDEN, "Mutate", "p oGeno(oGeno)", PROCEDURE(p_mutate), "returns mutated Geno object from supplied Geno", }, … … 523 524 } 524 525 526 string GenMan::LaTeXize(const char *g) 527 { 528 char buf[50]; 529 int len = strlen(g); 530 int chars = 0, lines = 0; //currently not used 531 uint32_t *styletab = new uint32_t[len]; 532 getFullStyle(g, styletab); 533 string latex = "\\usepackage{xcolor}\n% Using \\texttt{} may be beneficial for some genetic encodings, but then you may lose bold/italic.\n\\noindent \\sloppy"; 534 uint32_t prevstyle, prevcolor, style = 0, color = 0; 535 for (int i = 0; i < len; i++) 536 { 537 if (g[i] == '\r') continue; 538 if (g[i] == '\n') { latex += "\\\\\n"; lines++; continue; } 539 chars++; 540 prevstyle = style; 541 prevcolor = color; 542 style = GENGETSTYLE(styletab[i]); 543 color = GENGETCOLOR(styletab[i]); 544 545 // Unfortunately, LaTeX (as opposed to HTML) uses the same closing tags "}" for color, bold, italic, underline - so they cannot intersect. 546 // Therefore we have to "turn off" everything on every change of style or color, and then "turn on" (to avoid problems with e.g. red-bold-blue-unbold or bold-italic-unbold-unitalic). 547 // This could be optimized by a more complex logic and tracking which color/style section starts and ends within another section. 548 549 if (((style & GENSTYLE_INVALID) != (prevstyle & GENSTYLE_INVALID)) 550 || 551 ((style & GENSTYLE_BOLD) != (prevstyle & GENSTYLE_BOLD)) 552 || 553 ((style & GENSTYLE_ITALIC) != (prevstyle & GENSTYLE_ITALIC)) 554 || 555 ((i == 0 || (color != prevcolor)))) 556 { 557 if (prevstyle & GENSTYLE_INVALID) latex += "}"; 558 if (prevstyle & GENSTYLE_BOLD) latex += "}"; 559 if (prevstyle & GENSTYLE_ITALIC) latex += "}"; 560 if (i != 0) latex += "}"; //for color 561 if (style & GENSTYLE_INVALID) latex += "\\underline{"; 562 if (style & GENSTYLE_BOLD) latex += "\\textbf{"; 563 if (style & GENSTYLE_ITALIC) latex += "\\textit{"; 564 sprintf(buf, "\\textcolor[rgb]{%.2g,%.2g,%.2g}{", GENGET_R(color) / 255.0, GENGET_G(color) / 255.0, GENGET_B(color) / 255.0); latex += buf; 565 } 566 if (g[i] == '<') latex += "$<$"; else if (g[i] == '>') latex += "$>$"; else 567 if (g[i] == '-') latex += "$-$"; else if (g[i] == '|') latex += "$|$"; else 568 if (g[i] == '$') latex += "\\$"; else if (g[i] == '%') latex += "\\%"; else latex += g[i]; 569 if ((i % 3) == 0 && g[i] == ' ') latex += "\n"; //for readability, insert some newlines into latex... 570 if (i % 10 == 0) latex += "{\\hskip 0pt}"; // https://tex.stackexchange.com/questions/33526/automatic-line-breaking-of-long-lines-of-text 571 } 572 delete[] styletab; 573 latex += "}"; //for color (it was used at least once) 574 if (style & GENSTYLE_BOLD) latex += "}"; 575 if (style & GENSTYLE_ITALIC) latex += "}"; 576 latex += "\n"; 577 return latex; 578 } 579 580 void GenMan::p_latexize(ExtValue *args, ExtValue *ret) 581 { 582 ret->setString(LaTeXize(args->getString().c_str()).c_str()); 583 } 584 525 585 Geno GenMan::getSimplest(const SString& format) 526 586 { -
cpp/frams/genetics/genman.h
r955 r965 60 60 GenoOperators* getOper_f(const SString& format); 61 61 string HTMLize(const char *g, bool shorten); 62 string LaTeXize(const char *g); 62 63 int findOperFormatIndex(const SString& format); 63 64 public: … … 80 81 PARAMPROCDEF(p_htmlize); 81 82 PARAMPROCDEF(p_htmlizeshort); 83 PARAMPROCDEF(p_latexize); 82 84 PARAMPROCDEF(p_validate); 83 85 PARAMPROCDEF(p_mutate);
Note: See TracChangeset
for help on using the changeset viewer.