question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Is it possible to identify code block in minted?

See original GitHub issue

I am using command like \newminted{java}{linenos,frame=lines ... } , and surround my code by \begin{javacode}.

But the code in this enviroment can’t be recognized as code. It will still be influenced by LaTeX grammar check and the formatter.

I tried code injection, but IDE keeps warning and error for lack of code context and the code will still be formatted.

Is it possible to identify code block and disable grammar check for them?

Issue Analytics

  • State:open
  • Created 9 months ago
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
OharaRinneYcommented, Dec 13, 2022
\documentclass{article}
\usepackage{minted}
\newminted{python}{linenos}
\begin{document}
\begin{pythoncode}
from sklearn.neighbors import KNeighborsClassifier

neighbours = np.arange(1, 9)
train_accuracy = np.empty(len(neighbours))
test_accuracy = np.empty(len(neighbours))

for i, k in enumerate(neighbours):
    knn = KNeighborsClassifier(n_neighbors=k)
    knn.fit(X_train, y_train)
    train_accuracy[i] = knn.score(X_train, y_train)
    test_accuracy[i] = knn.score(X_test, y_test)
\end{pythoncode}
\end{document}

compile with xelatex -shell-escape test.tex and python package Pygments installed.

An introduction for this package can be found here

0reactions
PHPiratescommented, Dec 13, 2022

Language injection itself should be easy to do generically, @jojo2357 if you want to help: all LatexLanguageInjector has to do is search for \newminted commands, take the argument and assume it’s the language to be injected.

However, treating the code as verbatim and not LaTeX depending on whether it is defined with \newminted or not is not possible with the lexer we have, so all we can do is as you suggest if the environment name contains code assume it is code. I’m afraid this will lead to very inconvenient false positives though as there are likely environments with “code” in the name which just contain LaTeX. We can check the default TeX Live ones I could find, otherwise maybe we should stick to a few known languages. image

Read more comments on GitHub >

github_iconTop Results From Across the Web

Is it possible to identify code block in minted? - PullAnswer
I tried code injection, but IDE keeps warning and error for lack of code context and the code will still be formatted. Is...
Read more >
Is it possible to find methods in source code using \inputminted?
Show activity on this post. Yes, this is nice :). If there were something like this in minted ...
Read more >
Code Highlighting with minted - Overleaf, Online LaTeX Editor
This article shows how to use the minted package to format and highlight programming language source code within a LaTeX document, starting with...
Read more >
The minted package: Highlighted source code in LaTeX - CTAN
minted provides the listing environment to wrap around a source code block. listing (env.) This puts the code into a floating box, with...
Read more >
Support minted in addition to listings for code block in latex?
Since the listings package support just a few languages, tt would be nice if the latex writer can output code blocks with the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found