MEP 29: Markup text #7291

Merged
merged 6 commits into from Nov 5, 2016

Conversation

Projects
None yet
10 participants
Contributor

rougier commented Oct 17, 2016

This is MEP for discussing the opportunity of adding lightweight markup to text.

mdboom added the needs_review label Oct 17, 2016

afvincent added the text label Oct 17, 2016

Member

Kojoley commented Oct 17, 2016

If you are going to add html-like syntax support it is better to use HTMLParser/html5/html5lib module for parsing instead of regular expressions and to validate it with DTD instead of hand-written validator.

Contributor

rougier commented Oct 17, 2016

This would introduce further dependencies and my idea is to have a very lightweight markup, nothing too much elaborated.

Member

Kojoley commented Oct 17, 2016

This would introduce further dependencies

HTMLParser is the part of the Python Standard Library.

Contributor

NelleV commented Oct 17, 2016

Hi @rougier

I think this suggestion is overall a good idea.
Would it be possible to a couple of examples of how the API would look like?

Also, don't forget to change the MEP number of the title and to add the MEP to the index of MEPs: the documentation fails to build on your branch as the new file is not part of any tree.

Contributor

rougier commented Oct 17, 2016

@Kojoley Oh, I see. Ok, I will try to convert my code.

Contributor

rougier commented Oct 17, 2016

@NelleV Problem is that I'm not quite sure of the number to use since there may be other MEP's around (I know for sure MEP28). But anyway, I'll got for 29 and fix the tree.

Contributor

NelleV commented Oct 17, 2016

That's a good point… It's also a good reason to merge MEPs as draft quite quickly.

Contributor

anntzer commented Oct 17, 2016

Wouldn't it make more sense to implement this as improvements to mathtext? instead of

"Hello <b>world</b>!"
"Hello <span color=blue>world</span>!"
"Hello <span family=serif size=x-small>world</span>"

have

r"$\text{Hello \textbf{world}}$"
r"$\text{Hello \textcolor{blue}{world}}$"
r"$\text{Hello \textsf{\small world}}$"

You'll be able to have a better layout this way too (basically keep using the mathtext layout engine).
One could have some helper if "$\text{}$" is too much to type (but TBH you immediately gain back on the fact that you don't need closing tags...).

(Initially posted to matplotlib-devel.)

Contributor

rougier commented Oct 18, 2016

@anntzer This constrains the font family and I find it too verbose compared to the markup version.

Contributor

anntzer commented Oct 18, 2016

In what sense is the font family constrained? The default font will be the same (DejaVu) for mathtext and non-mathtext in 2.0 (#5214), and I'd guess changing the mathtext font and the non-mathtext font is approximately as complicated...

Arguably $\text{}$ is a bit verbose, but anything inside is actually less verbose (compare

<span family=serif>foo</span>

and

\textrm{foo}

or even possibly

{\rm foo}
Contributor

myyc commented Oct 18, 2016

Isn't markdown all the rage nowadays?

Contributor

NelleV commented Oct 18, 2016

I think supporting markdown or html-like support would be a nice additional feature.

As on the other MEPs, I'd suggest merging this as soon as possible as a draft, and discuss about this on the mailing list.

Owner

efiring commented Oct 18, 2016

@rougier I suggest that you mention @anntzer's mathtext suggestion in the Alternatives sections. I would also like to see you address the question of how the html-like approach would interact with mathext. Would they be mutually exclusive? Or could one markup style occur inside another? (I suspect the former is the case.)
@NelleV, I don't see any reason not to flesh this MEP out a little bit as suggested above before merging it and discussing it on the list.

Owner

efiring commented Oct 18, 2016

@myyc, I don't think markdown is appropriate for mpl. Markdown concentrates on aspects that don't normally occur in plots (formatting blocks of text as lists, etc.), and lacks the types of style control addressed by this MEP (color, font).

Contributor

anntzer commented Oct 18, 2016

@efiring exactly nailed it: what is supposed to happen when some writes $ <span ...> $ </span>? On the other hand I like the idea of using markdown, which does allow for embedding math (at least in the pandoc dialect).

Contributor

rougier commented Oct 18, 2016 edited

@anntzer @efiring you're right. I will update the MEP with alternative and potential problems. The fact is that I did not think at all of the latex text problem and I've no idea how to handle that case.

Contributor

rougier commented Oct 18, 2016

Also, following @Kojoley comments, I need to integrate the html5lib module.

Contributor

anntzer commented Oct 18, 2016

If we decide to use html-like syntax then you should just use the stdlib's parser.

Owner

tacaswell commented Oct 19, 2016

Not sure where the right place to leave this comment is, but http://matplotlib.org/devdocs/users/annotations.html#using-complex-coordinates-with-annotations item 5 has a (I think) more robust way of doing the offset (as it will recompute the offset late).

Contributor

NelleV commented Nov 2, 2016

I am fine merging this MEP as a draft and continuing the discussion on the mailing list. Opinions?

Owner

efiring commented Nov 2, 2016

I would rather wait until @rougier has made the improvements to it that he has in mind based on the comments to date. Discussion on the mailing list can be more productive if it starts from a more complete MEP, and that is well within reach.

Contributor

rougier commented Nov 2, 2016

Hope to work on it by the end of the week.

Contributor

rougier commented Nov 4, 2016

Done.

rougier added some commits Oct 17, 2016

@rougier rougier Added markup MEP 995f8cf
@rougier rougier Added link to code 0159cb1
@rougier rougier Fix example link 5d9478a
@rougier rougier Updated MEP number 9cb29a4
@rougier rougier Added suggestions from the MEP PR comments a4ccb37
@rougier rougier Typo
bd1e273
Contributor

rougier commented Nov 4, 2016

Just rebased because of conflict with MEP28 on index.rst

@NelleV

NelleV approved these changes Nov 4, 2016

NelleV changed the title from MEP 29: Markup text to [MRG+1] MEP 29: Markup text Nov 4, 2016

efiring changed the title from [MRG+1] MEP 29: Markup text to MEP 29: Markup text Nov 5, 2016

@efiring efiring merged commit fd2e62d into matplotlib:master Nov 5, 2016

2 of 3 checks passed

continuous-integration/appveyor/pr AppVeyor build failed
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
coverage/coveralls Coverage remained the same at 61.841%
Details

QuLogic added this to the 2.1 (next point release) milestone Nov 5, 2016

QuLogic removed the needs_review label Nov 24, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment