Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Syntax highlighting broken with minted inline #113

Open
btmcnellis opened this issue Dec 7, 2016 · 8 comments
Open

Syntax highlighting broken with minted inline #113

btmcnellis opened this issue Dec 7, 2016 · 8 comments
Labels

Comments

@btmcnellis
Copy link

btmcnellis commented Dec 7, 2016

The minted package for code listings has a command mintedinline for inlining code. Syntax highlighting breaks for me when dollar signs or backticks are present in the inlined code, e.g. \mintinline{javascript}{$(".jquery-stuff")}. I suspect the issue is similar to #75 and would have a similar solution.

@Aerijo
Copy link
Collaborator

Aerijo commented Jul 17, 2017

The problem is the mintedinline command is not accounted for, so it defaults to the generic macro highlighting. This does not take arguments, so what follows is considered regular text.

Solution would be to add something along the lines of the following to the latex grammar file

{
  comment: 'inline minted support'
  match: '(\\\\)mintedinline\\{(.*?)\\}\\{(.*?)\\}'
  captures:
    0:
      name: 'whatever.strange.name.this.package.uses.latex'
    3:
      name: 'verbatim.stuff.latex'
}

Seems easy enough to do, question is if there is anybody maintaining this package @yudai-nkt ?

@yudai-nkt
Copy link
Collaborator

Yep, we currently don't provide a grammar for \mintedinline. I'll try to add grammars for this in the future.

@Aerijo
Copy link
Collaborator

Aerijo commented Sep 2, 2017

@yudai-nkt I'm working on this now, but I'm not sure what scopes to use. The general syntax for this command is as follows (taken from minted manual):

\mintinline[⟨options⟩]{⟨language⟩}⟨delim⟩⟨code⟩⟨delim⟩

The delimiters and code I would treat like verbatim, so I'm trying to match that style. It's the optional arguments, language, and overall scopes I'm not sure about. Aside from that though, the following (normal) regex seems to work well (https://regex101.com/r/U5RnJ9/1)

((\\)mintinline(?:(\[).*(\]))?((\{).*?(\}))((([^{])(.*?)(\10|$))|((\{)(.*?)(\}|$))))

First the \mintinline, then an optional pair of square brackets, then a required language selection, then either start and end with a random character, or contain it in curly braces (both work).

The other problem is bracket matching, as it allows unbalanced brackets in the optional and language scopes, but I don't think this package handles that anyway.

@natestemen
Copy link

The following example breaks the minted environment for me.

double compute (int n) {
  for (int i=0; i<n; ++i) {
    double x = Math.sqrt(i)
  }
}

If I had a semicolon at the end of the line within the for loop, then we are fine, but I shouldn't have to do this.

@Aerijo
Copy link
Collaborator

Aerijo commented Sep 8, 2017

@natestemen This issue is for minted inline, not the minted environment. If you have an issue with the minted environment, please open a new issue and give a minimum (not) working example that someone can copy and paste into Atom to immediately see the problem. As it stands, I cannot replicate your issue.

@yudai-nkt
Copy link
Collaborator

@Aerijo

as it allows unbalanced brackets in the optional and language scopes

I can't come up with a concrete example because I don't fully remember all the options in the minted package. Could you show me an example with unbalanced brackets in the optional argument? (I don't think the second argument contains brackets)

@natestemen I actually reproduced your problem but this issue is not the place to discuss yours. So please make a new issue with a reproducible LaTeX (not Java) code example if this is really a language-latex's problem. At the moment, I think this is more of a problem of the language-java package since all we can do is include the Java grammar.

@Aerijo
Copy link
Collaborator

Aerijo commented Sep 13, 2017

@yudai-nkt That was because I like to have broken things be shown by the syntax before compiling (within reason). There is no real reason to expect unbalanced brackets. However, something like

\mintinline{{python}+def minted()+

will appear fine, but will not compile because there are two opening { and only one closing one. Despite this, the simplicity probably outweighs the 'risks' in this case.

@yudai-nkt
Copy link
Collaborator

I get your point and the simplicity definitely outweighs the risks.

I have one favor to ask of you; as in the "Unification of backslash and letters in pattern matching" section in yudai-nkt/language-tex#10, I prefer \\mintinline to (\\)mintinline and I'd like you to define the grammar in the former manner if you don't disagree.


(I should export some of the issue from language-tex to here.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants