-
Notifications
You must be signed in to change notification settings - Fork 16
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
defblock fails to export output when using latex derived backend #12
Comments
I encounter a similar problem when exporting with ox-gfm. My guess is that |
The same when exporting to epub with I've tried with (advice-add 'org-hmtl-special-block :around
(lambda (f &rest r)
(let ((org-export-current-backend 'html))
(apply 'f r)))) but nothing changed. |
Finally I found a temporay fix to convert all epub exports to html ones: (add-to-list 'org-export-filter-parse-tree-functions
(lambda (tree backend info)
(when (eq backend 'epub)
(org-element-map tree 'export-block
(lambda (el)
(when (string= (org-element-property :type el) "EPUB")
(org-element-put-property el :type "HTML")))))
tree)) |
Hey @arongile, adopting @DPDmancul's approach, we have a solution 😉
(defun ospe-add-support-for-derived-backend (new-backend parent-backend)
"See subsequent snippet for a working example use."
(add-to-list 'org-export-filter-parse-tree-functions
`(lambda (tree backend info)
(when (eq backend (quote ,new-backend))
(org-element-map tree 'export-block
(lambda (el)
(when (string= (org-element-property :type el) (s-upcase (symbol-name (quote ,new-backend))))
(org-element-put-property el :type (s-upcase (symbol-name (quote ,parent-backend))))))))
tree)))
;; “C-x C-e” at the end to see an example of support for derived modes.
(-let [new-backend 'super-duper-new-derived-backend]
;; Register new backend
(org-export-define-derived-backend new-backend 'latex)
(ospe-add-support-for-derived-backend new-backend 'latex)
;; Register new special block
(o-defblock amyblock nil nil
"Place a ‘✓’ before contents when doing latex derived backend exports."
(if ;; ≈ (or (equal backend 'latex) (equal backend new-backend) ⋯)
(org-export-derived-backend-p backend 'latex)
(format "✓ %s" raw-contents)
raw-contents))
;; Do an example export
(with-temp-buffer
(insert (s-join "\n" '("#+begin_amyblock"
"It worked!"
"#+end_amyblock")))
;; (org-export-to-buffer 'html "*Export Result Buffer*" nil nil t t) ;; No “✓”
(org-export-to-buffer new-backend "*Export Result Buffer*" nil nil t t) ;; Yes “✓”
)) However, I don't know enough about derived backends to explain why this is needed. Perhaps @DPDmancul can provide more insight 🙏 @sopoforic, this solution also works for ox-gfm 😲 ;; “C-x C-e” at the end to see an example of support for ox-gfm
(progn
;; Register new backend
(ospe-add-support-for-derived-backend 'gfm 'html)
;; Register new special block
(o-defblock nice (𝒏 "1") nil
"Place 𝒏-many ‘✓’ before contents when doing latex derived backend exports."
(if ;; ≈ (or (equal backend 'latex) (equal backend new-backend) ⋯)
(org-export-derived-backend-p backend 'html)
(format "%s %s" (s-repeat (string-to-number 𝒏) "✓") raw-contents)
raw-contents))
;; Do an example export
(with-temp-buffer
(insert (s-join "\n" '("#+begin_nice 3"
"It worked!"
"#+end_nice")))
(org-export-to-buffer 'gfm "*Export Result Buffer*" nil nil t t))) Aslo @authsec, and @kaushalmodi of #21, this solution also works for ox-hugo 😲 Notice that block arguments also work as expected 🥳 ;; “C-x C-e” at the end to see an example of support for ox-hugo
(progn
;; Register new backend
(ospe-add-support-for-derived-backend 'hugo 'html)
;; Register new special block
(o-defblock nice (𝒏 "1") nil
"Place 𝒏-many ‘✓’ before contents when doing latex derived backend exports."
(if ;; ≈ (or (equal backend 'latex) (equal backend new-backend) ⋯)
(org-export-derived-backend-p backend 'html)
(format "%s %s" (s-repeat (string-to-number 𝒏) "✓") raw-contents)
raw-contents))
;; Do an example export
(with-temp-buffer
(insert (s-join "\n" '("#+begin_nice 3"
"It worked!"
"#+end_nice")))
(org-export-to-buffer 'hugo "*Export Result Buffer*" nil nil t t))) |
Hi @alhassy, that sounds awesome, but unfortunately I cannot get it to work 😞. I am using the following configuration, but if I export with If I execute the temp buffer test however, that seems to work for me and produces:
New Configuration
"Old" ConfigurationThe configuration I tried to build before is which works, but is unable to interpret the parameters given.:
Can you please update the "old" configuration with the |
Consider some latex derived backend:
And a custom special block
myblock
to go with itUse
mybloc
in some test.org file:Now the issue is
myblock
is never rendered when exporting test.org to latexIs there a proper way to make
defblock
work with latex dervied backends?Currently overriding
org-latex-special-block
frommy-backend
translation tableand fixing
org-export-current-backend
to point tolatex
during export seems towork.
The text was updated successfully, but these errors were encountered: