Skip to content

Commit

Permalink
Fix display of LaTeXForm properties.
Browse files Browse the repository at this point in the history
  • Loading branch information
Kasper Peeters committed Nov 9, 2024
1 parent a19d693 commit fc27979
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 17 deletions.
11 changes: 9 additions & 2 deletions core/pythoncdb/py_properties.cc
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,16 @@ namespace cadabra {
std::string bare = Ex_as_latex(for_obj);

if (dynamic_cast<const LaTeXForm*>(prop)) {
bare = std::regex_replace(bare, std::regex(R"(\\)"), "$\\backslash{}$}");
// Since the LaTeXForm property has already been attached, the
// Ex_as_latex call above will replace the original symbol and
// replace it with the LaTeXForm. But we want to show the original
// symbol!
bare = *(for_obj->begin()->name);
bare = std::regex_replace(bare, std::regex(R"(#)"), "\\#");
str << " attached to {\\tt " + bare + "}.";
bare = std::regex_replace(bare, std::regex(R"(\{)"), "\\{");
bare = std::regex_replace(bare, std::regex(R"(\})"), "\\}");
bare = std::regex_replace(bare, std::regex(R"(\\)"), "\\textbackslash{}");
str << " attached to {\\texttt{" + bare + "}}.}";
}
else {
str << " attached to~}" + bare + ".";
Expand Down
2 changes: 2 additions & 0 deletions doc/the_cadabra_book.tex
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,8 @@ \chapter{The input format}
%==================================================================
\chapter{Mathematical properties}
\input{ref_derivatives.tex}
\input{ref_accents.tex}
\input{ref_ordering.tex}

%==================================================================
\chapter{Manipulating expressions}
Expand Down
30 changes: 20 additions & 10 deletions frontend/gtkmm/TeXView.cc
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,11 @@ void TeXView::TeXArea::get_preferred_height_for_width_vfunc(int width,
int remember = rendering_width;
rendering_width = width - 2*padding_x;
layout_latex();
minimum_height = _render->getHeight() + 2*padding_y;
natural_height = _render->getHeight() + 2*padding_y;
// std::cerr << "**** computed for width " << width << " height as " << natural_height << std::endl;
if(_render!=nullptr) {
minimum_height = _render->getHeight() + 2*padding_y;
natural_height = _render->getHeight() + 2*padding_y;
// std::cerr << "**** computed for width " << width << " height as " << natural_height << std::endl;
}
if(rendering_width==9999)
rendering_width = remember;
}
Expand Down Expand Up @@ -229,16 +231,24 @@ void TeXView::TeXArea::update_image(std::shared_ptr<TeXEngine::TeXRequest> conte

void TeXView::TeXArea::layout_latex() const
{
if(_render)
if(_render) {
delete _render;
_render = nullptr;
}

// std::cerr << "running layout with text_size = " << _text_size << std::endl;
_render = microtex::MicroTeX::parse(
fixed, //microtex::utf82wide(fixed),
rendering_width,
_text_size,
_text_size / 3.f,
0xff424242);
try {
// std::cerr << "fixed = " << fixed << std::endl;
_render = microtex::MicroTeX::parse(
fixed, //microtex::utf82wide(fixed),
rendering_width,
_text_size,
_text_size / 3.f,
0xff424242);
}
catch(std::exception& err) {
std::cerr << "MicroTeX::parse: exception parsing input (" << fixed << "): " << err.what() << std::endl;
}
}

guint32 color_from_rgba(Gdk::RGBA color)
Expand Down
1 change: 0 additions & 1 deletion submodules/microtex
Submodule microtex deleted from d68cf3
6 changes: 6 additions & 0 deletions web2/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ set(TUTORIALS
ref_exponents
ref_spacing
ref_implicit_versus_explicit
ref_indexbrackets
ref_accents
ref_ordering
ref_selecting
ref_c++_library
)
Expand All @@ -66,6 +69,9 @@ set(BOOK_PARTS
ref_exponents
ref_spacing
ref_implicit_versus_explicit
ref_indexbrackets
ref_accents
ref_ordering
ref_selecting
ref_c++_library
)
Expand Down
8 changes: 4 additions & 4 deletions web2/cadabra2/source/help.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
{% block head %}{%- endblock %}

{% block main %}
<h1>Help</h1>
<h1>Help and book</h1>

<h2>Forum</h2>

Expand Down Expand Up @@ -57,14 +57,14 @@ <h2>The Cadabra book</h2>
<li><a href="notebooks/ref_exponents.html">Exponents, indices and labels</a></li>
<li><a href="notebooks/ref_spacing.html">Spacing and brackets</a></li>
<li><a href="notebooks/ref_implicit_versus_explicit.html">Implicit versus explicit indices</a></li>
<li><a href="notebooks/ref_indexbrackets">Index brackets</a></li>
<li><a href="notebooks/ref_indexbrackets.html">Index brackets</a></li>
</ol>
</li>
<li>Mathematical properties
<ol>
<li><a href="notebooks/ref_derivatives.html">Derivatives and implicit dependence on coordinates</a></li>
<li>Accents</li>
<li>Symbol ordering and commutation properties</li>
<li><a href="notebooks/ref_accents.html">Accents</a></li>
<li><a href="notebooks/ref_ordering.html">Symbol ordering and commutation properties</a></li>
<li>Anti-commuting objects and derivatives</li>
</ol>
<li>Manipulating expressions
Expand Down

0 comments on commit fc27979

Please sign in to comment.