GkdHighlight
GKD, i.e., 搞快点, means "(please) do it faster", which is an old saying in China.
Backgroud, Installation and CLI
click and see
100 trillion words omitted here,
let us present gkdhighlight.
It's a syntax highlighting library via GkdTeX,
which is a programmable TeX compiles to LaTeX.
No LaTeX dependencies other than xcolor and asmmath,
no shell-escape,
no package conflicts, but—
only normal paragraphs generated and coloured,
you place it in tabular, in commands—
Oh, composability! Reusability!
The strong PTSD against its alternatives eventually fades.
—but anyway, now,
pip install pygments gkdtex gkdhighlight within 0.5 seconds,
gkdtex main.tex --out_file main.out.tex within 0.5 seconds,
latexmk -pdf main.out.tex within 10 seconds—
faster typesetting and compilation,
longer sleep,
the joy of reasonable programming,
hope your paper got accepted.
Preview
\gkd@usepackage{gkdhighlight}
\begin{document}
...
\gkd@highlight{ocaml}{
module FM = Functor(M)
let res = print_endline FM.message
}
\gkd@loadpygments{colorful}
\gkd@highlight{python}{
class S:
def f(self, x):
return print(1 + x)
}
\gkd@loadpygments{perldoc}
\gkd@highlight{haskell}{
data NAT repr = NAT { Z :: repr, S :: repr -> repr }
data Nat
= Z
| S Nat
}
Writing Your Own Stylers
In the configuration directory of gkdtex(specified by gkdtex --config_dir <xxx>; default to be the directory you call gkdtex),
add the following code to your .gkdrc.py.
from pygments.style import Style
from pygments import token
def pygments_monkeypatch_style(mod_name, cls):
import sys
import pygments.styles
cls_name = cls.__name__
mod = type(__import__("os"))(mod_name)
setattr(mod, cls_name, cls)
setattr(pygments.styles, mod_name, mod)
sys.modules["pygments.styles." + mod_name] = mod
from pygments.styles import STYLE_MAP
STYLE_MAP[mod_name] = mod_name + "::" + cls_name
class YourStyler(Style):
background_color = "#FFFFAA"
styles = {
token.Text: "#AA3939",
token.String: "#479030",
token.Keyword: "#A600A6",
token.Operator: "#246C60",
token.Number: "#779D34",
token.Comment: "#AA6F39",
token.Punctuation: "#DE369D",
token.Literal: "#4671D5",
}
pygments_monkeypatch_style("you_gkd_please", YourStyler)
Then load it in gkdtex.
\gkd@loadpygments{you_gkd_please}
Writing Your Own Lexers
Write this in your .gkdrc.py.
from pygments.lexer import RegexLexer
from sphinx.highlighting import lexers
keywords = ['lAtEx']
class YourLexer(RegexLexer):
name = "your_lang"
tokens = {
"root": [
*[(escape(k), token.Keyword) for k in keywords],
(r"[a-zA-Z_][a-zA-Z_]*", token.Name),
(r"\s+", token.Whitespace)
]
}
lexers[YourLexer.name] = YourLexer(startinline=True)
Then use it in gkdtex.
\gkd@highlight{your_lang}{ lAtEx is so cool! }
Miscellaneous
Many popular Python distributions are addicted to providing broken pygments in their bundles.
I've appreciated it a lot and you need to reinstall pygments again in order to use alternatives to gkdhighlight.
Unfortunately, gkdhighlight just works if you have Python 3.6+ installed.
Metadata
Release files for gkdhighlight 0.2.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| gkdhighlight-0.2.1-py3-none-any.whl | Python 3 | none | any | Details |
Release files / gkdhighlight-0.2.1-py3-none-any.whl
| Download URL | gkdhighlight-0.2.1-py3-none-any.whl |
|---|---|
| Size | 6.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
30aa24658b06043f43bb79a897cd79411af776e857b08cddedd6a772d83c731e
|
|
BLAKE2b-256 checksum How to use checksums |
7d0159bea52a31e7d4d247cfac6ffad87b28200fa73a7d732b53368da24b2ef5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.2.0.post20200714 requests-toolbelt/0.9.1 tqdm/4.47.0 CPython/3.8.3
|