From a3d91b5b5cd611845a26e27d1a10d1e06ab5531d Mon Sep 17 00:00:00 2001 From: Andrew Lorimer Date: Fri, 5 Apr 2019 22:00:25 +1100 Subject: [PATCH] pandoc filters and xcursor_theme --- atom/.atom/config.cson | 3 +- i3/.i3/config | 7 +++-- pandoc/.pandoc/filters/chem.py | 50 ++++++++++++++++++++++++++++++++++ x/.Xresources | 2 ++ x/.xinitrc | 1 + 5 files changed, 58 insertions(+), 5 deletions(-) create mode 100755 pandoc/.pandoc/filters/chem.py create mode 100644 x/.Xresources diff --git a/atom/.atom/config.cson b/atom/.atom/config.cson index 1fccd41..2ba054e 100644 --- a/atom/.atom/config.cson +++ b/atom/.atom/config.cson @@ -42,9 +42,8 @@ "--standalone" ] pandocBibliography: true - pandocMarkdownFlavor: "markdown-latex_macros" pandocFilters: [ - "/home/andrew/.pandoc/filters/pandoc-chem-struct.py" + "/home/andrew/.pandoc/filters/chem.py" ] pandocMarkdownFlavor: "markdown+latex_macros+raw_tex" pandocRemoveReferences: false diff --git a/i3/.i3/config b/i3/.i3/config index c555ef3..e942b44 100644 --- a/i3/.i3/config +++ b/i3/.i3/config @@ -213,9 +213,10 @@ gaps inner 15 gaps outer 0 # startup scripts -exec_always xrandr --output HDMI-0 --pos 0x0 --output DVI-D-0 --pos 240x1080 -exec_always feh --bg-fill /home/andrew/.wallpaper.png -exec_always compton -f -b --config /home/andrew/.compton.conf +exec_always --no-startup-id xrdb /home/andrew/.Xdefaults +exec_always --no-startup-id xrandr --output HDMI-0 --pos 0x0 --output DVI-D-0 --pos 240x1080 +exec_always --no-startup-id feh --bg-fill /home/andrew/.wallpaper.png +exec_always --no-startup-id compton -f -b --config /home/andrew/.compton.conf exec --no-startup-id chromium exec --no-startup-id spotify diff --git a/pandoc/.pandoc/filters/chem.py b/pandoc/.pandoc/filters/chem.py new file mode 100755 index 0000000..b2106a2 --- /dev/null +++ b/pandoc/.pandoc/filters/chem.py @@ -0,0 +1,50 @@ +#! /usr/bin/env python3 +"""Pandoc filter to format simple chemical structures. + +Structures specified as in s:{CH3CH2O-}, s:{SO4^2-} +are converted to formatted structures such as CH~3~CH~2~OH^-^, +SO~4~^2−^. + +""" + +from pandocfilters import toJSONFilter, Str, Subscript, Superscript +import re + +# Pattern for structures in md. +ID_PAT = re.compile('(.*)ce\{(.*)\}(.*)') +# Used to identify charges at end of formula. +CHARGE_PAT = re.compile('(\w*)\^?([0-9]*[-–−+])') + +def chem_struct (key, val, fmt, meta): + if key == 'Str' and ID_PAT.match(val): + # Store punctuation after formula in end. + start, raw_formula, end = ID_PAT.match(val).groups() + + if CHARGE_PAT.match(raw_formula): + formula, charge = CHARGE_PAT.match(raw_formula).groups() + # Replace hyphen with minus sign + charge = charge.replace('-', '−') + else: + formula, charge = raw_formula, None + + formatted_formula = [] + + for d in formula: + if d.isdigit(): + formatted_formula.append(Subscript([Str(d)])) + else: + formatted_formula.append(Str(d)) + + if charge: + formatted_charge = [Superscript([Str(charge)])] + else: + formatted_charge = [] + + formatted_start = [Str(start)] + formatted_end = [Str(end)] + + return formatted_start + formatted_formula + formatted_charge \ + + formatted_end + +if __name__ == '__main__': + toJSONFilter(chem_struct) diff --git a/x/.Xresources b/x/.Xresources new file mode 100644 index 0000000..0562568 --- /dev/null +++ b/x/.Xresources @@ -0,0 +1,2 @@ +Xcursor.theme: Neutral +Xcursor.size: 12 diff --git a/x/.xinitrc b/x/.xinitrc index 0943044..28932c9 100644 --- a/x/.xinitrc +++ b/x/.xinitrc @@ -1,3 +1,4 @@ #! /bin/bash +xrdb -merge /home/andrew/.Xresources exec i3 -- 2.49.0