pandoc filters and xcursor_theme
authorAndrew Lorimer <andrew@lorimer.id.au>
Fri, 5 Apr 2019 11:00:25 +0000 (22:00 +1100)
committerAndrew Lorimer <andrew@lorimer.id.au>
Fri, 5 Apr 2019 11:00:25 +0000 (22:00 +1100)
atom/.atom/config.cson
i3/.i3/config
pandoc/.pandoc/filters/chem.py [new file with mode: 0755]
x/.Xresources [new file with mode: 0644]
x/.xinitrc
index 1fccd41951564496a7ac97d7058e455f8a97bd0b..2ba054ea9e489add03ba6986ef95bfd398ef06e5 100644 (file)
@@ -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
index c555ef33bd8f8d6af9f7305c8d8cff8e4458ac11..e942b44a84444e7e37074344b5ee352f8ac139b1 100644 (file)
@@ -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 (executable)
index 0000000..b2106a2
--- /dev/null
@@ -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 (file)
index 0000000..0562568
--- /dev/null
@@ -0,0 +1,2 @@
+Xcursor.theme: Neutral
+Xcursor.size: 12
index 0943044faa10210575cd4711d566ba1f74fa9994..28932c943de3af3e6d0f886cbd2bd8c471025985 100644 (file)
@@ -1,3 +1,4 @@
 #! /bin/bash
 
+xrdb -merge /home/andrew/.Xresources
 exec i3