Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 23 additions & 23 deletions engine/equationDisplayRender.cc
Original file line number Diff line number Diff line change
Expand Up @@ -520,21 +520,21 @@ namespace MathDAG
template <>
void OperationDAG<OperationType::asin>::render(Surface& surf) const
{
print(surf.cairo(),"sin<sup>-1</sup>",Anchor::nw);
print(surf.cairo(),"sin<span size=\"smaller\" rise=\"5000\">-1</span>",Anchor::nw);
if (!arguments.empty() && !arguments[0].empty() && arguments[0][0])
{parenthesise(surf, [&](Surface& surf){arguments[0][0]->render(surf);});}
}
template <>
Comment thread
highperformancecoder marked this conversation as resolved.
Resolved
void OperationDAG<OperationType::acos>::render(Surface& surf) const
{
print(surf.cairo(),"cos<small><sup>-1</sup></small>",Anchor::nw);
print(surf.cairo(),"cos<span size=\"smaller\" rise=\"5000\">-1</span>",Anchor::nw);
if (!arguments.empty() && !arguments[0].empty() && arguments[0][0])
{parenthesise(surf, [&](Surface& surf){arguments[0][0]->render(surf);});}
}
template <>
void OperationDAG<OperationType::atan>::render(Surface& surf) const
{
print(surf.cairo(),"tan<small><sup>-1</sup></small>",Anchor::nw);
print(surf.cairo(),"tan<span size=\"smaller\" rise=\"5000\">-1</span>",Anchor::nw);
if (!arguments.empty() && !arguments[0].empty() && arguments[0][0])
{parenthesise(surf, [&](Surface& surf){arguments[0][0]->render(surf);});}
}
Expand Down Expand Up @@ -674,46 +674,46 @@ namespace MathDAG
template <>
void OperationDAG<OperationType::sum>::render(Surface& surf) const
{
print(surf.cairo(),"∑<sub>i</sub>",Anchor::nw);
print(surf.cairo(),"∑<span size=\"smaller\" rise=\"-2000\">i</span>",Anchor::nw);
if (!arguments.empty() && !arguments[0].empty() && arguments[0][0])
{
const double h=parenthesise(surf, [&](Surface& surf){arguments[0][0]->render(surf);});
cairo_rel_move_to(surf.cairo(), 0, 0.5*h);
print(surf.cairo(),"<sub>i</sub>",Anchor::nw);
print(surf.cairo(),"<span size=\"smaller\" rise=\"-2000\">i</span>",Anchor::nw);
cairo_rel_move_to(surf.cairo(), 0, -0.5*h);
}
}

template <>
void OperationDAG<OperationType::product>::render(Surface& surf) const
{
print(surf.cairo(),"∏<sub>i</sub>",Anchor::nw);
print(surf.cairo(),"∏<span size=\"smaller\" rise=\"-2000\">i</span>",Anchor::nw);
if (!arguments.empty() && !arguments[0].empty() && arguments[0][0])
{
parenthesise(surf, [&](Surface& surf){arguments[0][0]->render(surf);});
print(surf.cairo(),"<sub>i</sub>",Anchor::nw);
print(surf.cairo(),"<span size=\"smaller\" rise=\"-2000\">i</span>",Anchor::nw);
}
}

template <>
void OperationDAG<OperationType::infimum>::render(Surface& surf) const
{
print(surf.cairo(),"min<sub>i</sub>",Anchor::nw);
print(surf.cairo(),"min<span size=\"smaller\" rise=\"-2000\">i</span>",Anchor::nw);
if (!arguments.empty() && !arguments[0].empty() && arguments[0][0])
{
parenthesise(surf, [&](Surface& surf){arguments[0][0]->render(surf);});
print(surf.cairo(),"<sub>i</sub>",Anchor::nw);
print(surf.cairo(),"<span size=\"smaller\" rise=\"-2000\">i</span>",Anchor::nw);
}
}

template <>
void OperationDAG<OperationType::supremum>::render(Surface& surf) const
{
print(surf.cairo(),"min<sub>i</sub>",Anchor::nw);
print(surf.cairo(),"min<span size=\"smaller\" rise=\"-2000\">i</span>",Anchor::nw);
if (!arguments.empty() && !arguments[0].empty() && arguments[0][0])
{
parenthesise(surf, [&](Surface& surf){arguments[0][0]->render(surf);});
print(surf.cairo(),"<sub>i</sub>",Anchor::nw);
print(surf.cairo(),"<span size=\"smaller\" rise=\"-2000\">i</span>",Anchor::nw);
}
}

Expand All @@ -734,55 +734,55 @@ namespace MathDAG
template <>
void OperationDAG<OperationType::any>::render(Surface& surf) const
{
print(surf.cairo(),"Θ(max<sub>i</sub>",Anchor::nw);
print(surf.cairo(),"Θ(max<span size=\"smaller\" rise=\"-2000\">i</span>",Anchor::nw);
if (!arguments.empty() && !arguments[0].empty() && arguments[0][0])
{
parenthesise(surf, [&](Surface& surf){arguments[0][0]->render(surf);});
print(surf.cairo(),"<sub>i</sub>&gt;0.5)",Anchor::nw);
print(surf.cairo(),"<span size=\"smaller\" rise=\"-2000\">i</span>&gt;0.5)",Anchor::nw);
}
}

template <>
void OperationDAG<OperationType::all>::render(Surface& surf) const
{
print(surf.cairo(),"∏<sub>i</sub>Θ(",Anchor::nw);
print(surf.cairo(),"∏<span size=\"smaller\" rise=\"-2000\">i</span>Θ(",Anchor::nw);
if (!arguments.empty() && !arguments[0].empty() && arguments[0][0])
{
parenthesise(surf, [&](Surface& surf){arguments[0][0]->render(surf);});
print(surf.cairo(),"<sub>i</sub>&gt;0.5)",Anchor::nw);
print(surf.cairo(),"<span size=\"smaller\" rise=\"-2000\">i</span>&gt;0.5)",Anchor::nw);
}
}

template <>
void OperationDAG<OperationType::runningSum>::render(Surface& surf) const
{
print(surf.cairo(),"∑<sub>j=0</sub><sup>i</sup>",Anchor::nw);
print(surf.cairo(),"∑<span size=\"smaller\" rise=\"-2000\">j=0</span><span size=\"smaller\" rise=\"5000\">i</span>",Anchor::nw);
if (!arguments.empty() && !arguments[0].empty() && arguments[0][0])
{
parenthesise(surf, [&](Surface& surf){arguments[0][0]->render(surf);});
print(surf.cairo(),"<sub>j</sub>",Anchor::nw);
print(surf.cairo(),"<span size=\"smaller\" rise=\"-2000\">j</span>",Anchor::nw);
}
}

template <>
void OperationDAG<OperationType::runningAv>::render(Surface& surf) const
{
print(surf.cairo(),"(1/i)∑<sub>j=0</sub><sup>i</sup>",Anchor::nw);
print(surf.cairo(),"(1/i)∑<span size=\"smaller\" rise=\"-2000\">j=0</span><span size=\"smaller\" rise=\"5000\">i</span>",Anchor::nw);
if (!arguments.empty() && !arguments[0].empty() && arguments[0][0])
{
parenthesise(surf, [&](Surface& surf){arguments[0][0]->render(surf);});
print(surf.cairo(),"<sub>j</sub>",Anchor::nw);
print(surf.cairo(),"<span size=\"smaller\" rise=\"-2000\">j</span>",Anchor::nw);
}
}

template <>
void OperationDAG<OperationType::runningProduct>::render(Surface& surf) const
{
print(surf.cairo(),"∏<sub>j=0</sub><sup>i</sup>",Anchor::nw);
print(surf.cairo(),"∏<span size=\"smaller\" rise=\"-2000\">j=0</span><span size=\"smaller\" rise=\"5000\">i</span>",Anchor::nw);
if (!arguments.empty() && !arguments[0].empty() && arguments[0][0])
{
parenthesise(surf, [&](Surface& surf){arguments[0][0]->render(surf);});
print(surf.cairo(),"<sub>j</sub>",Anchor::nw);
print(surf.cairo(),"<span size=\"smaller\" rise=\"-2000\">j</span>",Anchor::nw);
}
}

Expand All @@ -793,7 +793,7 @@ namespace MathDAG
if (!arguments.empty() && !arguments[0].empty() && arguments[0][0])
{
parenthesise(surf, [&](Surface& surf){arguments[0][0]->render(surf);});
print(surf.cairo(),"<sub>i</sub>",Anchor::nw);
print(surf.cairo(),"<span size=\"smaller\" rise=\"-2000\">i</span>",Anchor::nw);
}
}

Expand All @@ -804,7 +804,7 @@ namespace MathDAG
if (!arguments.empty() && !arguments[0].empty() && arguments[0][0])
{
parenthesise(surf, [&](Surface& surf){arguments[0][0]->render(surf);});
print(surf.cairo(),"<sub>i</sub>",Anchor::nw);
print(surf.cairo(),"<span size=\"smaller\" rise=\"-2000\">i</span>",Anchor::nw);
}
}

Expand Down
24 changes: 19 additions & 5 deletions engine/latexMarkup.cc
Original file line number Diff line number Diff line change
Expand Up @@ -726,6 +726,20 @@ namespace

Result(const string& x=""): string(x) {}

// Pango's <sub>/<sup> markup is rendered with the wrong font size
// when the layout is created under a scaled cairo context (ticket 787),
// so use an explicit size and rise instead.
static string openTag(const string& x)
{
if (x=="sup") return "<span size=\"smaller\" rise=\"5000\">";
if (x=="sub") return "<span size=\"smaller\" rise=\"-2000\">";
Comment on lines +734 to +735

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Canonical ids are only used for the Minsky::variableValue keys. I don't see them used elsewhere. The main purpose is to correctly identify the name strings x_1 with x_{1}, and to not identify x_10 and x_{10}. But schemas only store the LaTeX encoded name strings.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot - see above reponse

return "<"+x+">";
}
static string closeTag(const string& x)
{
return (x=="sup"||x=="sub")? "</span>": "</"+x+">";
}

void push_back(const string& x,bool popAgain=false)
{
stack.push_back(x);
Expand All @@ -749,22 +763,22 @@ namespace
else
{
if (!x.empty())
*this+="<"+x+">";
*this+=openTag(x);
push_back(x);
input++;
}
else if (*input=='\\')
{
push_back(x,x!="{");
if (!x.empty())
*this+="<"+x+">";
*this+=openTag(x);
processLaTeX(input);
return;
}
else if (x=="rm")
*this+=utf8char(input);
else if (!x.empty())
*this+=string("<")+x+">"+utf8char(input)+"</"+x+">";
*this+=openTag(x)+utf8char(input)+closeTag(x);
}

void pop()
Expand All @@ -773,7 +787,7 @@ namespace
do
{
if (!stack.back().empty() && stack.back()!="{")
*this+="</"+stack.back()+">";
*this+=closeTag(stack.back());
stack.pop_back();
popMore.pop_back();
} while (!stack.empty() && !popMore.empty() && popMore.back());
Expand Down Expand Up @@ -817,7 +831,7 @@ namespace
if (*input=='[')
{
const string index=parseOpt(input);
*this+="<small><sup>"+index+"</sup></small>";
*this+=openTag("sup")+index+closeTag("sup");
}
*this+=latexSymbols["surd"];
process1arg("", input);
Expand Down
7 changes: 6 additions & 1 deletion engine/variableValue.cc
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,12 @@ namespace minsky
}

string expMultiplier(int exp)
{return exp!=0? "×10<sup>"+std::to_string(exp)+"</sup>": "";}
{
// Note: <sup> markup is rendered with an oversized exponent by Pango when the
// layout is created under a scaled cairo context (ticket 787), so use an
// explicit size/rise instead.
return exp!=0? "×10<span size=\"smaller\" rise=\"5000\">"+std::to_string(exp)+"</span>": "";
}


void VariableValue::exportAsCSV(const string& filename, const string& comment, bool tabular) const
Expand Down
26 changes: 13 additions & 13 deletions test/testLatexToPango.cc
Original file line number Diff line number Diff line change
Expand Up @@ -26,29 +26,29 @@ TEST(LaTeXToPango, LaTeXToPango)
{
struct {const char* latex, *pango;}
qr[]= {
{"x^yz", "<i>x<sup>y</sup>z</i>"},
{"x^{yy}z","<i>x<sup>yy</sup>z</i>"},
{"x^\\mathtt{yy}z","<i>x<sup><tt>yy</tt></sup>z</i>"},
{"x^{\\mathbf{yy}}z","<i>x<sup><b>yy</b></sup>z</i>"},
{"x^yz", "<i>x<span size=\"smaller\" rise=\"5000\">y</span>z</i>"},
{"x^{yy}z","<i>x<span size=\"smaller\" rise=\"5000\">yy</span>z</i>"},
{"x^\\mathtt{yy}z","<i>x<span size=\"smaller\" rise=\"5000\"><tt>yy</tt></span>z</i>"},
{"x^{\\mathbf{yy}}z","<i>x<span size=\"smaller\" rise=\"5000\"><b>yy</b></span>z</i>"},
{"\\mathrm{xxx}", "<i>xxx</i>"},
{"\\mathit{xxx}", "<i><i>xxx</i></i>"},
{"\\mathcal{xxx}", "<i><i>xxx</i></i>"},
{"x_yz", "<i>x<sub>y</sub>z</i>"},
{"x_{yy}z","<i>x<sub>yy</sub>z</i>"},
{"x_\\mathtt{yy}z","<i>x<sub><tt>yy</tt></sub>z</i>"},
{"x_{\\mathbf{yy}}z","<i>x<sub><b>yy</b></sub>z</i>"},
{"x_{\\mathbf{yy}z}","<i>x<sub><b>yy</b>z</sub></i>"},
{"x_yz", "<i>x<span size=\"smaller\" rise=\"-2000\">y</span>z</i>"},
{"x_{yy}z","<i>x<span size=\"smaller\" rise=\"-2000\">yy</span>z</i>"},
{"x_\\mathtt{yy}z","<i>x<span size=\"smaller\" rise=\"-2000\"><tt>yy</tt></span>z</i>"},
{"x_{\\mathbf{yy}}z","<i>x<span size=\"smaller\" rise=\"-2000\"><b>yy</b></span>z</i>"},
{"x_{\\mathbf{yy}z}","<i>x<span size=\"smaller\" rise=\"-2000\"><b>yy</b>z</span></i>"},
{"\\sqrt2","<i>√2</i>"},
{"\\sqrt{2}","<i>√2</i>"},
{"\\sqrt[3]2","<i><small><sup>3</sup></small>√2</i>"},
{"\\sqrt[3]{2}","<i><small><sup>3</sup></small>√2</i>"},
{"\\sqrt[3]2","<i><span size=\"smaller\" rise=\"5000\">3</span>√2</i>"},
{"\\sqrt[3]{2}","<i><span size=\"smaller\" rise=\"5000\">3</span>√2</i>"},
{"\\verb+a_b^y\\mathrm <>&\'\"+",
"<i><tt>a_b^y\\mathrm &lt;&gt;&amp;&apos;&quot;</tt></i>"},
{"\\\"u","<i>ü</i>"},
{"\\\"{u}","<i>ü</i>"},
{"a_\\mathrm1","<i>a<sub>1</sub></i>"},
{"a_\\mathrm1","<i>a<span size=\"smaller\" rise=\"-2000\">1</span></i>"},
{"a{bcd}","<i>abcd</i>"},
{"a_1","<i>a<sub>1</sub></i>"},
{"a_1","<i>a<span size=\"smaller\" rise=\"-2000\">1</span></i>"},
};

for (size_t i=0; i<sizeof(qr)/sizeof(qr[0]); ++i)
Expand Down
Loading