From 3e19940e71bca5696fc71689436463534dcba89a Mon Sep 17 00:00:00 2001 From: j4nk Date: Wed, 4 Jan 2023 14:57:27 -0500 Subject: [PATCH] Added ability to add LaTeX --- md4tj_parse.el | 17 ++++++++++++++++- test_css.css | 8 ++++++++ test_file.html | 3 ++- test_file.md4tj | 1 + 4 files changed, 27 insertions(+), 2 deletions(-) diff --git a/md4tj_parse.el b/md4tj_parse.el index 94f431a..87c2e1f 100644 --- a/md4tj_parse.el +++ b/md4tj_parse.el @@ -91,6 +91,19 @@ (md4tj-begin-tag "p" (list (list "id" "lastupdated"))) "Last updated: " (current-time-string) (md4tj-end-tag "p"))) + ((and (string-match "^$$.*$$" line) (eq (nth 1 state) 'normal)) ;; LaTeX formula + (shell-command (concat "./pnglatex" + " -d 300" + " -f " + "\"" + (string-replace "$$" "" line) + "\"" + " -o " + "./teximg/" + (md5 (string-replace "$$" "" line)) ".png")) + (md4tj-begin-tag "img" (list (list "class" "teximg") ;; give teximgs their own class + (list "src" (concat "./teximg/" (md5 (string-replace "$$" "" line)) ".png")) + (list "alt" (string-replace "$$" "" line))))) ;; If this is some other signal, ignore ((string-match "^@@" line) "") ;; Otherwise, process as normal @@ -146,7 +159,9 @@ (t 'normal)))) (defun md4tj-begin () - "Insert beginning code for all html." + "Insert beginning code for all html, initialize." + (shell-command "mkdir -p ./teximg") ;; Ensure ./teximg folder exists + (shell-command "rm ./teximg/*") ;; Clear everything from the folder (concat "\n" (md4tj-begin-tag "html" (list (list "lang" diff --git a/test_css.css b/test_css.css index bcbac00..8c42a07 100644 --- a/test_css.css +++ b/test_css.css @@ -9,3 +9,11 @@ video { outline: dashed 1px black; text-align: center; } + +.teximg { + display: block; + margin-left: auto; + margin-right: auto; + width: 5%; + height: auto; +} diff --git a/test_file.html b/test_file.html index b40edf2..825aa30 100644 --- a/test_file.html +++ b/test_file.html @@ -70,6 +70,7 @@ int main() {

Dungeon Crawl Stone Soup - My favorite FOSS roguelike (Yes, I know the greatest roguelike of all time is NetHack, I don't care).

-

Last updated: Wed Jan 4 13:40:47 2023

+e^{i \pi} + 1 = 0 +

Last updated: Wed Jan 4 14:56:23 2023

\ No newline at end of file diff --git a/test_file.md4tj b/test_file.md4tj index 82ed7a4..419d58c 100644 --- a/test_file.md4tj +++ b/test_file.md4tj @@ -25,4 +25,5 @@ int main() { } ``` [Dungeon Crawl Stone Soup](https://crawl.develz.org) - My favorite FOSS roguelike (Yes, I know the greatest roguelike of all time is NetHack, I don't care). +$$e^{i \pi} + 1 = 0$$ @@LASTUPDATED \ No newline at end of file