Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dvisvgm support #497

Merged
merged 6 commits into from
Jan 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 38 additions & 2 deletions ox-blackfriday.el
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,11 @@ Note that this variable is *only* for internal use.")
(figure . "Figure")) ;Note that `figure' is not an actual Org element
"Alist of strings used to represent various Org elements.")

(defvar org-blackfriday--ltximg-directory "ltximg/"
"Sub directory created inside the site's static directory for LaTeX images.

This sub directory is created when an export option like
`tex:dvisvgm' is used.")


;;; User-Configurable Variables
Expand Down Expand Up @@ -798,6 +803,35 @@ exported instead:
(org-trim (replace-regexp-in-string "^" " " contents))))))))

;;;; Latex Environment
(defun org-blackfriday--update-ltximg-path (html-str)
"Update the path to latex exported images directory.

For example, this function converts

<img src=\"foo/bar/xyz.svg\" ..

to

<img src=\"/ltximg/xyz.svg\" ..

where \"ltximg/\" is the default value of
`org-blackfriday--ltximg-directory'.

Return the updated HTML string."
;; (message "dbg html-str: %S" html-str)
(if (and (stringp html-str)
(string-match "\\(.*?<img src=\"\\)\\([^\"]+\\)\\(\"\\(.\\|\n\\)*\\)" html-str))
(let ((updated-img-path (format "/%s%s"
org-blackfriday--ltximg-directory
(file-name-nondirectory
(match-string-no-properties 2 html-str)))))
;; (message "dbg updated-img-path: %S" updated-img-path)
(format "%s%s%s"
(match-string-no-properties 1 html-str)
updated-img-path
(match-string-no-properties 3 html-str)))
html-str))

(defun org-blackfriday-latex-environment (latex-environment _contents info)
"Transcode a LATEX-ENVIRONMENT object into Blackfriday Markdown format.
INFO is a plist holding contextual information."
Expand All @@ -813,7 +847,8 @@ INFO is a plist holding contextual information."
;; (message "[ox-bf-latex-env DBG] env: %s" env)
env))
(t
(org-html-latex-environment latex-environment nil info)))))
(org-blackfriday--update-ltximg-path
(org-html-latex-environment latex-environment nil info))))))

;;;; Latex Fragment
(defun org-blackfriday-latex-fragment (latex-fragment _contents info)
Expand All @@ -828,7 +863,8 @@ INFO is a plist holding contextual information."
;; (message "[ox-bf-latex-frag DBG] frag: %s" frag)
frag))
(t
(org-html-latex-fragment latex-fragment nil info)))))
(org-blackfriday--update-ltximg-path
(org-html-latex-fragment latex-fragment nil info))))))

;;;; Plain List
(defun org-blackfriday-plain-list (plain-list contents info)
Expand Down
21 changes: 19 additions & 2 deletions ox-hugo.el
Original file line number Diff line number Diff line change
Expand Up @@ -2425,7 +2425,7 @@ and rewrite link paths to make blogging more seamless."
""))))

;;;;; Helpers
(defun org-hugo--maybe-copy-resources (info)
(defun org-hugo--copy-resources-maybe (info)
"Copy resources to the bundle directory if needed.

INFO is a plist used as a communication channel."
Expand All @@ -2451,6 +2451,22 @@ INFO is a plist used as a communication channel."
(message "[ox-hugo] Copied resource %S to %S" src-path dest-path)
(copy-file src-path dest-path :ok-if-already-exists)))))))))))))

(defun org-hugo--copy-ltximg-maybe (info)
"Copy `org-preview-latex-image-directory' contents into site's ltximg directory.

INFO is a plist used as a communication channel."
(when (file-exists-p org-preview-latex-image-directory)
(let* ((hugo-base-dir (file-name-as-directory (plist-get info :hugo-base-dir)))
(static-ltximg-dir (file-truename
(file-name-as-directory
(expand-file-name
org-blackfriday--ltximg-directory
(expand-file-name "static" hugo-base-dir))))))
(copy-directory org-preview-latex-image-directory static-ltximg-dir
nil :parents :copy-contents)
(message "[ox-hugo] Copied contents of %S into %S"
org-preview-latex-image-directory static-ltximg-dir))))

(defun org-hugo--attachment-rewrite-maybe (path info)
"Copy local images and pdfs to the static/bundle directory if needed.
Also update the link paths to match those.
Expand Down Expand Up @@ -2929,7 +2945,8 @@ INFO is a plist holding export options."
BODY is the result of the export.
INFO is a plist holding export options."
;; Copy the page resources to the bundle directory.
(org-hugo--maybe-copy-resources info)
(org-hugo--copy-resources-maybe info)
(org-hugo--copy-ltximg-maybe info)
;; (message "[ox-hugo body filter] ITEM %S" (org-entry-get (point) "ITEM"))
;; (message "[ox-hugo body filter] TAGS: %S" (org-entry-get (point) "TAGS"))
;; (message "[ox-hugo body filter] ALLTAGS: %S" (org-entry-get (point) "ALLTAGS"))
Expand Down
21 changes: 21 additions & 0 deletions test/site/content-org/all-posts.org
Original file line number Diff line number Diff line change
Expand Up @@ -3521,7 +3521,28 @@ spacing:
\[a\;b\]
\[a\:b\]
\[a\!b\]
** Equations exported to SVG (dvisvgm) :dvisvgm:dont_export_during_make_test:
:PROPERTIES:
:EXPORT_FILE_NAME: equations-exported-to-svg
:EXPORT_OPTIONS: tex:dvisvgm
:END:
#+begin_description
Exporting {{{latex}}} equations as SVG images.
#+end_description
{{{oxhugoissue(327)}}}

Example of an inline equation: \[ a + b \]

Example of a block equation:

\begin{equation}
C = W\log_{2} (1+\mathrm{SNR})
\end{equation}

#+begin_note
Referencing to equation labels does not work when {{{latex}}}
equations are exported as images.
#+end_note
* Lists :lists:
** List following a list
:PROPERTIES:
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading