-
Notifications
You must be signed in to change notification settings - Fork 39
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
Emulate github syntax highlighting? #54
Comments
This is what the same code looks like in my latex: I'm using \usepackage[charsperline = 80,
autoload = true,
defaultmonofont = false,
linenumbers = true,
theme = default]{jlcode}
\definecolor{light-gray}{gray}{0.98}
\lstset{language = Julia,
captionpos = b
basicstyle = \ttfamily,
keywordstyle = \footnotestyle\ttfamily\bfseries\color{MidnightBlue},
stringstyle = \footnotestyle\ttfamily,
backgroundcolor = \color{light-gray},
commentstyle = \footnotestyle\ttfamily\color{Maroon}} (if that matters) |
Well, I guess the best idea would be to create your own color sheme. It should not be to difficult to do that, just look at the existing ones, see for example https://github.com/wg030/jlcode/blob/master/jlcode.sty#L463-L483 |
Thank you, that is very helpful! I see the default theme does not distinguish between "base" and functions, eg Lines 416 to 430 in 9cce985
Now I understand that I can use the custom keywords with \lstset{keywordstyle = {[5]\color{Blue}}} which I inferred from this: Lines 528 to 542 in 9cce985
Something that seems to be the case (empirically, just from working with it), is that github (or vim) does not simply highlight code based on "tokens", but is rather able to understand how it is used. For example the keyword Is this possible with listings (or latex) --- which for example would also allow me to highlight non-julia functions --- anything that has the form Either way this is great, I think I am going to be able to achieve what I need at the end of the day one way or another. |
Does this code: Lines 836 to 842 in 9cce985
mean that we need to define new themes to change colors, rather than using |
Yes, the jlcode package was designed in such a way that you would only need to add a new theme and then load it as described in the manual if you wanted to have different colors. Having that this, instead of doing something like
you would only need to set
Yes, github and vim or other code editors are usually way smarter in recognizing code patterns. The detection in listings, which jlcode is completely based on, is rather simple compared to modern code highlighting.
Hence something similiar is definitiley not possible with the listings respectively the jlcode package and you could only manually adjust here unfortuantely. I haven't looked for alternatives for years now so that I don't know if somebody has meanwhile come up with a smarter solution than listings as far as code lighting is concerned. |
Ok, great!
This makes sense and thank you for the detailed response! For a paper, its not that crazy to simply write out the extra package-specific functions that we need highlighted anyways. |
I would like to know if it's possible to emulate github's syntax highlighting, which highlights both functions and literals. For example:
from Oceananigans README.
I'm willing to make a contribution to
jlcode.sty
to achieve this (if its needed, and if its possible) but might need tips.The text was updated successfully, but these errors were encountered: