Skip to content

Commit

Permalink
latex-like completions (Julia) (#13)
Browse files Browse the repository at this point in the history
* add julia (latex-like) completions

* support for multiple indices and exponents

* add julia.html
  • Loading branch information
MarcMush authored Aug 18, 2021
1 parent 6824782 commit ec54a78
Show file tree
Hide file tree
Showing 5 changed files with 139 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
<a href="https://abrudz.github.io/lb/brachylog"><kbd>Brachylog</kbd></a>
<a href="https://abrudz.github.io/lb/husk"><kbd>Husk</button></a>
<a href="https://abrudz.github.io/lb/jelly"><kbd>Jelly</kbd></a>
<a href="https://abrudz.github.io/lb/julia"><kbd>Julia</kbd></a>
<a href="https://abrudz.github.io/lb/vyxal"><kbd>Vyxal</kbd></a>

This provides up to three ways to easily enter the special characters of a programming language into pretty much any input field on any webpage.
Expand Down
1 change: 1 addition & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ <h1>
<a href="https://abrudz.github.io/lb/brachylog"><button>Brachylog</button></a>
<a href="https://abrudz.github.io/lb/husk"><button>Husk</button></a>
<a href="https://abrudz.github.io/lb/jelly"><button>Jelly</button></a>
<a href="https://abrudz.github.io/lb/jelly"><button>Julia</button></a>
<a href="https://abrudz.github.io/lb/vyxal"><button>Vyxal</button></a>
<a href="https://github.com/sponsors/abrudz" style="text-decoration: none; color: #ea4aaa; float: right;"
title="Sponsor"></a>
Expand Down
38 changes: 38 additions & 0 deletions julia.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<!doctype html>
<html>
<head>
<meta charset=utf-8><title>Julia</title>
<style>kbd{border: 1px solid buttonshadow;border-radius:.5ex;padding:0 .25ex;margin:0 .2ex;background:buttonface;}</style>
</head>
<body>
<article>
<h1><a href="https://julialang.org/">Julia</a> language bar and character compositions <a href="."><button>More…</button></a></h1>
<p>This provides two ways to easily enter Julia characters into pretty much any input field on any webpage:</p>
<ol>
<li>Enter a combo sequence and hit Tab, e.g. <kbd>\</kbd><kbd>p</kbd><kbd>i</kbd><kbd>Tab</kbd> gives <code>π</code>. See the <a href="https://docs.julialang.org/en/v1/manual/unicode-input/">complete list of completions</a>.</li>
<li>Click on symbols in the language bar.</li>
</ol>
<p>Try it here: <input autofocus/></p>
<p>Hover over a symbol in the language bar for combo sequences.</p>
<h2>Installation</h2>
<h3>Desktop browser</h3>
<ol>
<li>Drag this link to your bookmarks bar: <a href='javascript:(d=>{let e=d.createElement("script");e.src="https://abrudz.github.io/lb/julia.js";d.body.appendChild(e)})(document)'>Julia</a></li>
</ol>
<h3>Mobile browser</h3>
<ol>
<li>Add a bookmark for this page.</li>
<li>Edit the bookmark's target URL address to <code>javascript:(d=&gt;{let%20e=d.createElement("script");e.src="https://abrudz.github.io/lb/julia.js";d.body.appendChild(e)})(document)</code></li>
</ol>
<h3>Webpage</h3>
<ol>
<li>Include this HTML in your page: <code>&lt;script src="https://abrudz.github.io/lb/julia.js">&lt;/script></code></li>
</ol>
<h2>Activation</h2>
<ol>
<li>Navigate to the web page where you want to enter Julia characters.</li>
<li>Click on the <em>Julia</em> bookmark. The language bar should appear at the web page's top.</li>
</ol>
</article>
<script src="https://abrudz.github.io/lb/julia.js"></script>
</html>
35 changes: 35 additions & 0 deletions julia.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
using REPL

lbs = String[]
tc = Tuple{String,String}[]
for (a,b) in REPL.REPLCompletions.latex_symbols
push!(tc, (a[2:end],b))
bs=Symbol(b)
if isdefined(Main,bs)
be=string(eval(bs))
push!(lbs, b^2*"\n$be"^(beb))
end
end

lbs = sort(unique(lbs))
tc = sort(tc, by=x->(length(x[1]),x))
tcf = first.(tc)
tcc = join(tcf) |> unique |> sort |> join |> x->replace(x, ["\$()*+-./?[\\]^{|}"...]=>x->'\\'*x) |> x-> "/\\\\([$x]+)\$/"
tcu = filter(i->!isnothing(match(r"^\^.$",i)), tcf) .|> last |> sort |> join |> x->replace(x, ["\$()*+-./?[\\]^{|}"...]=>x->'\\'*x) |> x-> "/\\\\\\^([$x]+)\$/"
tcl = filter(i->!isnothing(match(r"^_.$",i)), tcf) .|> last |> sort |> join |> x->replace(x, ["\$()*+-./?[\\]^{|}"...]=>x->'\\'*x) |> x-> "/\\\\_([$x]+)\$/"

slbs = '['*join(repr.(lbs),',')*']'
stc = '{'*join(tc.|>x->join(repr.(x),':'),',')*'}'

out = """
, lbs = $slbs
, tc = $stc
, tcc = $tcc
, tcl = $tcl
, tcu = $tcu
"""
try
clipboard(out)
catch
print(out)
end
64 changes: 64 additions & 0 deletions julia.js

Large diffs are not rendered by default.

0 comments on commit ec54a78

Please sign in to comment.