Skip to content

Strings containing TeX are now rendered as format strings #5

Closed

Description

@eric-wieser

Eg matplotlib's labels:

ax1.set(ylabel=R'$\frac{m_{j \rightarrow i}(\mathrm{good})}{\sum{m_{j \rightarrow i}}}$')

Maybe look for $-surrounded strings and apply TeX to them?

Activity

  1. 1st1 commented on Oct 20, 2015

    @1st1
    Member

    This is a consequence of us trying to highlight new formatting '{foo}'.format(foo=1), which is quite a common use-case. I'm a little uncomfortable to highlight everything between $ signs as TeX, as $ are quite popular in various templates, and this can potentially cause a lot of false-positives.

    More importantly, switching language contexts (at least in Atom) opens possibilities of bigger highlighting failures. I.e. if you have an unclosed { bracket, the TeX syntax won't end where your Python string ends, likely resulting in the rest of the file highlighted incorrectly.

  2. eric-wieser commented on Oct 20, 2015

    @eric-wieser
    Author

    Perhaps formatting syntax should be only enabled if .format (no parens) follows the string?

  3. DanielOaks commented on Oct 20, 2015

    @DanielOaks

    I'll commonly define a format string on one line and then have the .format on a different line, either due to line lengths or to bunching up all the output strings in one place in the file / project. I think it makes sense to use the formatting syntax even when .format doesn't follow the string.

  4. vpetrovykh commented on Oct 20, 2015

    @vpetrovykh
    Contributor

    Please see my explanation for this issue. All the problems listed there are relevant for this case as well.
    I will be fixing the incorrect highlighting of nested braces, though. This should reduce the amount of visual noise, but it is a little trickier than it sounds since there are ways to legally nest braces in python formatting ('text {0:{fill}{align}16} text') that we currently highlight.

  5. vpetrovykh commented on Oct 21, 2015

    @vpetrovykh
    Contributor

    @eric-wieser
    Although the highlighter will not switch to TeX syntax within the string, it should no longer generate visual noise in this use case. I've fixed the way we highlight illegal formatting in v0.4.28 (should be updated in Package Control in a bit). The rule of thumb is that once we detect that the format string uses illegal {} syntax, we ignore that type of formatting for the rest of the string (this works in multiline strings too). I'll write more on the motivation in #12.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions