Skip to main content

No project description provided

Project description

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
}

example0.PNG

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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

gkdhighlight-0.2.1-py3-none-any.whl (6.2 kB view details)

Uploaded Python 3

File details

Details for the file gkdhighlight-0.2.1-py3-none-any.whl.

File metadata

  • Download URL: gkdhighlight-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 6.2 kB
  • Tags: Python 3
  • Uploaded using 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

File hashes

Hashes for gkdhighlight-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 30aa24658b06043f43bb79a897cd79411af776e857b08cddedd6a772d83c731e
MD5 fbb0322d5c9164785c9ff5d72fb7b3af
BLAKE2b-256 7d0159bea52a31e7d4d247cfac6ffad87b28200fa73a7d732b53368da24b2ef5

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page