MEP29: Text light markup#
Status#
Discussion
Branches and Pull requests#
None at the moment, proof of concept only.
Abstract#
This MEP proposes to add lightweight markup to the text artist.
Detailed description#
Using different size/color/family in a text annotation is difficult because thetext method accepts argument for size/color/family/weight/etc. that are usedfor the whole text. But, if one wants, for example, to have different colors,one has to look at the gallery where one such example is provided:Concatenate text objects with different properties
This example takes a list of strings as well as a list of colors which makes itcumbersome to use. An alternative would be to use a restricted set ofpango-like markup and to interpret this markup.
Some markup examples:
Hello <b>world!</b>`Hello <span color="blue">world!</span>
Implementation#
A proof of concept is provided inmarkup_example.py but it currently only handles the horizontal direction.
Improvements#
This proof of concept uses regex to parse the text but it may be betterto use the html.parser from the standard library.
Computation of text fragment positions could benefit from the OffsetFromclass. See for example item 5 inUsing Complex Coordinates with Annotations
Problems#
One serious problem is how to deal with text having both LaTeX andHTML-like tags. For example, consider the following:
$<b>Bold$</b>
Recommendation would be to have mutual exclusion.
Backward compatibility#
None at the moment since it is only a proof of concept
Alternatives#
As proposed by @anntzer, this could be also implemented as improvements tomathtext. For example:
r"$\text{Hello \textbf{world}}$"r"$\text{Hello \textcolor{blue}{world}}$"r"$\text{Hello \textsf{\small world}}$"