-
Notifications
You must be signed in to change notification settings - Fork 0
/
example.tex
88 lines (64 loc) · 2.45 KB
/
example.tex
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
\documentclass{article}
\usepackage{hilite}
% an example of using hilite with mdframed or similar
\usepackage{mdframed}
% first, configure shellout. we need to provide a cache prefix, and a path to
% the shell script helper (yeah i know, tex libraries can't find their own feet
% without currfile hacks)
\shelloutcacheprefix{shellout/\jobname}
\shelloutnocachemode
\shelloutbin{./shellout.sh}
% select a theme. this enables use of the \hilitepalette command to select
% colours from the palette, as well as defining the RG@fgcolor and RG@bgcolor
% colour variables.
\hilitestyle{magritte}
\makeatletter
\newmdenv[
middlelinecolor=RG@fgcolor
middlelinewidth=0.75pt,
font=\ttfamily,
rightmargin=8pt,
shadowsize=4pt,
backgroundcolor=RG@bgcolor,
]{myexample}
\makeatother
% add surrounding commands to the hilite block environment. here we use
% this command to make every hilite block be our custom mdframed box.
\hiliteblockenv{\begin{myexample}}{\end{myexample}}
% similar but for inline highlights
\hiliteinlineenv{\ttfamily}{\relax}
% OPTIONAL: override the rouge command to load custom lexers, themes, etc
% \hiliterougecmd{rougify -r ./ruby/my_extensions.rb}
\hiliterougecmd{rougify}
% OPTIONAL: set a default language for {hilite} environments
\hilitedefaultlang{text}
% access any rouge palette colour using `RG@palette@magritte@palettename
\def\RGP#1{RG@palette@magritte@#1}
\begin{document}
%%%%%%%%% UTIL %%%%%%%%%
\def\withcursor#1{\texttt{\textbf{%
\fboxsep=0pt\colorbox{gray}{%
\parbox[c][\height][c]{0.61em}{%
\strut\textcolor{white}{#1}%
}%
}}%
}}
\def\cursormark{\withcursor{}}
\def\prompt{\textasciitilde>}
\title{Demo of text highlighting}
\author{jneen}
\maketitle
\noindent Hello! Here is some highlighted code:
\begin{hilite}[ruby]
# yo this is ruby
Rouge.highlight('LaTeX') # not real syntax lol
puts "completely \" backslash \safe" # \\\\\\\\\
puts "embedded <@\LaTeX@>"
\end{hilite}
\noindent And you can also \hl[ruby]/puts "your highlighted code"/ inline! While this does depend on the \hl|-shell-escape| flag (and therefore is not usable on platforms like Overleaf where shelling out is not an option), we do generate cache files, so that TeX sources can be distributed without relying on \hl|-shell-escape|.
See \hl|example.tex| for more info, or run \hl|make| in this repository to make the example.
Backslash safe with embedding example:
\begin{hilite}[tex]
\LaTeX is how you make <@\LaTeX@> in LaTeX.
\end{hilite}
\end{document}