* Re: [PATCH] New remote resource download policy
@ 2022-07-16 9:47 92% ` Timothy
0 siblings, 0 replies; 200+ results
From: Timothy @ 2022-07-16 9:47 UTC (permalink / raw)
To: Max Nikulin; +Cc: emacs-orgmode
[-- Attachment #1: Type: text/plain, Size: 1480 bytes --]
Hi Max,
I’ve just made a few more tweaks, tested it, and pushed this as 0583a0c. We may
want to tweak this further before the next Org release, but I think this is a
good enough starting point.
> An idea: a menu entry that displays location in the org file that caused the
> prompt. However it may require enough work to pass context data to the function
> rendering menu.
This could be added in future.
> I see you point concerning blocking modal prompt and I do not like it as well.
> Have you seen the following thread:
>
> Arthur Miller. Proposal: ’executable’ org-capture-templaes. Wed, 22 Jun 2022
> 14:13:51 +0200.
> <https://list.orgmode.org/AM9PR09MB49771CF015DAECBF3E5F955E96B29@AM9PR09MB4977.eurprd09.prod.outlook.com>
>
> If it were merged already, would it be enough for you to implement the dialog or
> the proposal lacks some features necessary for smooth user experience?
I have not read much of this thread, but from a brief glance — possibly.
> The reason why I asked about `org-mks’ is expectation of UI consistency withing
> Org. It might help users having customized `display-buffer-alist’
Here I was more thinking of UI consistency within Emacs.
> I still do not like code adding a menu close enough to existing one, but I will
> not object any more.
Since this is separate to the functionality, I’m going to push this for now, and
we can update the UI side of things later.
All the best,
Timothy
^ permalink raw reply [relevance 92%]
* Re: fontsets (was: [possible patch] Basic fontspec code for LuaLaTeX and XelaTeX (was "LaTeX export: when is it more useful..."))
@ 2022-07-11 17:45 85% ` Timothy
0 siblings, 0 replies; 200+ results
From: Timothy @ 2022-07-11 17:45 UTC (permalink / raw)
To: Juan Manuel Macías; +Cc: Maxim Nikulin, Ihor Radchenko, orgmode
[-- Attachment #1: Type: text/plain, Size: 1432 bytes --]
Hi Juan,
> When you talk about fontset, I understand that you mean lists of
> families with their options that you have previously defined, is that
> right?
Yep, so in my config’s implementation I have an alist of fontset names and
individual fonts. For something part of org-mode itself, we’d probably want to
add a format level to this, something like:
┌────
│ ((fontset-name .
│ ((serif .
│ ((pdflatex . "\\usepackage{myserif}")
│ (lualatex . "etc.")
│ (html . "and so on")))
│ (sans ...) ... ))
│ (another-fontset ...) ...)
└────
Actually, now that I think of it maybe it would be better to seperate out the
fontsets and fots, e.g.
┌────
│ ;; Fonts
│ ((myfonta . ((pdflatex . "etc.") (lualatex ...) (html ...) ...))
│ (myfontb ...)
│ ...)
│ ;; Fontsets
│ ((myfontset .
│ ((sans . myfonta)
│ (serif . myfontb)
│ (mono . myfontc)
│ ...))
│ ...)
└────
> In any case, I think it would also be nice if the user could add only
> one family for roman, sans, mono or math, if he/she prefers it that way.
> Something like:
>
> #+options: rmfont:Minion Pro
Sure. There’s another bit of functionality in my config which I think is worth
noting, you can add a -sans/-serif/-mono suffix to the fontset name to override
the default body text font.
All the best,
Timothy
^ permalink raw reply [relevance 85%]
* Re: [possible patch] Basic fontspec code for LuaLaTeX and XelaTeX (was "LaTeX export: when is it more useful...")
@ 2022-07-11 14:19 76% ` Timothy
0 siblings, 1 reply; 200+ results
From: Timothy @ 2022-07-11 14:19 UTC (permalink / raw)
To: Ihor Radchenko; +Cc: Juan Manuel Macías, orgmode
[-- Attachment #1: Type: text/plain, Size: 1786 bytes --]
Hi Ihor & co.,
> As I recall, Timothy has been working on simplifying preamble
> generation. If we do not put unnecessary packages into preamble,
> compilation will be significantly faster.
>
> If Timothy can come up with a patch some time soon, I’d prefer to have a
> more targeted preamble. Otherwise, the proposed approach is the way to
> go.
Yep, I’ve got something in my config currently that intercepts LaTeX preamble
creation and generates it only the fly from a list of detected features based on
the exported document and capability providers. I use this in my config to
automatically switch to LuaLaTeX when necessary and use pdfLaTeX the rest of the
time.
This should also be able to be able clean up some of the currently kludgy
preamble modifications like in oc-csl.el.
This has been on the back-burner for a while (I want to implement this is a way
that can be generalised across all output backends), but I’ll see if I can make
some progress and hopefully have a preliminary patch set in the next few weeks.
Lastly, there’s something extra I want to note. If we talk about including a
font customisation, I’d advocate for supporting font sets, not fonts. Once
again, this is something I’m a fan of from my config, and this could potentially
be supported across multiple export formats.
As an illustrative example, if I include this in one of my documents and create
a PDF:
┌────
│ #+options: fontset:biolinum
└────
Then I’ll get text with:
⁃ libertine roman as the serif font
⁃ biolinum as the serif, and default, font
⁃ source code pro as the mono font
⁃ newtxmath as the maths font
Similarly I can do `fontset:noto' and you can guess what that does.
All the best,
Timothy
^ permalink raw reply [relevance 76%]
* Re: [PATCH] New remote resource download policy
@ 2022-06-29 15:27 93% ` Timothy
0 siblings, 1 reply; 200+ results
From: Timothy @ 2022-06-29 15:27 UTC (permalink / raw)
To: Max Nikulin; +Cc: emacs-orgmode
[-- Attachment #1: Type: text/plain, Size: 1563 bytes --]
Hi Max,
Max Nikulin <manikulin@gmail.com> writes:
>>> I see your intention to add something fancy to the dialog. May `org-mks’ be
>>> reused instead to avoid proliferation variants of rather similar UI code?
>> Well, the thing here is that I’m explicitly trying to mimic the
>> file-local-variable dialog, and since a general form isn’t exposed by Emacs, a
>> little bit of proliferation seems like the best option to me.
>
> From my point of view the result is rather close (prompt should be adjusted):
>
> (let ((uri “<https://orgmode.org>”))
> (org-mks
> nil
> (format “An org-mode document would like to download %s, which is not
> considered safe.
>
> Do you want to download this?”
> (propertize uri ’face ’(:inherit org-link :weight normal)))
> nil ; prompt
> `((,(propertize “!” ’face ’success)
> “download this resource, and permanantly mark it as safe.”)
> (,(propertize “y” ’face ’warning)
> “to download this resource, just this once.”)
> (,(propertize “n” ’face ’error)
> “skip this resource.”))))
I just tried this snippet and it looked quite different to me, that said I have
tweaked `org-mks' a bit in my config… (I initially found org-capture quite
ugly).
I also really don’t like how `org-mks' so forcefully grabs all keyboard input. I
can see it being nice to jump back to the buffer and see where the resource is
being used, which isn’t really possible using `org-mks'.
All the best,
Timothy
^ permalink raw reply [relevance 93%]
* Re: [PATCH] Fix caption format for custom latex src block
@ 2022-06-29 15:26 89% ` Timothy
1 sibling, 0 replies; 200+ results
From: Timothy @ 2022-06-29 15:26 UTC (permalink / raw)
To: Matt Huszagh; +Cc: Ihor Radchenko, emacs-orgmode
[-- Attachment #1: Type: text/plain, Size: 1123 bytes --]
Hi Matt,
As mentioned by Ihor, you’ll want to take a look at the curent version of
ox-latex, specifically `org-latex-src-block--custom' which now contains `(?c .
,caption)'. You may want to consider modifying `org-latex--caption/label-string' to
accept the form `(element info &optional content-only)' or reimplementing just the
bits needed for this purpose — which ever works out nicer. Looking at
`org-latex--caption/label-string' a substring approach looks quite fragile, though
you might be able to get away with an application of `replace-regexp-in-string',
though I’d personally consider this a bit of a last resort.
Matt Huszagh <huszaghmatt@gmail.com> writes:
> Ihor Radchenko <yantar92@gmail.com> writes:
>
>> I think that it will be better if you use
>> org-latex–caption/label-string instead. It will take care about short
>> captions as well.
>
> Changing this to (?c . ,caption-str) yields for the original example
>
> {Perform inter-sample interpolation.
> }
>
> I could use substring to remove the leading { and trailing
> }. What do you think?
All the best,
Timothy
^ permalink raw reply [relevance 89%]
* Re: [PATCH] Fix caption format for custom latex src block
@ 2022-06-29 15:20 93% ` Timothy
0 siblings, 0 replies; 200+ results
From: Timothy @ 2022-06-29 15:20 UTC (permalink / raw)
To: Ihor Radchenko; +Cc: Matt Huszagh, Emacs-Orgmode
[-- Attachment #1: Type: text/plain, Size: 310 bytes --]
Hi Ihor,
> Timothy, looking at the new implementation of org-latex-src-block, I do
> not see custom-env being passed as an argument of
> org-latex-src-block–custom. This is likely a bug.
Ah yes, this was an oversight. Corrected in 30953bd7b701c870152cd60f52f2d484970caeb9.
All the best,
Timothy
^ permalink raw reply [relevance 93%]
* Re: [STYLE] :version tags in defcustom definitions (was: [PATCH] Improve look of agenda on graphical displays)
@ 2022-06-29 14:07 93% ` Timothy
0 siblings, 0 replies; 200+ results
From: Timothy @ 2022-06-29 14:07 UTC (permalink / raw)
To: Stefan Kangas; +Cc: Ihor Radchenko, Daniel Mendler, emacs-orgmode
[-- Attachment #1: Type: text/plain, Size: 451 bytes --]
Hi Ihor and Stefan,
>> Sure. Just trying to clarify my confusion. The inconsistency with some
>> defcustoms using :version and some not is bugging me.
>
> Agreed. It would be better to be consistent with this.
Given that org-mode is distributed separately to Emacs, and I get the impression
having a newer org-mode version that Emacs version is not uncommon, I think it
would make sense to have /just/ org-mode version tags.
All the best,
Timothy
^ permalink raw reply [relevance 93%]
* Re: [PATCH] New remote resource download policy
@ 2022-06-22 10:01 85% ` Timothy
0 siblings, 1 reply; 200+ results
From: Timothy @ 2022-06-22 10:01 UTC (permalink / raw)
To: Max Nikulin; +Cc: emacs-orgmode
[-- Attachment #1: Type: text/plain, Size: 3028 bytes --]
Hi Max,
>> — a/lisp/org-attach.el
>> +++ b/lisp/org-attach.el
>> @@ -525,7 +525,11 @@ (defun org-attach-attach (file &optional visit-dir method)
>> [snip]
>> + (if (or (not noninteractive) (org–should-fetch-remote-resource-p file))
>
> I am confused by (not noninteractive). Does it mean that interactive call is
> enough to bypass protection? It may have sense it at this step there is no
> ambiguity what resources is fetched. On the other hand I am unsure concerning a
> case when `org-attach-attach’ is a part of a larger command.
The idea here is that when this is done interactively the user will be aware of
the URL this is being applied to, and so it isn’t a risk. Let me know if this
assumption doesn’t hold.
>> +(defcustom org-download-remote-resources ’prompt
>
> The name sounds like some function.
Mmm. I could add `-policy' to that variable name perhaps.
>> +(defun org–confirm-resource-safe (uri)
>> + “Ask the user if URI should be considered safe, returning non-nil if so.”
>> + (unless noninteractive
>> + (let ((buf (get-buffer-create “*Org Remote Resource*”)))
>
> I see your intention to add something fancy to the dialog. May `org-mks’ be
> reused instead to avoid proliferation variants of rather similar UI code?
Well, the thing here is that I’m explicitly trying to mimic the
file-local-variable dialog, and since a general form isn’t exposed by Emacs, a
little bit of proliferation seems like the best option to me.
>> + ;; Set up the contents of the *Local Variables* buffer.
>
> I am in doubts concerning “once”. I tried “y” in a file having to “#+include:”
> of the same file. I did not get question for second include. I did not get
> prompt for this file anymore at all, even during next export. I modified the
> remote file, but stale content appeared during export. So the file was really
> downloaded once, but it is hardly in agreement with my expectations. Behavior is
> unrelated to this patch, concerning wording I am not sure, but I have no a
> better variant.
Ok, that is not the intended behaviour. I’ll see if I can work out what’s going
on here. Oh, and I should change that comment to “Set up the contents of the *Org
Remote Resource* buffer.”.
>> + (propertize “n” ’face ’error)
>> + “ to skip this resource.”)
>
> From “skip” I do not expect aborting of export.
Hmm, the “skip” action isn’t determined by the “is it safe” functions, but some
wording that doesn’t sound completely safe at least would be good.
> I have an idea but unsure if it should be implemented. Consider
> `org-remote-resources-policy’ custom variable that is a list of pairs
> (url-regexp . policy) for fine grain tuning instead of 2 variables. The price is
> more complicated structure, so higher chance of user error.
My initial reaction is that this feels like overkill.
All the best,
Timothy
^ permalink raw reply [relevance 85%]
* Re: [PATCH] New remote resource download policy
@ 2022-06-22 9:58 93% ` Timothy
0 siblings, 0 replies; 200+ results
From: Timothy @ 2022-06-22 9:58 UTC (permalink / raw)
To: Robert Pluim; +Cc: emacs-orgmode
[-- Attachment #1: Type: text/plain, Size: 719 bytes --]
Hi Robert,
> Timothy> +(defcustom org-download-remote-resources ’prompt
>
> ’prompted when downloading unsafe resources’
>
> maybe?
>
> Does this need a ’prompt-always option? I guess thatʼs what you get
> with the default value of `org-safe-remote-resources’, but maybe it
> makes sense to be explicit?
That isn’t the behaviour. `prompt' doesn’t /always/ prompt, just when the resource
in question is not considered safe according to `org--safe-remote-resource-p'.
So, `prompt-always' would be something else, but one can easily make prompt behave
that way by setting `org-safe-remote-resources' to nil, so I don’t think it
warrants an extra option.
All the best,
Timothy
^ permalink raw reply [relevance 93%]
* [PATCH] New remote resource download policy
@ 2022-06-12 14:43 37% Timothy
0 siblings, 2 replies; 200+ results
From: Timothy @ 2022-06-12 14:43 UTC (permalink / raw)
To: emacs-orgmode
[-- Attachment #1.1: Type: text/plain, Size: 492 bytes --]
Hi All,
As was raised in the `#+include: URL' thread
(<https://list.orgmode.org/877d5sd7yu.fsf@gmail.com>), currently Org will
automatically download files without confirmation in various circumstances.
This patch introduces two variables to control Org’s attitude towards
downloading files, and hooks them into the relevant parts of the codebase.
When prompting for downloading, this uses an approach borrowed from file local
variable confirmation.
All the best,
Timothy
[-- Attachment #1.2: Type: text/html, Size: 3186 bytes --]
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-org-Add-setting-for-remote-file-download-policy.patch --]
[-- Type: text/x-patch, Size: 8990 bytes --]
From 4f3437a2386e2ffdf37c99d476fa5ea3481b8d3c Mon Sep 17 00:00:00 2001
From: TEC <tec@tecosaur.com>
Date: Sun, 12 Jun 2022 22:37:42 +0800
Subject: [PATCH] org: Add setting for remote file download policy
* lisp/org.el (org-download-remote-resources,
org-safe-remote-resources): Two new customisations to configure the
policy for downloading remote resources.
(org--should-fetch-remote-resource-p, org--safe-remote-resource-p,
org--confirm-resource-safe, org-download-remote-resources): Introduce
the new function `org--should-fetch-remote-resource-p' for internal use
determining whether a remote resource should be downloaded according to
the download policy. This function makes use of two helper functions,
`org--safe-remote-resource-p' and `org--confirm-resource-safe'.
(org-file-contents): Apply `org--safe-remote-resource-p' to file
downloading.
* lisp/org-persist.el (org-persist-write): Apply
`org--safe-remote-resource-p' to url downloading.
* lisp/org-attach.el (org-attach-attach): Apply
`org--safe-remote-resource-p' to url downloading.
---
lisp/org-attach.el | 6 ++-
lisp/org-persist.el | 5 +-
lisp/org.el | 115 ++++++++++++++++++++++++++++++++++++++------
3 files changed, 109 insertions(+), 17 deletions(-)
diff --git a/lisp/org-attach.el b/lisp/org-attach.el
index 5ee2b84b2..6f21ad716 100644
--- a/lisp/org-attach.el
+++ b/lisp/org-attach.el
@@ -525,7 +525,11 @@ (defun org-attach-attach (file &optional visit-dir method)
((eq method 'cp) (copy-file file attach-file))
((eq method 'ln) (add-name-to-file file attach-file))
((eq method 'lns) (make-symbolic-link file attach-file))
- ((eq method 'url) (url-copy-file file attach-file)))
+ ((eq method 'url)
+ (if (or (not noninteractive) (org--should-fetch-remote-resource-p file))
+ (url-copy-file file attach-file)
+ (error "The remote resource %S is considered unsafe, and will not be downloaded."
+ file))))
(run-hook-with-args 'org-attach-after-change-hook attach-dir)
(org-attach-tag)
(cond ((eq org-attach-store-link-p 'attached)
diff --git a/lisp/org-persist.el b/lisp/org-persist.el
index 068f58cec..f49abe8cd 100644
--- a/lisp/org-persist.el
+++ b/lisp/org-persist.el
@@ -655,7 +655,10 @@ (defun org-persist-write:url (c collection)
(format "%s-%s.%s" persist-file (md5 path) ext))))
(unless (file-exists-p (file-name-directory file-copy))
(make-directory (file-name-directory file-copy) t))
- (url-copy-file path file-copy 'overwrite)
+ (if (org--should-fetch-remote-resource-p path)
+ (url-copy-file path file-copy 'overwrite)
+ (error "The remote resource %S is considered unsafe, and will not be downloaded."
+ path))
(format "%s-%s.%s" persist-file (md5 path) ext)))))
(defun org-persist-write:index (container _)
diff --git a/lisp/org.el b/lisp/org.el
index 8e7aadde5..3a8acaa8f 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -1352,6 +1352,32 @@ (defcustom org-file-apps
(string :tag "Command")
(function :tag "Function")))))
+(defcustom org-download-remote-resources 'prompt
+ "The policy applied to requests to obtain remote resources.
+
+This affects keywords like #+setupfile and #+incude on export,
+`org-persist-write:url',and `org-attach-attach' in
+non-interactive Emacs sessions.
+
+This recognises four possible values:
+- t, remote resources should always be downloaded.
+- prompt, you will be prompted to download resources nt considered safe.
+- safe, only resources considered safe will be downloaded.
+- nil, never download remote resources.
+
+A resource is considered safe if it matches one of the patterns
+in `org-safe-remote-resources'."
+ :group 'org
+ :type '(choice (const :tag "Always download remote resources" t)
+ (const :tag "Prompt before downloading an unsafe resource" prompt)
+ (const :tag "Only download resources considered safe" safe)
+ (const :tag "Never download any resources" nil)))
+
+(defcustom org-safe-remote-resources nil
+ "A list of regexp patterns matching safe URIs."
+ :group 'org
+ :type '(list regexp))
+
(defcustom org-open-non-existing-files nil
"Non-nil means `org-open-file' opens non-existing files.
@@ -4466,21 +4492,25 @@ (defun org-file-contents (file &optional noerror nocache)
(cond
(cache)
(is-url
- (with-current-buffer (url-retrieve-synchronously file)
- (goto-char (point-min))
- ;; Move point to after the url-retrieve header.
- (search-forward "\n\n" nil :move)
- ;; Search for the success code only in the url-retrieve header.
- (if (save-excursion
- (re-search-backward "HTTP.*\\s-+200\\s-OK" nil :noerror))
- ;; Update the cache `org--file-cache' and return contents.
- (puthash file
- (buffer-substring-no-properties (point) (point-max))
- org--file-cache)
- (funcall (if noerror #'message #'user-error)
- "Unable to fetch file from %S"
- file)
- nil)))
+ (if (org--should-fetch-remote-resource-p file)
+ (with-current-buffer (url-retrieve-synchronously file)
+ (goto-char (point-min))
+ ;; Move point to after the url-retrieve header.
+ (search-forward "\n\n" nil :move)
+ ;; Search for the success code only in the url-retrieve header.
+ (if (save-excursion
+ (re-search-backward "HTTP.*\\s-+200\\s-OK" nil :noerror))
+ ;; Update the cache `org--file-cache' and return contents.
+ (puthash file
+ (buffer-substring-no-properties (point) (point-max))
+ org--file-cache)
+ (funcall (if noerror #'message #'user-error)
+ "Unable to fetch file from %S"
+ file)
+ nil))
+ (funcall (if noerror #'message #'user-error)
+ "The remote resource %S is considered unsafe, and will not be downloaded."
+ file)))
(t
(with-temp-buffer
(condition-case nil
@@ -4493,6 +4523,61 @@ (defun org-file-contents (file &optional noerror nocache)
file)
nil)))))))
+(defun org--should-fetch-remote-resource-p (uri)
+ "Return non-nil if the URI should be fetched."
+ (or (eq org-download-remote-resources t)
+ (org--safe-remote-resource-p uri)
+ (and (eq org-download-remote-resources 'prompt)
+ (org--confirm-resource-safe uri))))
+
+(defun org--safe-remote-resource-p (uri)
+ "Return non-nil if URI is considered safe.
+This checks every pattern in `org-safe-remote-resources', and
+returns non-nil if any of them match."
+ (let (match-p (uri-patterns org-safe-remote-resources))
+ (while (and (not match-p) uri-patterns)
+ (setq match-p (string-match-p (car uri-patterns) uri)
+ uri-patterns (cdr uri-patterns)))
+ match-p))
+
+(defun org--confirm-resource-safe (uri)
+ "Ask the user if URI should be considered safe, returning non-nil if so."
+ (unless noninteractive
+ (let ((buf (get-buffer-create "*Org Remote Resource*")))
+ ;; Set up the contents of the *Local Variables* buffer.
+ (with-current-buffer buf
+ (erase-buffer)
+ (insert "An org-mode document would like to download "
+ (propertize uri 'face '(:inherit org-link :weight normal))
+ ", which is not considered safe.\n\n"
+ "Do you want to download this? You can type\n "
+ (propertize "!" 'face 'success)
+ " to download this resource, and permanantly mark it as safe.\n "
+ (propertize "y" 'face 'warning)
+ " to download this resource, just this once.\n "
+ (propertize "n" 'face 'error)
+ " to skip this resource.\n")
+ (setq-local cursor-type nil)
+ (set-buffer-modified-p nil)
+ (goto-char (point-min)))
+ ;; Display the buffer and read a choice.
+ (save-window-excursion
+ (pop-to-buffer buf)
+ (let* ((exit-chars '(?y ?n ?! ?\s))
+ (prompt (format "Please type y, n, or !%s: "
+ (if (< (line-number-at-pos (point-max))
+ (window-body-height))
+ ""
+ ", or C-v/M-v to scroll")))
+ char)
+ (setq char (read-char-choice prompt exit-chars))
+ (when (= char ?!)
+ (customize-push-and-save
+ 'org-safe-remote-resources
+ (regexp-quote uri)))
+ (prog1 (memq char '(?! ?\s ?y))
+ (quit-window t)))))))
+
(defun org-extract-log-state-settings (x)
"Extract the log state setting from a TODO keyword string.
This will extract info from a string like \"WAIT(w@/!)\"."
--
2.36.1
^ permalink raw reply related [relevance 37%]
* Re: [PATCH] Support #+include-ing URLs
2022-06-05 14:32 43% [PATCH] Support #+include-ing URLs Timothy
@ 2022-06-12 9:52 93% ` Timothy
1 sibling, 0 replies; 200+ results
From: Timothy @ 2022-06-12 9:52 UTC (permalink / raw)
To: Org Mode
Hi All,
> This is just a little patchset to treat #+include: URL the same way as
> #+setupfile: URL. All the usual #+include: bells and whistles
> (::*Heading, :lines, etc.) work as normal.
Since it's been a week and nobody has raised any objections to this
functionality (though it has provoked a proposed change to
org-file-contents), I'm going to tentatively merge this and prepare a
patch for org-file-contents to add download settings.
All the best,
Timothy
^ permalink raw reply [relevance 93%]
* Re: [PATCH] Support #+include-ing URLs
@ 2022-06-07 11:27 91% ` Timothy
0 siblings, 0 replies; 200+ results
From: Timothy @ 2022-06-07 11:27 UTC (permalink / raw)
To: Fraga, Eric; +Cc: Max Nikulin, emacs-orgmode
[-- Attachment #1: Type: text/plain, Size: 682 bytes --]
Hi Eric,
>> Is it possible to disable fetching remote files by some setting?
>
> I would not want automatic retrieval of URLs without confirmation.
This already occurs with #+setupfile.
I think this is a good point to raise, but a slightly separate one as it
concerns the pre-existing behaviour of org-file-contents.
A new patch set introducing a defcustom with three values (t, prompt, nil) and
accompanying modification to org-file-contents (it’s the only use of
`url-retrieve-synchronously' other than org-feed I see) would probably be a decent
idea. If nobody makes such a patch in the next week or so I’ll take a punt at
this.
All the best,
Timothy
^ permalink raw reply [relevance 91%]
* [PATCH] Support #+include-ing URLs
@ 2022-06-05 14:32 43% Timothy
2022-06-12 9:52 93% ` Timothy
0 siblings, 2 replies; 200+ results
From: Timothy @ 2022-06-05 14:32 UTC (permalink / raw)
To: Org Mode
[-- Attachment #1.1: Type: text/plain, Size: 218 bytes --]
Hi All,
This is just a little patchset to treat `#+include: URL' the same way as
`#+setupfile: URL'. All the usual `#+include:' bells and whistles (`::*Heading',
`:lines', etc.) work as normal.
All the best,
Timothy
[-- Attachment #1.2: Type: text/html, Size: 3326 bytes --]
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0002-org-lint-don-t-complain-about-include-URL.patch --]
[-- Type: text/x-patch, Size: 4172 bytes --]
From df0b382e43cf44860247fafd14bd2932fe3ed026 Mon Sep 17 00:00:00 2001
From: TEC <tec@tecosaur.com>
Date: Sun, 5 Jun 2022 22:28:39 +0800
Subject: [PATCH 2/2] org-lint: don't complain about #+include URL
* lisp/org-lint.el (org-lint-wrong-include-link-parameter): When the
included file is a URL, skip the usual file checks.
---
lisp/org-lint.el | 67 ++++++++++++++++++++++++------------------------
1 file changed, 34 insertions(+), 33 deletions(-)
diff --git a/lisp/org-lint.el b/lisp/org-lint.el
index cce6fddbd..1e0dba4a0 100644
--- a/lisp/org-lint.el
+++ b/lisp/org-lint.el
@@ -649,39 +649,40 @@ (defun org-lint-wrong-include-link-parameter (ast)
(org-element-map ast 'keyword
(lambda (k)
(when (equal (org-element-property :key k) "INCLUDE")
- (let* ((value (org-element-property :value k))
- (path
- (and (string-match "^\\(\".+\"\\|\\S-+\\)[ \t]*" value)
- (save-match-data
- (org-strip-quotes (match-string 1 value))))))
- (if (not path)
- (list (org-element-property :post-affiliated k)
- "Missing location argument in INCLUDE keyword")
- (let* ((file (org-string-nw-p
- (if (string-match "::\\(.*\\)\\'" path)
- (substring path 0 (match-beginning 0))
- path)))
- (search (and (not (equal file path))
- (org-string-nw-p (match-string 1 path)))))
- (if (and file
- (not (file-remote-p file))
- (not (file-exists-p file)))
- (list (org-element-property :post-affiliated k)
- "Non-existent file argument in INCLUDE keyword")
- (let* ((visiting (if file (find-buffer-visiting file)
- (current-buffer)))
- (buffer (or visiting (find-file-noselect file)))
- (org-link-search-must-match-exact-headline t))
- (unwind-protect
- (with-current-buffer buffer
- (when (and search
- (not (ignore-errors
- (org-link-search search nil t))))
- (list (org-element-property :post-affiliated k)
- (format
- "Invalid search part \"%s\" in INCLUDE keyword"
- search))))
- (unless visiting (kill-buffer buffer))))))))))))
+ (let* ((value (org-element-property :value k))
+ (path
+ (and (string-match "^\\(\".+\"\\|\\S-+\\)[ \t]*" value)
+ (save-match-data
+ (org-strip-quotes (match-string 1 value))))))
+ (if (not path)
+ (list (org-element-property :post-affiliated k)
+ "Missing location argument in INCLUDE keyword")
+ (let* ((file (org-string-nw-p
+ (if (string-match "::\\(.*\\)\\'" path)
+ (substring path 0 (match-beginning 0))
+ path)))
+ (search (and (not (equal file path))
+ (org-string-nw-p (match-string 1 path)))))
+ (unless (org-url-p file)
+ (if (and file
+ (not (file-remote-p file))
+ (not (file-exists-p file)))
+ (list (org-element-property :post-affiliated k)
+ "Non-existent file argument in INCLUDE keyword")
+ (let* ((visiting (if file (find-buffer-visiting file)
+ (current-buffer)))
+ (buffer (or visiting (find-file-noselect file)))
+ (org-link-search-must-match-exact-headline t))
+ (unwind-protect
+ (with-current-buffer buffer
+ (when (and search
+ (not (ignore-errors
+ (org-link-search search nil t))))
+ (list (org-element-property :post-affiliated k)
+ (format
+ "Invalid search part \"%s\" in INCLUDE keyword"
+ search))))
+ (unless visiting (kill-buffer buffer)))))))))))))
(defun org-lint-obsolete-include-markup (ast)
(let ((regexp (format "\\`\\(?:\".+\"\\|\\S-+\\)[ \t]+%s"
--
2.36.1
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #3: 0001-ox-Support-include-ing-URLs.patch --]
[-- Type: text/x-patch, Size: 4174 bytes --]
From 2e2189c451c8e8bbd8461a626fe63e5e97dd4a07 Mon Sep 17 00:00:00 2001
From: TEC <tec@tecosaur.com>
Date: Sun, 5 Jun 2022 22:25:22 +0800
Subject: [PATCH 1/2] ox: Support #+include-ing URLs
* lisp/ox.el (org-export--prepare-file-contents,
org-export--inclusion-absolute-lines): Replace instances of
`(insert-file-contents FILE)' with `(insert (org-file-contents FILE))',
as in `org--collect-keywords-1'.
(org-export-expand-include-keyword): Tweak to accept a URL as FILE, and
not perform the standard "file exists and is readable" check.
* etc/ORG-NEWS: Mention this change in behaviour.
---
etc/ORG-NEWS | 3 +++
lisp/ox.el | 22 +++++++++++++---------
2 files changed, 16 insertions(+), 9 deletions(-)
diff --git a/etc/ORG-NEWS b/etc/ORG-NEWS
index 35af94f92..397cb668c 100644
--- a/etc/ORG-NEWS
+++ b/etc/ORG-NEWS
@@ -219,6 +219,9 @@ blocks to LaTeX. This requires the =fvextra=, =float=, and (by
default, but not necessarily) =tcolorbox= LaTeX packages be
installed. It uses Emacs' font-lock information, and so tends to
produce results superior to Minted or Listings.
+*** Support for =#+include=-ing URLs
+
+=#+include: FILE= will now accept URLs as the file.
** New functions and changes in function arguments
diff --git a/lisp/ox.el b/lisp/ox.el
index 9a8e63046..fc0ee671f 100644
--- a/lisp/ox.el
+++ b/lisp/ox.el
@@ -3229,15 +3229,18 @@ (defun org-export-expand-include-keyword (&optional included dir footnotes)
value)
(prog1
(save-match-data
- (let ((matched (match-string 1 value)))
+ (let ((matched (match-string 1 value))
+ stripped)
(when (string-match "\\(::\\(.*?\\)\\)\"?\\'"
matched)
(setq location (match-string 2 matched))
(setq matched
(replace-match "" nil nil matched 1)))
- (expand-file-name (org-strip-quotes matched)
- dir)))
- (setq value (replace-match "" nil nil value)))))
+ (setq stripped (org-strip-quotes matched))
+ (if (org-url-p stripped)
+ stripped
+ (expand-file-name stripped dir))))
+ (setq value (replace-match "" nil nil value)))))
(only-contents
(and (string-match ":only-contents *\\([^: \r\t\n]\\S-*\\)?"
value)
@@ -3273,7 +3276,7 @@ (defun org-export-expand-include-keyword (&optional included dir footnotes)
(delete-region (point) (line-beginning-position 2))
(cond
((not file) nil)
- ((not (file-readable-p file))
+ ((and (not (org-url-p file)) (not (file-readable-p file)))
(error "Cannot include file %s" file))
;; Check if files has already been parsed. Look after
;; inclusion lines too, as different parts of the same
@@ -3319,8 +3322,9 @@ (defun org-export-expand-include-keyword (&optional included dir footnotes)
includer-file)))
(org-export-expand-include-keyword
(cons (list file lines) included)
- (file-name-directory file)
- footnotes)
+ (unless (org-url-p file)
+ (file-name-directory file))
+ footnotes)
(buffer-string)))))
;; Expand footnotes after all files have been
;; included. Footnotes are stored at end of buffer.
@@ -3343,7 +3347,7 @@ (defun org-export--inclusion-absolute-lines (file location only-contents lines)
Return a string of lines to be included in the format expected by
`org-export--prepare-file-contents'."
(with-temp-buffer
- (insert-file-contents file)
+ (insert (org-file-contents file))
(unless (eq major-mode 'org-mode)
(let ((org-inhibit-startup t)) (org-mode)))
(condition-case err
@@ -3448,7 +3452,7 @@ (defun org-export--prepare-file-contents
Optional argument INCLUDER is the file name where the inclusion
is to happen."
(with-temp-buffer
- (insert-file-contents file)
+ (insert (org-file-contents file))
(when lines
(let* ((lines (split-string lines "-"))
(lbeg (string-to-number (car lines)))
--
2.36.1
^ permalink raw reply related [relevance 43%]
* Re: [PATCH] (v3) New LaTeX code export option: engraved
@ 2022-05-12 16:44 93% ` Timothy
0 siblings, 0 replies; 200+ results
From: Timothy @ 2022-05-12 16:44 UTC (permalink / raw)
To: Daniel Fleischer; +Cc: Ihor Radchenko, emacs-orgmode, Nicolas Goaziou
[-- Attachment #1: Type: text/plain, Size: 635 bytes --]
Hi Daniel,
> Looks good. I had to update `engrave-faces’ to 0.3 because of new
> variables/functions and it works now. It does what it says on the box so
> let’s move forward introducing these changes and be open to feedback.
>
> Thank you very much for introducing this feature!
That’s great to hear! I’ve just tagged and pushed 0.3.1 of engrave-faces, so
HEAD is no longer required, along with my patch of ox-latex commits.
Thanks for helping with the process of getting this in, this has been over a
year in the works and so it feels fantastic to have this feature in-tree at last!
All the best,
Timothy
^ permalink raw reply [relevance 93%]
* Re: [PATCH] (v3) New LaTeX code export option: engraved
2022-05-08 14:30 6% ` [PATCH] (v2) " Timothy
@ 2022-05-11 16:05 5% ` Timothy
1 sibling, 1 reply; 200+ results
From: Timothy @ 2022-05-11 16:05 UTC (permalink / raw)
To: Daniel Fleischer; +Cc: Ihor Radchenko, emacs-orgmode, Nicolas Goaziou
[-- Attachment #1: Type: text/plain, Size: 799 bytes --]
Hi All,
I now have what I hope is the final set of patches[1].
Compared to v2 we have:
• a fix for % in captions (long standing bug)
• support for mathescaped code
• a news/manual entry for engraved
• a collection of tweaks based on Ihor’s lovely feedback 🤗
I’ve also slipped in a patch to `org-latex--label' which adds the `lst:' prefix
(short for listings) to `\label's generated for source blocks. This seemed like a
decent idea while I was working on captions, if anyone thinks otherwise I’ll
happily leave it out.
Daniel, if you’re happy with these commits let me know and I’ll push them :)
All the best,
Timothy
Footnotes
─────────
[1] For getting this feature
into Org. I’m sure there will be tweaks in the future.
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-ox-latex-Refactor-org-latex-src-block.patch --]
[-- Type: text/x-patch, Size: 15944 bytes --]
From 18adbd0e1226cf3307090861e09e92bfa9cdfbf1 Mon Sep 17 00:00:00 2001
From: TEC <tec@tecosaur.com>
Date: Sun, 21 Nov 2021 14:35:34 +0800
Subject: [PATCH 01/13] ox-latex: Refactor `org-latex-src-block'
* lisp/ox-latex.el (org-latex-src-block): Extract the per-format logic
from `org-latex-src-block' into new dedicated functions:
+ `org-latex-src-block--verbatim'
+ `org-latex-src-block--custom'
+ `org-latex-src-block--minted'
+ `org-latex-src-block--listings'
This makes `org-latex-src-block' much less monolithic, taking it from
175 lines to 30, and I find also makes it easier to understand.
---
lisp/ox-latex.el | 339 ++++++++++++++++++++++++++---------------------
1 file changed, 185 insertions(+), 154 deletions(-)
diff --git a/lisp/ox-latex.el b/lisp/ox-latex.el
index 841ad48bc..c2f728a1c 100644
--- a/lisp/ox-latex.el
+++ b/lisp/ox-latex.el
@@ -2997,164 +2997,195 @@ (defun org-latex-src-block (src-block _contents info)
(float (plist-get attributes :float))
(listings (plist-get info :latex-listings)))
(cond
- ;; Case 1. No source fontification.
((or (not lang) (not listings))
- (let ((caption-str (org-latex--caption/label-string src-block info))
- (verbatim (format "\\begin{verbatim}\n%s\\end{verbatim}"
- (org-export-format-code-default src-block info))))
- (cond ((string= "multicolumn" float)
- (format "\\begin{figure*}[%s]\n%s%s\n%s\\end{figure*}"
- (plist-get info :latex-default-figure-position)
- (if caption-above-p caption-str "")
- verbatim
- (if caption-above-p "" caption-str)))
- (caption (concat
- (if caption-above-p caption-str "")
- verbatim
- (if caption-above-p "" (concat "\n" caption-str))))
- (t verbatim))))
- ;; Case 2. Custom environment.
+ (org-latex-src-block--verbatim src-block info lang caption caption-above-p label
+ num-start retain-labels attributes float))
(custom-env
- (let ((caption-str (org-latex--caption/label-string src-block info))
- (formatted-src (org-export-format-code-default src-block info)))
- (if (string-match-p "\\`[a-zA-Z0-9]+\\'" custom-env)
- (format "\\begin{%s}\n%s\\end{%s}\n"
- custom-env
- (concat (and caption-above-p caption-str)
- formatted-src
- (and (not caption-above-p) caption-str))
- custom-env)
- (format-spec custom-env
- `((?s . ,formatted-src)
- (?c . ,caption)
- (?f . ,float)
- (?l . ,(org-latex--label src-block info))
- (?o . ,(or (plist-get attributes :options) "")))))))
- ;; Case 3. Use minted package.
+ (org-latex-src-block--custom src-block info lang caption caption-above-p label
+ num-start retain-labels attributes float custom-env))
((eq listings 'minted)
- (let* ((caption-str (org-latex--caption/label-string src-block info))
- (placement (or (org-unbracket-string "[" "]" (plist-get attributes :placement))
- (plist-get info :latex-default-figure-position)))
- (float-env
- (cond
- ((string= "multicolumn" float)
- (format "\\begin{listing*}[%s]\n%s%%s\n%s\\end{listing*}"
- placement
- (if caption-above-p caption-str "")
- (if caption-above-p "" caption-str)))
- (caption
- (format "\\begin{listing}[%s]\n%s%%s\n%s\\end{listing}"
- placement
- (if caption-above-p caption-str "")
- (if caption-above-p "" caption-str)))
- ((string= "t" float)
- (concat (format "\\begin{listing}[%s]\n"
- placement)
- "%s\n\\end{listing}"))
- (t "%s")))
- (options (plist-get info :latex-minted-options))
- (body
- (format
- "\\begin{minted}[%s]{%s}\n%s\\end{minted}"
- ;; Options.
- (concat
- (org-latex--make-option-string
- (if (or (not num-start) (assoc "linenos" options))
- options
- (append
- `(("linenos")
- ("firstnumber" ,(number-to-string (1+ num-start))))
- options)))
- (let ((local-options (plist-get attributes :options)))
- (and local-options (concat "," local-options))))
- ;; Language.
- (or (cadr (assq (intern lang)
- (plist-get info :latex-minted-langs)))
- (downcase lang))
- ;; Source code.
- (let* ((code-info (org-export-unravel-code src-block))
- (max-width
- (apply 'max
- (mapcar 'length
- (org-split-string (car code-info)
- "\n")))))
- (org-export-format-code
- (car code-info)
- (lambda (loc _num ref)
- (concat
- loc
- (when ref
- ;; Ensure references are flushed to the right,
- ;; separated with 6 spaces from the widest line
- ;; of code.
- (concat (make-string (+ (- max-width (length loc)) 6)
- ?\s)
- (format "(%s)" ref)))))
- nil (and retain-labels (cdr code-info)))))))
- ;; Return value.
- (format float-env body)))
- ;; Case 4. Use listings package.
+ (org-latex-src-block--minted src-block info lang caption caption-above-p label
+ num-start retain-labels attributes float))
(t
- (let ((lst-lang
- (or (cadr (assq (intern lang)
- (plist-get info :latex-listings-langs)))
- lang))
- (caption-str
- (when caption
- (let ((main (org-export-get-caption src-block))
- (secondary (org-export-get-caption src-block t)))
- (if (not secondary)
- (format "{%s}" (org-export-data main info))
- (format "{[%s]%s}"
- (org-export-data secondary info)
- (org-export-data main info))))))
- (lst-opt (plist-get info :latex-listings-options)))
- (concat
- ;; Options.
- (format
- "\\lstset{%s}\n"
- (concat
- (org-latex--make-option-string
- (append
- lst-opt
- (cond
- ((and (not float) (plist-member attributes :float)) nil)
- ((string= "multicolumn" float) '(("float" "*")))
- ((and float (not (assoc "float" lst-opt)))
- `(("float" ,(plist-get info :latex-default-figure-position)))))
- `(("language" ,lst-lang))
- (if label
- `(("label" ,(org-latex--label src-block info)))
- '(("label" " ")))
- (if caption-str `(("caption" ,caption-str)) '(("caption" " ")))
- `(("captionpos" ,(if caption-above-p "t" "b")))
- (cond ((assoc "numbers" lst-opt) nil)
- ((not num-start) '(("numbers" "none")))
- (t `(("firstnumber" ,(number-to-string (1+ num-start)))
- ("numbers" "left"))))))
- (let ((local-options (plist-get attributes :options)))
- (and local-options (concat "," local-options)))))
- ;; Source code.
- (format
- "\\begin{lstlisting}\n%s\\end{lstlisting}"
- (let* ((code-info (org-export-unravel-code src-block))
- (max-width
- (apply 'max
- (mapcar 'length
- (org-split-string (car code-info) "\n")))))
- (org-export-format-code
- (car code-info)
- (lambda (loc _num ref)
- (concat
- loc
- (when ref
- ;; Ensure references are flushed to the right,
- ;; separated with 6 spaces from the widest line of
- ;; code
- (concat (make-string (+ (- max-width (length loc)) 6) ?\s)
- (format "(%s)" ref)))))
- nil (and retain-labels (cdr code-info))))))))))))
-
+ (org-latex-src-block--listings src-block info lang caption caption-above-p label
+ num-start retain-labels attributes float))))))
+
+(defun org-latex-src-block--verbatim
+ (src-block info _lang caption caption-above-p _label
+ _num-start _retain-labels _attributes float)
+ "Transcode a SRC-BLOCK element from Org to LaTeX, using verbatim.
+LANG, CAPTION, CAPTION-ABOVE-P, LABEL, NUM-START, RETAIN-LABELS, ATTRIBUTES
+and FLOAT are extracted from SRC-BLOCK and INFO in `org-latex-src-block'."
+ (let ((caption-str (org-latex--caption/label-string src-block info))
+ (verbatim (format "\\begin{verbatim}\n%s\\end{verbatim}"
+ (org-export-format-code-default src-block info))))
+ (cond ((string= "multicolumn" float)
+ (format "\\begin{figure*}[%s]\n%s%s\n%s\\end{figure*}"
+ (plist-get info :latex-default-figure-position)
+ (if caption-above-p caption-str "")
+ verbatim
+ (if caption-above-p "" caption-str)))
+ (caption (concat
+ (if caption-above-p caption-str "")
+ verbatim
+ (if caption-above-p "" (concat "\n" caption-str))))
+ (t verbatim))))
+
+(defun org-latex-src-block--custom
+ (src-block info _lang caption caption-above-p _label
+ _num-start _retain-labels attributes float custom-env)
+ "Transcode a SRC-BLOCK element from Org to LaTeX, using a custom environment.
+LANG, CAPTION, CAPTION-ABOVE-P, LABEL, NUM-START, RETAIN-LABELS, ATTRIBUTES
+and FLOAT are extracted from SRC-BLOCK and INFO in `org-latex-src-block'."
+ (let ((caption-str (org-latex--caption/label-string src-block info))
+ (formatted-src (org-export-format-code-default src-block info)))
+ (if (string-match-p "\\`[a-zA-Z0-9]+\\'" custom-env)
+ (format "\\begin{%s}\n%s\\end{%s}\n"
+ custom-env
+ (concat (and caption-above-p caption-str)
+ formatted-src
+ (and (not caption-above-p) caption-str))
+ custom-env)
+ (format-spec custom-env
+ `((?s . ,formatted-src)
+ (?c . ,caption)
+ (?f . ,float)
+ (?l . ,(org-latex--label src-block info))
+ (?o . ,(or (plist-get attributes :options) "")))))))
+
+(defun org-latex-src-block--minted
+ (src-block info lang caption caption-above-p _label
+ num-start retain-labels attributes float)
+ "Transcode a SRC-BLOCK element from Org to LaTeX, using minted.
+LANG, CAPTION, CAPTION-ABOVE-P, LABEL, NUM-START, RETAIN-LABELS, ATTRIBUTES
+and FLOAT are extracted from SRC-BLOCK and INFO in `org-latex-src-block'."
+ (let* ((caption-str (org-latex--caption/label-string src-block info))
+ (placement (or (org-unbracket-string "[" "]" (plist-get attributes :placement))
+ (plist-get info :latex-default-figure-position)))
+ (float-env
+ (cond
+ ((string= "multicolumn" float)
+ (format "\\begin{listing*}[%s]\n%s%%s\n%s\\end{listing*}"
+ placement
+ (if caption-above-p caption-str "")
+ (if caption-above-p "" caption-str)))
+ (caption
+ (format "\\begin{listing}[%s]\n%s%%s\n%s\\end{listing}"
+ placement
+ (if caption-above-p caption-str "")
+ (if caption-above-p "" caption-str)))
+ ((string= "t" float)
+ (concat (format "\\begin{listing}[%s]\n"
+ placement)
+ "%s\n\\end{listing}"))
+ (t "%s")))
+ (options (plist-get info :latex-minted-options))
+ (body
+ (format
+ "\\begin{minted}[%s]{%s}\n%s\\end{minted}"
+ ;; Options.
+ (concat
+ (org-latex--make-option-string
+ (if (or (not num-start) (assoc "linenos" options))
+ options
+ (append
+ `(("linenos")
+ ("firstnumber" ,(number-to-string (1+ num-start))))
+ options)))
+ (let ((local-options (plist-get attributes :options)))
+ (and local-options (concat "," local-options))))
+ ;; Language.
+ (or (cadr (assq (intern lang)
+ (plist-get info :latex-minted-langs)))
+ (downcase lang))
+ ;; Source code.
+ (let* ((code-info (org-export-unravel-code src-block))
+ (max-width
+ (apply 'max
+ (mapcar 'length
+ (org-split-string (car code-info)
+ "\n")))))
+ (org-export-format-code
+ (car code-info)
+ (lambda (loc _num ref)
+ (concat
+ loc
+ (when ref
+ ;; Ensure references are flushed to the right,
+ ;; separated with 6 spaces from the widest line
+ ;; of code.
+ (concat (make-string (+ (- max-width (length loc)) 6)
+ ?\s)
+ (format "(%s)" ref)))))
+ nil (and retain-labels (cdr code-info)))))))
+ ;; Return value.
+ (format float-env body)))
+
+(defun org-latex-src-block--listings
+ (src-block info lang caption caption-above-p label
+ num-start retain-labels attributes float)
+ "Transcode a SRC-BLOCK element from Org to LaTeX, using listings.
+LANG, CAPTION, CAPTION-ABOVE-P, LABEL, NUM-START, RETAIN-LABELS, ATTRIBUTES
+and FLOAT are extracted from SRC-BLOCK and INFO in `org-latex-src-block'."
+ (let ((lst-lang
+ (or (cadr (assq (intern lang)
+ (plist-get info :latex-listings-langs)))
+ lang))
+ (caption-str
+ (when caption
+ (let ((main (org-export-get-caption src-block))
+ (secondary (org-export-get-caption src-block t)))
+ (if (not secondary)
+ (format "{%s}" (org-export-data main info))
+ (format "{[%s]%s}"
+ (org-export-data secondary info)
+ (org-export-data main info))))))
+ (lst-opt (plist-get info :latex-listings-options)))
+ (concat
+ ;; Options.
+ (format
+ "\\lstset{%s}\n"
+ (concat
+ (org-latex--make-option-string
+ (append
+ lst-opt
+ (cond
+ ((and (not float) (plist-member attributes :float)) nil)
+ ((string= "multicolumn" float) '(("float" "*")))
+ ((and float (not (assoc "float" lst-opt)))
+ `(("float" ,(plist-get info :latex-default-figure-position)))))
+ `(("language" ,lst-lang))
+ (if label
+ `(("label" ,(org-latex--label src-block info)))
+ '(("label" " ")))
+ (if caption-str `(("caption" ,caption-str)) '(("caption" " ")))
+ `(("captionpos" ,(if caption-above-p "t" "b")))
+ (cond ((assoc "numbers" lst-opt) nil)
+ ((not num-start) '(("numbers" "none")))
+ (t `(("firstnumber" ,(number-to-string (1+ num-start)))
+ ("numbers" "left"))))))
+ (let ((local-options (plist-get attributes :options)))
+ (and local-options (concat "," local-options)))))
+ ;; Source code.
+ (format
+ "\\begin{lstlisting}\n%s\\end{lstlisting}"
+ (let* ((code-info (org-export-unravel-code src-block))
+ (max-width
+ (apply 'max
+ (mapcar 'length
+ (org-split-string (car code-info) "\n")))))
+ (org-export-format-code
+ (car code-info)
+ (lambda (loc _num ref)
+ (concat
+ loc
+ (when ref
+ ;; Ensure references are flushed to the right,
+ ;; separated with 6 spaces from the widest line of
+ ;; code
+ (concat (make-string (+ (- max-width (length loc)) 6) ?\s)
+ (format "(%s)" ref)))))
+ nil (and retain-labels (cdr code-info))))))))
;;;; Statistics Cookie
--
2.35.3
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #3: 0002-ox-latex-Refactor-org-latex-inline-src-block.patch --]
[-- Type: text/x-patch, Size: 4018 bytes --]
From 6635b72356192c3b0be500984b327d0b4ebd8e2b Mon Sep 17 00:00:00 2001
From: TEC <tec@tecosaur.com>
Date: Wed, 4 May 2022 18:53:10 +0800
Subject: [PATCH 02/13] ox-latex: Refactor `org-latex-inline-src-block'
* lisp/ox-latex.el (org-latex-inline-src-block,
org-latex-inline-src-block--minted,
org-latex-inline-src-block--listings): Extract the minted and listings
specific logic out of `org-latex-inline-src-block` into the new
functions `org-latex-inline-src-block--minted` and
`org-latex-inline-src-block--listings`.
---
lisp/ox-latex.el | 62 +++++++++++++++++++++++++-----------------------
1 file changed, 32 insertions(+), 30 deletions(-)
diff --git a/lisp/ox-latex.el b/lisp/ox-latex.el
index c2f728a1c..38f36a1f3 100644
--- a/lisp/ox-latex.el
+++ b/lisp/ox-latex.el
@@ -2127,36 +2127,38 @@ (defun org-latex-inline-src-block (inline-src-block _contents info)
"Transcode an INLINE-SRC-BLOCK element from Org to LaTeX.
CONTENTS holds the contents of the item. INFO is a plist holding
contextual information."
- (let* ((code (org-element-property :value inline-src-block))
- (separator (org-latex--find-verb-separator code)))
- (cl-case (plist-get info :latex-listings)
- ;; Do not use a special package: transcode it verbatim, as code.
- ((nil) (org-latex--text-markup code 'code info))
- ;; Use minted package.
- (minted
- (let* ((org-lang (org-element-property :language inline-src-block))
- (mint-lang (or (cadr (assq (intern org-lang)
- (plist-get info :latex-minted-langs)))
- (downcase org-lang)))
- (options (org-latex--make-option-string
- (plist-get info :latex-minted-options))))
- (format "\\mintinline%s{%s}{%s}"
- (if (string= options "") "" (format "[%s]" options))
- mint-lang
- code)))
- ;; Use listings package.
- (otherwise
- ;; Maybe translate language's name.
- (let* ((org-lang (org-element-property :language inline-src-block))
- (lst-lang (or (cadr (assq (intern org-lang)
- (plist-get info :latex-listings-langs)))
- org-lang))
- (options (org-latex--make-option-string
- (append (plist-get info :latex-listings-options)
- `(("language" ,lst-lang))))))
- (concat (format "\\lstinline[%s]" options)
- separator code separator))))))
-
+ (let ((code (org-element-property :value inline-src-block))
+ (lang (org-element-property :language inline-src-block)))
+ (pcase (plist-get info :latex-listings)
+ ('nil (org-latex--text-markup code 'code info))
+ ('minted (org-latex-inline-src-block--minted info code lang))
+ (_ (org-latex-inline-src-block--listings info code lang)))))
+
+(defun org-latex-inline-src-block--minted (info code lang)
+ "Transcode an inline src block's content from Org to LaTeX, using minted.
+INFO, CODE, and LANG are provided by `org-latex-inline-src-block'."
+ (let ((mint-lang (or (cadr (assq (intern lang)
+ (plist-get info :latex-minted-langs)))
+ (downcase lang)))
+ (options (org-latex--make-option-string
+ (plist-get info :latex-minted-options))))
+ (format "\\mintinline%s{%s}{%s}"
+ (if (string= options "") "" (format "[%s]" options))
+ mint-lang
+ code)))
+
+(defun org-latex-inline-src-block--listings (info code lang)
+ "Transcode an inline src block's content from Org to LaTeX, using lstlistings.
+INFO, CODE, and LANG are provided by `org-latex-inline-src-block'."
+ (let* ((lst-lang (or (cadr (assq (intern lang)
+ (plist-get info :latex-listings-langs)))
+ lang))
+ (separator (org-latex--find-verb-separator code))
+ (options (org-latex--make-option-string
+ (append (plist-get info :latex-listings-options)
+ `(("language" ,lst-lang))))))
+ (concat (format "\\lstinline[%s]" options)
+ separator code separator)))
;;;; Inlinetask
--
2.35.3
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #4: 0003-ox-latex-More-versitile-option-construction.patch --]
[-- Type: text/x-patch, Size: 4118 bytes --]
From 108f321a80de89c72974fc25fcde36c85023daca Mon Sep 17 00:00:00 2001
From: TEC <tec@tecosaur.com>
Date: Wed, 4 May 2022 23:31:59 +0800
Subject: [PATCH 03/13] ox-latex: More versitile option construction
* lisp/ox-latex.el (org-latex--make-option-string): Support a custom
option seperator string.
(org-latex--make-option-string, org-latex-minted-options,
org-latex-listings-options): The first line of the docstrings for
`org-latex-minted-options` and `org-latex-listings-options` describe the
variables as "association lists", yet `org-latex--make-option-string`
does not handle association lists and an example of two-value lists is
provided. To make the behaviour match the docstring,
`org-latex--make-option-string` is modified to work with either a list
two-value lists or an association list, and the examples in
`org-latex-minted-options` and `org-latex-listings-options` updated
accordingly.
---
lisp/ox-latex.el | 38 ++++++++++++++++++++++++--------------
1 file changed, 24 insertions(+), 14 deletions(-)
diff --git a/lisp/ox-latex.el b/lisp/ox-latex.el
index 38f36a1f3..2d4b3bace 100644
--- a/lisp/ox-latex.el
+++ b/lisp/ox-latex.el
@@ -1006,12 +1006,16 @@ (defcustom org-latex-listings-options nil
These options are supplied as a comma-separated list to the
\\lstset command. Each element of the association list should be
-a list containing two strings: the name of the option, and the
-value. For example,
+a list or cons cell containing two strings: the name of the
+option, and the value. For example,
(setq org-latex-listings-options
\\='((\"basicstyle\" \"\\\\small\")
(\"keywordstyle\" \"\\\\color{black}\\\\bfseries\\\\underbar\")))
+ ; or
+ (setq org-latex-listings-options
+ \\='((\"basicstyle\" . \"\\\\small\")
+ (\"keywordstyle\" . \"\\\\color{black}\\\\bfseries\\\\underbar\")))
will typeset the code in a small size font with underlined, bold
black keywords.
@@ -1059,11 +1063,14 @@ (defcustom org-latex-minted-options nil
These options are supplied within square brackets in
\\begin{minted} environments. Each element of the alist should
-be a list containing two strings: the name of the option, and the
-value. For example,
+be a list or cons cell containing two strings: the name of the
+option, and the value. For example,
(setq org-latex-minted-options
\\='((\"bgcolor\" \"bg\") (\"frame\" \"lines\")))
+ ; or
+ (setq org-latex-minted-options
+ \\='((\"bgcolor\" . \"bg\") (\"frame\" . \"lines\")))
will result in source blocks being exported with
@@ -1506,21 +1513,24 @@ (defun org-latex--find-verb-separator (s)
when (not (string-match (regexp-quote (char-to-string c)) s))
return (char-to-string c))))
-(defun org-latex--make-option-string (options)
+(defun org-latex--make-option-string (options &optional seperator)
"Return a comma separated string of keywords and values.
OPTIONS is an alist where the key is the options keyword as
a string, and the value a list containing the keyword value, or
nil."
(mapconcat (lambda (pair)
- (pcase-let ((`(,keyword ,value) pair))
- (concat keyword
- (and (> (length value) 0)
- (concat "="
- (if (string-match-p (rx (any "[]")) value)
- (format "{%s}" value)
- value))))))
- options
- ","))
+ (let ((keyword (car pair))
+ (value (pcase (cdr pair)
+ ((pred stringp) (cdr pair))
+ ((pred consp) (cadr pair)))))
+ (concat keyword
+ (when value
+ (concat "="
+ (if (string-match-p (rx (any "[]")) value)
+ (format "{%s}" value)
+ value))))))
+ options
+ (or seperator ",")))
(defun org-latex--wrap-label (element output info)
"Wrap label associated to ELEMENT around OUTPUT, if appropriate.
--
2.35.3
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #5: 0004-ox-latex-Introduce-engraved-code-highlighting.patch --]
[-- Type: text/x-patch, Size: 17857 bytes --]
From ac29f0f3991faf457f161698b4ad311edfe5d55d Mon Sep 17 00:00:00 2001
From: TEC <tec@tecosaur.com>
Date: Sun, 21 Nov 2021 20:04:12 +0800
Subject: [PATCH 04/13] ox-latex: Introduce "engraved" code highlighting
* lisp/ox-latex.el (org-latex-src-block, org-latex-src-block--engraved,
org-latex-inline-src-block, org-latex-inline-src-block--engraved,
org-latex-src--engrave-code, org-latex-template, org-latex-listings):
Make use of the engraved-faces package (available on ELPA) to provide an
alternative LaTeX code highlighting backend which functions similarly to
htmlize.el for HTML exports.
(org-latex-engraved-preamble, org-latex-engraved-options): Introduce
variables to construct the preamble for engraved code blocks.
* lisp/ox-beamer.el (org-beamer-template): Modify to add engrave-faces
preamble when applicable.
---
lisp/ox-beamer.el | 6 +
lisp/ox-latex.el | 292 ++++++++++++++++++++++++++++++++++++++++++++--
2 files changed, 289 insertions(+), 9 deletions(-)
diff --git a/lisp/ox-beamer.el b/lisp/ox-beamer.el
index 6be73c91e..fe73bf686 100644
--- a/lisp/ox-beamer.el
+++ b/lisp/ox-beamer.el
@@ -857,6 +857,12 @@ (defun org-beamer-template (contents info)
(let ((template (plist-get info :latex-hyperref-template)))
(and (stringp template)
(format-spec template (org-latex--format-spec info))))
+ ;; engrave-faces-latex preamble
+ (when (and (eq org-latex-listings 'engraved)
+ (org-element-map (plist-get info :parse-tree)
+ '(src-block inline-src-block) #'identity
+ info t))
+ (org-latex-generate-engraved-preamble info t))
;; Document start.
"\\begin{document}\n\n"
;; Title command.
diff --git a/lisp/ox-latex.el b/lisp/ox-latex.el
index 2d4b3bace..e0f47cf80 100644
--- a/lisp/ox-latex.el
+++ b/lisp/ox-latex.el
@@ -37,6 +37,8 @@ (defvar org-latex-default-packages-alist)
(defvar org-latex-packages-alist)
(defvar orgtbl-exp-regexp)
+(declare-function engrave-faces-latex-gen-preamble "ext:engrave-faces-latex")
+(declare-function engrave-faces-latex-buffer "ext:engrave-faces-latex")
\f
;;; Define Back-End
@@ -125,6 +127,8 @@ (org-export-define-backend 'latex
(:latex-default-quote-environment nil nil org-latex-default-quote-environment)
(:latex-default-table-mode nil nil org-latex-default-table-mode)
(:latex-diary-timestamp-format nil nil org-latex-diary-timestamp-format)
+ (:latex-engraved-options nil nil org-latex-engraved-options)
+ (:latex-engraved-preamble nil nil org-latex-engraved-preamble)
(:latex-footnote-defined-format nil nil org-latex-footnote-defined-format)
(:latex-footnote-separator nil nil org-latex-footnote-separator)
(:latex-format-drawer-function nil nil org-latex-format-drawer-function)
@@ -937,22 +941,48 @@ (defcustom org-latex-listings nil
"Non-nil means export source code using the listings package.
This package will fontify source code, possibly even with color.
-If you want to use this, you also need to make LaTeX use the
-listings package, and if you want to have color, the color
-package. Just add these to `org-latex-packages-alist', for
-example using customize, or with something like:
+There are four implementations of this functionality you may
+choose from (ordered from least to most capable):
+1. Verbatim (nil)
+2. Listings (t)
+3. Minted (minted)
+4. Engraved (engraved)
+
+The first two options provide basic syntax
+highlighting (listings), or none at all (verbatim).
+
+When using listings, you also need to make use of the LaTeX
+\"listings\" package. The \"color\" package is also needed if you
+would like color too. These can simply be added to
+`org-latex-packages-alist', using customise or something like:
(require \\='ox-latex)
(add-to-list \\='org-latex-packages-alist \\='(\"\" \"listings\"))
(add-to-list \\='org-latex-packages-alist \\='(\"\" \"color\"))
-Alternatively,
+There are two further options for more comprehensive
+fontification. The first can be set with,
+
+ (setq org-latex-listings \\='engraved)
+
+which causes source code to be run through
+`engrave-faces-latex-buffer', which generates colorings using
+Emacs' font-lock information. This requires the engrave-faces
+package (availible from ELPA), and the fvextra LaTeX package be
+installed.
+
+The styling of the engraved result can customised with
+`org-latex-engraved-preamble' and `org-latex-engraved-options'.
+The default preamble also uses the tcolorbox LaTeX package in
+addition to fvextra.
+
+The second more comprehensive option can be set with,
(setq org-latex-listings \\='minted)
-causes source code to be exported using the minted package as
-opposed to listings. If you want to use minted, you need to add
-the minted package to `org-latex-packages-alist', for example
+which causes source code to be exported using the minted package
+as opposed to listings. If you want to use minted, you need to
+add the minted package to `org-latex-packages-alist', for example
using customize, or with
(require \\='ox-latex)
@@ -971,8 +1001,9 @@ (defcustom org-latex-listings nil
:type '(choice
(const :tag "Use listings" t)
(const :tag "Use minted" minted)
+ (const :tag "Use engrave-faces-latex" engraved)
(const :tag "Export verbatim" nil))
- :safe (lambda (s) (memq s '(t nil minted))))
+ :safe (lambda (s) (memq s '(t nil minted engraved))))
(defcustom org-latex-listings-langs
'((emacs-lisp "Lisp") (lisp "Lisp") (clojure "Lisp")
@@ -1142,6 +1173,151 @@ (defcustom org-latex-custom-lang-environments nil
:version "26.1"
:package-version '(Org . "9.0"))
+(defcustom org-latex-engraved-preamble
+ "\\usepackage{fvextra}
+
+[FVEXTRA-SETUP]
+
+% Make line numbers smaller and grey.
+\\renewcommand\\theFancyVerbLine{\\footnotesize\\color{black!40!white}\\arabic{FancyVerbLine}}
+
+\\usepackage{xcolor}
+
+% In case engrave-faces-latex-gen-preamble has not been run.
+\\providecolor{EfD}{HTML}{f7f7f7}
+\\providecolor{EFD}{HTML}{28292e}
+
+% Define a Code environment to prettily wrap the fontified code.
+\\usepackage[breakable,xparse]{tcolorbox}
+\\DeclareTColorBox[]{Code}{o}%
+{colback=EfD!98!EFD, colframe=EfD!95!EFD,
+ fontupper=\\footnotesize\\setlength{\\fboxsep}{0pt},
+ colupper=EFD,
+ IfNoValueTF={#1}%
+ {boxsep=2pt, arc=2.5pt, outer arc=2.5pt,
+ boxrule=0.5pt, left=2pt}%
+ {boxsep=2.5pt, arc=0pt, outer arc=0pt,
+ boxrule=0pt, leftrule=1.5pt, left=0.5pt},
+ right=2pt, top=1pt, bottom=0.5pt,
+ breakable}
+
+[LISTINGS-SETUP]"
+ "Preamble content injected when using engrave-faces-latex for source blocks.
+This is relevant when `org-latex-listings' is set to `engraved'.
+
+There is quite a lot of flexibility in what this preamble can be,
+as long as it:
+- Loads the fvextra package.
+- Loads the package xcolor (if it is not already loaded elsewhere).
+- Defines a \"Code\" environment (note the capital C), which all
+ \"Verbatim\" environments (provided by fvextra) will be wrapped with.
+
+In the default value the colors \"EFD\" and \"EfD\" are provided
+as they are respectively the foreground and background colours,
+just in case they aren't provided by the generated preamble, so
+we can asume they are always set.
+
+Within this preamble there are two recognised macro-like placeholders:
+
+ [FVEXTRA-SETUP]
+
+ [LISTINGS-SETUP]
+
+Unless you have a very good reason, both of these placeholders
+should be included in the preamble.
+
+FVEXTRA-SETUP sets fvextra's defaults according to
+`org-latex-engraved-options', and LISTINGS-SETUP creates the
+listings environment used for captioned or floating code blocks,
+as well as defining \\listoflistings."
+ :group 'org-export-latex
+ :type 'string
+ :package-version '(Org . "9.6"))
+
+(defcustom org-latex-engraved-options
+ '(("commandchars" . "\\\\\\{\\}")
+ ("highlightcolor" . "white!95!black!80!blue")
+ ("breaklines" . "true")
+ ("breaksymbol" . "\\color{white!60!black}\\tiny\\ensuremath{\\hookrightarrow}"))
+ "Association list of options for the latex fvextra package when engraving code.
+
+These options are set using \\fvset{...} in the preamble of the
+LaTeX export. Each element of the alist should be a list or cons
+cell containing two strings: the name of the option, and the
+value. For example,
+
+ (setq org-latex-engraved-options
+ \\='((\"highlightcolor\" \"green\") (\"frame\" \"lines\")))
+ ; or
+ (setq org-latex-engraved-options
+ \\='((\"highlightcolor\" . \"green\") (\"frame\" . \"lines\")))
+
+will result in the following LaTeX in the preamble
+
+\\fvset{%
+ bgcolor=bg,
+ frame=lines}
+
+This will affect all fvextra environments. Note that the same
+options will be applied to all blocks. If you need
+block-specific options, you may use the following syntax:
+
+ #+ATTR_LATEX: :options key1=value1,key2=value2
+ #+BEGIN_SRC <LANG>
+ ...
+ #+END_SRC"
+ :group 'org-export-latex
+ :type '(alist :key-type (string :tag "option")
+ :value-type (string :tag "value")))
+
+(defun org-latex-generate-engraved-preamble (info syntax-colours-p)
+ "Generate the preamble to setup engraved code.
+The result is constructed from the :latex-engraved-preamble and
+:latex-engraved-optionsn export options, the default values of
+which are given by `org-latex-engraved-preamble' and
+`org-latex-engraved-options' respectively."
+ (let* ((engraved-options
+ (plist-get info :latex-engraved-options))
+ (engraved-preamble (plist-get info :latex-engraved-preamble)))
+ (when (string-match "^[ \t]*\\[FVEXTRA-SETUP\\][ \t]*\n?" engraved-preamble)
+ (setq engraved-preamble
+ (replace-match
+ (concat
+ "\\fvset{%\n "
+ (org-latex--make-option-string engraved-options ",\n ")
+ "}\n")
+ t t
+ engraved-preamble)))
+ (when (string-match "^[ \t]*\\[LISTINGS-SETUP\\][ \t]*\n?" engraved-preamble)
+ (setq engraved-preamble
+ (replace-match
+ (format
+ "%% Support listings with captions
+\\usepackage{float}
+\\floatstyle{%s}
+\\newfloat{listing}{htbp}{lst}
+\\newcommand{\\listingsname}{Listing}
+\\floatname{listing}{\\listingsname}
+\\newcommand{\\listoflistingsname}{List of Listings}
+\\providecommand{\\listoflistings}{\\listof{listing}{\\listoflistingsname}}\n"
+ (if (memq 'src-block org-latex-caption-above)
+ "plaintop" "plain"))
+ t t
+ engraved-preamble)))
+ (if syntax-colours-p
+ (concat
+ "\n% Setup for code blocks [1/2]\n\n"
+ engraved-preamble
+ "\n\n% Setup for code blocks [2/2]: syntax highlighting colors\n"
+ (if (require 'engrave-faces-latex nil t)
+ (engrave-faces-latex-gen-preamble)
+ (message "Cannot engrave source blocks. Consider installing `engrave-faces'.")
+ "% WARNING syntax highlighting unavailible as engrave-faces-latex was missing.\n")
+ "\n")
+ (concat
+ "\n% Setup for code blocks\n\n"
+ engraved-preamble
+ "\n"))))
;;;; Compilation
@@ -1756,6 +1932,12 @@ (defun org-latex-template (contents info)
(let ((template (plist-get info :latex-hyperref-template)))
(and (stringp template)
(format-spec template spec)))
+ ;; engrave-faces-latex preamble
+ (when (and (eq org-latex-listings 'engraved)
+ (org-element-map (plist-get info :parse-tree)
+ '(src-block inline-src-block) #'identity
+ info t))
+ (org-latex-generate-engraved-preamble info t))
;; Document start.
"\\begin{document}\n\n"
;; Title command.
@@ -2142,6 +2324,7 @@ (defun org-latex-inline-src-block (inline-src-block _contents info)
(pcase (plist-get info :latex-listings)
('nil (org-latex--text-markup code 'code info))
('minted (org-latex-inline-src-block--minted info code lang))
+ ('engraved (org-latex-inline-src-block--engraved info code lang))
(_ (org-latex-inline-src-block--listings info code lang)))))
(defun org-latex-inline-src-block--minted (info code lang)
@@ -2157,6 +2340,11 @@ (defun org-latex-inline-src-block--minted (info code lang)
mint-lang
code)))
+(defun org-latex-inline-src-block--engraved (_info code lang)
+ "Transcode an inline src block's content from Org to LaTeX, using engrave-faces.
+INFO, CODE, and LANG are provided by `org-latex-inline-src-block'."
+ (format "\\Verb{%s}" (org-latex-src--engrave-code code lang)))
+
(defun org-latex-inline-src-block--listings (info code lang)
"Transcode an inline src block's content from Org to LaTeX, using lstlistings.
INFO, CODE, and LANG are provided by `org-latex-inline-src-block'."
@@ -2323,6 +2511,7 @@ (defun org-latex-keyword (keyword _contents info)
(cl-case (plist-get info :latex-listings)
((nil) "\\listoffigures")
(minted "\\listoflistings")
+ (engraved "\\listoflistings")
(otherwise "\\lstlistoflistings")))))))))
@@ -3017,6 +3206,9 @@ (defun org-latex-src-block (src-block _contents info)
num-start retain-labels attributes float custom-env))
((eq listings 'minted)
(org-latex-src-block--minted src-block info lang caption caption-above-p label
+ num-start retain-labels attributes float))
+ ((eq listings 'engraved)
+ (org-latex-src-block--engraved src-block info lang caption caption-above-p label
num-start retain-labels attributes float))
(t
(org-latex-src-block--listings src-block info lang caption caption-above-p label
@@ -3133,6 +3325,88 @@ (defun org-latex-src-block--minted
;; Return value.
(format float-env body)))
+(defun org-latex-src--engrave-code (content lang)
+ "Engrave CONTENT to LaTeX in a LANG-mode buffer, and give the result."
+ (if (require 'engrave-faces-latex nil t)
+ (let* ((lang-mode (and lang (org-src-get-lang-mode lang)))
+ (engraved-buffer
+ (with-temp-buffer
+ (insert content)
+ (when lang-mode
+ (if (functionp lang-mode)
+ (funcall lang-mode)
+ (message "Cannot engrave code as %s. %s is undefined."
+ lang lang-mode)))
+ (engrave-faces-latex-buffer)))
+ (engraved-code
+ (with-current-buffer engraved-buffer
+ (buffer-string))))
+ (kill-buffer engraved-buffer)
+ engraved-code)
+ (user-error "Cannot engrave code as `engrave-faces-latex' is unavailible.")))
+
+(defun org-latex-src-block--engraved
+ (src-block info lang caption caption-above-p _label
+ num-start retain-labels attributes float)
+ "Transcode a SRC-BLOCK element from Org to LaTeX, using engrave-faces-latex.
+LANG, CAPTION, CAPTION-ABOVE-P, LABEL, NUM-START, RETAIN-LABELS, ATTRIBUTES
+and FLOAT are extracted from SRC-BLOCK and INFO in `org-latex-src-block'."
+ (let* ((caption-str (org-latex--caption/label-string src-block info))
+ (placement (or (org-unbracket-string "[" "]" (plist-get attributes :placement))
+ (plist-get info :latex-default-figure-position)))
+ (float-env
+ (cond
+ ((string= "multicolumn" float)
+ (format "\\begin{listing*}[%s]\n%s%%s\n%s\\end{listing*}"
+ placement
+ (if caption-above-p caption-str "")
+ (if caption-above-p "" caption-str)))
+ (caption
+ (format "\\begin{listing}[%s]\n%s%%s\n%s\\end{listing}"
+ placement
+ (if caption-above-p caption-str "")
+ (if caption-above-p "" caption-str)))
+ ((string= "t" float)
+ (concat (format "\\begin{listing}[%s]\n"
+ placement)
+ "%s\n\\end{listing}"))
+ (t "%s")))
+ (options (plist-get info :latex-engraved-options))
+ (content
+ (let* ((code-info (org-export-unravel-code src-block))
+ (max-width
+ (apply 'max
+ (mapcar 'string-width
+ (org-split-string (car code-info)
+ "\n")))))
+ (org-export-format-code
+ (car code-info)
+ (lambda (loc _num ref)
+ (concat
+ loc
+ (when ref
+ ;; Ensure references are flushed to the right,
+ ;; separated with 6 spaces from the widest line
+ ;; of code.
+ (concat (make-string (+ (- max-width (length loc)) 6)
+ ?\s)
+ (format "(%s)" ref)))))
+ nil (and retain-labels (cdr code-info)))))
+ (body
+ (format
+ "\\begin{Code}\n\\begin{Verbatim}[%s]\n%s\\end{Verbatim}\n\\end{Code}"
+ ;; Options.
+ (concat
+ (org-latex--make-option-string
+ (append
+ (when (and num-start (not (assoc "linenos" options)))
+ `(("linenos")
+ ("firstnumber" ,(number-to-string (1+ num-start)))))
+ (let ((local-options (plist-get attributes :options)))
+ (and local-options (list local-options))))))
+ (org-latex-src--engrave-code content lang))))
+ (format float-env body)))
+
(defun org-latex-src-block--listings
(src-block info lang caption caption-above-p label
num-start retain-labels attributes float)
--
2.35.3
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #6: 0005-ox-latex-Don-t-use-length-to-get-string-width.patch --]
[-- Type: text/x-patch, Size: 1539 bytes --]
From 815de46384a566b3dcd86061b9aa93563a7acb29 Mon Sep 17 00:00:00 2001
From: TEC <tec@tecosaur.com>
Date: Sat, 7 May 2022 13:59:13 +0800
Subject: [PATCH 05/13] ox-latex: Don't use `length' to get string width
* lisp/ox-latex.el (org-latex-src-block--listings,
org-latex-src-block--engraved, org-latex-src-block--minted): Use
`string-width' instead of `length' to gauge the displayed width of the
string in LaTeX. This may not be a perfect match, but it should be an
improvement.
---
lisp/ox-latex.el | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/lisp/ox-latex.el b/lisp/ox-latex.el
index e0f47cf80..0788b40c0 100644
--- a/lisp/ox-latex.el
+++ b/lisp/ox-latex.el
@@ -3306,7 +3306,7 @@ (defun org-latex-src-block--minted
(let* ((code-info (org-export-unravel-code src-block))
(max-width
(apply 'max
- (mapcar 'length
+ (mapcar 'string-width
(org-split-string (car code-info)
"\n")))))
(org-export-format-code
@@ -3458,7 +3458,7 @@ (defun org-latex-src-block--listings
(let* ((code-info (org-export-unravel-code src-block))
(max-width
(apply 'max
- (mapcar 'length
+ (mapcar 'string-width
(org-split-string (car code-info) "\n")))))
(org-export-format-code
(car code-info)
--
2.35.3
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #7: 0006-ox-latex-Refactor-source-block-transcode-fun-sigs.patch --]
[-- Type: text/x-patch, Size: 7299 bytes --]
From fadf2011884d0e46b5442ec43dc942050e2fd048 Mon Sep 17 00:00:00 2001
From: TEC <tec@tecosaur.com>
Date: Sat, 7 May 2022 14:02:44 +0800
Subject: [PATCH 06/13] ox-latex: Refactor source block transcode fun sigs
* lisp/ox-latex.el (org-latex-src-block--listings,
org-latex-src-block--engraved, org-latex-src-block--minted,
org-latex-src-block--custom): Refactor these --backend functions to use
cl-defun with keys instead of having an 11-argument signature.
(org-latex-src-block): Adjust for the change in signature of the
--backend functions, and refactor the `cond' statement to use `pcase'.
---
lisp/ox-latex.el | 82 +++++++++++++++++++++++-------------------------
1 file changed, 39 insertions(+), 43 deletions(-)
diff --git a/lisp/ox-latex.el b/lisp/ox-latex.el
index 0788b40c0..4a077bb27 100644
--- a/lisp/ox-latex.el
+++ b/lisp/ox-latex.el
@@ -3186,37 +3186,37 @@ (defun org-latex-src-block (src-block _contents info)
contextual information."
(when (org-string-nw-p (org-element-property :value src-block))
(let* ((lang (org-element-property :language src-block))
- (caption (org-element-property :caption src-block))
- (caption-above-p (org-latex--caption-above-p src-block info))
- (label (org-element-property :name src-block))
- (custom-env (and lang
- (cadr (assq (intern lang)
- org-latex-custom-lang-environments))))
- (num-start (org-export-get-loc src-block info))
- (retain-labels (org-element-property :retain-labels src-block))
- (attributes (org-export-read-attribute :attr_latex src-block))
- (float (plist-get attributes :float))
- (listings (plist-get info :latex-listings)))
- (cond
- ((or (not lang) (not listings))
- (org-latex-src-block--verbatim src-block info lang caption caption-above-p label
- num-start retain-labels attributes float))
- (custom-env
- (org-latex-src-block--custom src-block info lang caption caption-above-p label
- num-start retain-labels attributes float custom-env))
- ((eq listings 'minted)
- (org-latex-src-block--minted src-block info lang caption caption-above-p label
- num-start retain-labels attributes float))
- ((eq listings 'engraved)
- (org-latex-src-block--engraved src-block info lang caption caption-above-p label
- num-start retain-labels attributes float))
- (t
- (org-latex-src-block--listings src-block info lang caption caption-above-p label
- num-start retain-labels attributes float))))))
-
-(defun org-latex-src-block--verbatim
- (src-block info _lang caption caption-above-p _label
- _num-start _retain-labels _attributes float)
+ (caption (org-element-property :caption src-block))
+ (caption-above-p (org-latex--caption-above-p src-block info))
+ (label (org-element-property :name src-block))
+ (custom-env (and lang
+ (cadr (assq (intern lang)
+ org-latex-custom-lang-environments))))
+ (num-start (org-export-get-loc src-block info))
+ (retain-labels (org-element-property :retain-labels src-block))
+ (attributes (org-export-read-attribute :attr_latex src-block))
+ (float (plist-get attributes :float))
+ (listings (plist-get info :latex-listings)))
+ (funcall
+ (pcase listings
+ ((or (pred not) (guard (not lang))) #'org-latex-src-block--verbatim)
+ ((guard custom-env) #'org-latex-src-block--custom)
+ ('minted #'org-latex-src-block--minted)
+ ('engraved #'org-latex-src-block--engraved)
+ (_ #'org-latex-src-block--listings))
+ :src-block src-block
+ :info info
+ :lang lang
+ :caption caption
+ :caption-above-p caption-above-p
+ :label label
+ :num-start num-start
+ :retain-labels retain-labels
+ :attributes attributes
+ :float float))))
+
+(cl-defun org-latex-src-block--verbatim
+ (&key src-block info caption caption-above-p float &allow-other-keys)
"Transcode a SRC-BLOCK element from Org to LaTeX, using verbatim.
LANG, CAPTION, CAPTION-ABOVE-P, LABEL, NUM-START, RETAIN-LABELS, ATTRIBUTES
and FLOAT are extracted from SRC-BLOCK and INFO in `org-latex-src-block'."
@@ -3235,9 +3235,8 @@ (defun org-latex-src-block--verbatim
(if caption-above-p "" (concat "\n" caption-str))))
(t verbatim))))
-(defun org-latex-src-block--custom
- (src-block info _lang caption caption-above-p _label
- _num-start _retain-labels attributes float custom-env)
+(cl-defun org-latex-src-block--custom
+ (&key src-block info caption caption-above-p attributes float custom-env &allow-other-keys)
"Transcode a SRC-BLOCK element from Org to LaTeX, using a custom environment.
LANG, CAPTION, CAPTION-ABOVE-P, LABEL, NUM-START, RETAIN-LABELS, ATTRIBUTES
and FLOAT are extracted from SRC-BLOCK and INFO in `org-latex-src-block'."
@@ -3257,9 +3256,8 @@ (defun org-latex-src-block--custom
(?l . ,(org-latex--label src-block info))
(?o . ,(or (plist-get attributes :options) "")))))))
-(defun org-latex-src-block--minted
- (src-block info lang caption caption-above-p _label
- num-start retain-labels attributes float)
+(cl-defun org-latex-src-block--minted
+ (&key src-block info lang caption caption-above-p num-start retain-labels attributes float &allow-other-keys)
"Transcode a SRC-BLOCK element from Org to LaTeX, using minted.
LANG, CAPTION, CAPTION-ABOVE-P, LABEL, NUM-START, RETAIN-LABELS, ATTRIBUTES
and FLOAT are extracted from SRC-BLOCK and INFO in `org-latex-src-block'."
@@ -3345,9 +3343,8 @@ (defun org-latex-src--engrave-code (content lang)
engraved-code)
(user-error "Cannot engrave code as `engrave-faces-latex' is unavailible.")))
-(defun org-latex-src-block--engraved
- (src-block info lang caption caption-above-p _label
- num-start retain-labels attributes float)
+(cl-defun org-latex-src-block--engraved
+ (&key src-block info lang caption caption-above-p num-start retain-labels attributes float &allow-other-keys)
"Transcode a SRC-BLOCK element from Org to LaTeX, using engrave-faces-latex.
LANG, CAPTION, CAPTION-ABOVE-P, LABEL, NUM-START, RETAIN-LABELS, ATTRIBUTES
and FLOAT are extracted from SRC-BLOCK and INFO in `org-latex-src-block'."
@@ -3407,9 +3404,8 @@ (defun org-latex-src-block--engraved
(org-latex-src--engrave-code content lang))))
(format float-env body)))
-(defun org-latex-src-block--listings
- (src-block info lang caption caption-above-p label
- num-start retain-labels attributes float)
+(cl-defun org-latex-src-block--listings
+ (&key src-block info lang caption caption-above-p label num-start retain-labels attributes float &allow-other-keys)
"Transcode a SRC-BLOCK element from Org to LaTeX, using listings.
LANG, CAPTION, CAPTION-ABOVE-P, LABEL, NUM-START, RETAIN-LABELS, ATTRIBUTES
and FLOAT are extracted from SRC-BLOCK and INFO in `org-latex-src-block'."
--
2.35.3
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #8: 0007-ox-latex-Replace-org-latex-listings.patch --]
[-- Type: text/x-patch, Size: 16239 bytes --]
From e6dfd941daf06beb859ae6effd0be9d734121897 Mon Sep 17 00:00:00 2001
From: TEC <tec@tecosaur.com>
Date: Sat, 7 May 2022 14:46:28 +0800
Subject: [PATCH 07/13] ox-latex: Replace `org-latex-listings'
* lisp/ox-latex.el (org-latex-src-block, org-latex-keyword,
org-latex-inline-src-block, org-latex-template,
org-latex--caption/label-string, org-latex-engraved-preamble,
org-latex-listings): Replace `org-latex-listings' with
`org-latex-src-block-backend', which now can be set to listings/verbatim
and no longer advertises t/nil as valid values.
* lisp/ox-beamer.el (org-beamer-template): Update in the same manner as
`org-latex-template'.
* lisp/org-compat.el: Make `org-latex-listings' an obsolete alias for
`org-latex-src-block-backend'.
* testing/lisp/test-ox.el: Replace `org-latex-listings' reference with
`org-latex-src-block-backend'.
* doc/org-manual.org (Footnotes, LaTeX specific properties, Literal
Examples): Replace references to `org-latex-listings' with
`org-latex-src-block-backend'.
* etc/ORG-NEWS: Add a news entry noting this change.
The variable `org-latex-listings' originally indicated whether source
blocks should use the listings LaTeX package, or not. This usage has
evolved over the years, and now it sets one of four different
fontification backends. This renaming should make the variable name a
bit less misleading.
---
doc/org-manual.org | 6 +--
etc/ORG-NEWS | 9 ++++
lisp/org-compat.el | 2 +
lisp/ox-beamer.el | 2 +-
lisp/ox-latex.el | 117 ++++++++++++++++++++++------------------
testing/lisp/test-ox.el | 2 +-
6 files changed, 81 insertions(+), 57 deletions(-)
diff --git a/doc/org-manual.org b/doc/org-manual.org
index c0d38cd8c..60bded419 100644
--- a/doc/org-manual.org
+++ b/doc/org-manual.org
@@ -11159,7 +11159,7 @@ ** Literal Examples
#+end_example
#+cindex: formatting source code, markup rules
-#+vindex: org-latex-listings
+#+vindex: org-latex-src-block-backend
If the example is source code from a programming language, or any
other text that can be marked up by Font Lock in Emacs, you can ask
for the example to look like the fontified Emacs buffer[fn:114]. This
@@ -16304,12 +16304,12 @@ **** LaTeX specific properties
| ~:latex-link-with-unknown-path-format~ | ~org-latex-link-with-unknown-path-format~ |
| ~:latex-listings-langs~ | ~org-latex-listings-langs~ |
| ~:latex-listings-options~ | ~org-latex-listings-options~ |
-| ~:latex-listings~ | ~org-latex-listings~ |
| ~:latex-minted-langs~ | ~org-latex-minted-langs~ |
| ~:latex-minted-options~ | ~org-latex-minted-options~ |
| ~:latex-prefer-user-labels~ | ~org-latex-prefer-user-labels~ |
| ~:latex-subtitle-format~ | ~org-latex-subtitle-format~ |
| ~:latex-subtitle-separate~ | ~org-latex-subtitle-separate~ |
+| ~:latex-src-block-backend~ | ~org-latex-src-block-backend~ |
| ~:latex-table-scientific-notation~ | ~org-latex-table-scientific-notation~ |
| ~:latex-tables-booktabs~ | ~org-latex-tables-booktabs~ |
| ~:latex-tables-centered~ | ~org-latex-tables-centered~ |
@@ -22256,7 +22256,7 @@ * Footnotes
version 1.34 of the =htmlize.el= package, which you need to install).
Fontified code chunks in LaTeX can be achieved using either the
[[https://www.ctan.org/pkg/listings][listings]] package or the [[https://www.ctan.org/pkg/minted][minted]] package. Refer to
-~org-latex-listings~ for details.
+~org-latex-src-block-backend~ for details.
[fn:115] Source code in code blocks may also be evaluated either
interactively or on export. See [[*Working with Source Code]] for more
diff --git a/etc/ORG-NEWS b/etc/ORG-NEWS
index 27de6da62..ebb3cd649 100644
--- a/etc/ORG-NEWS
+++ b/etc/ORG-NEWS
@@ -273,6 +273,15 @@ Chmod-style permissions are based on the new variable
~org-babel-tangle-default-file-mode~.
*** A new custom setting =org-agenda-clock-report-header= to add a header to org agenda clock report
+
+*** ~org-latex-listings~ has been replaced with ~org-latex-src-block-backend~
+
+~org-latex-listings~ has been renamed to better reflect the current
+purpose of the variable. The replacement variable
+~org-latex-src-block-backend~ acts in exactly the same way, however it
+accepts =listings= and =verbatim= in place of =t= and =nil= (which
+still work, but are no longer listed as valid options).
+
* Version 9.5
** Important announcements and breaking changes
diff --git a/lisp/org-compat.el b/lisp/org-compat.el
index a29f206a4..704197645 100644
--- a/lisp/org-compat.el
+++ b/lisp/org-compat.el
@@ -324,6 +324,8 @@ (define-obsolete-variable-alias 'org-latex-create-formula-image-program
'org-preview-latex-default-process "9.0")
(define-obsolete-variable-alias 'org-latex-preview-ltxpng-directory
'org-preview-latex-image-directory "9.0")
+(define-obsolete-variable-alias 'org-latex-listings
+ 'org-latex-src-block-backend "9.6")
(define-obsolete-function-alias 'org-table-p 'org-at-table-p "9.0")
(define-obsolete-function-alias 'org-on-heading-p 'org-at-heading-p "9.0")
(define-obsolete-function-alias 'org-at-regexp-p 'org-in-regexp "8.3")
diff --git a/lisp/ox-beamer.el b/lisp/ox-beamer.el
index fe73bf686..e6232d8d2 100644
--- a/lisp/ox-beamer.el
+++ b/lisp/ox-beamer.el
@@ -858,7 +858,7 @@ (defun org-beamer-template (contents info)
(and (stringp template)
(format-spec template (org-latex--format-spec info))))
;; engrave-faces-latex preamble
- (when (and (eq org-latex-listings 'engraved)
+ (when (and (eq org-latex-src-block-backend 'engraved)
(org-element-map (plist-get info :parse-tree)
'(src-block inline-src-block) #'identity
info t))
diff --git a/lisp/ox-latex.el b/lisp/ox-latex.el
index 4a077bb27..f81625b45 100644
--- a/lisp/ox-latex.el
+++ b/lisp/ox-latex.el
@@ -143,7 +143,7 @@ (org-export-define-backend 'latex
(:latex-inactive-timestamp-format nil nil org-latex-inactive-timestamp-format)
(:latex-inline-image-rules nil nil org-latex-inline-image-rules)
(:latex-link-with-unknown-path-format nil nil org-latex-link-with-unknown-path-format)
- (:latex-listings nil nil org-latex-listings)
+ (:latex-src-block-backend nil nil org-latex-src-block-backend)
(:latex-listings-langs nil nil org-latex-listings-langs)
(:latex-listings-options nil nil org-latex-listings-options)
(:latex-minted-langs nil nil org-latex-minted-langs)
@@ -937,22 +937,22 @@ (defcustom org-latex-format-inlinetask-function
;; Src blocks
-(defcustom org-latex-listings nil
- "Non-nil means export source code using the listings package.
+(defcustom org-latex-src-block-backend 'verbatim
+ "Backend used to generate source code listings.
-This package will fontify source code, possibly even with color.
-There are four implementations of this functionality you may
+This sets the behaviour for fontifying source code, possibly even with
+color. There are four implementations of this functionality you may
choose from (ordered from least to most capable):
-1. Verbatim (nil)
-2. Listings (t)
-3. Minted (minted)
-4. Engraved (engraved)
+1. Verbatim
+2. Listings
+3. Minted
+4. Engraved
The first two options provide basic syntax
highlighting (listings), or none at all (verbatim).
-When using listings, you also need to make use of the LaTeX
-\"listings\" package. The \"color\" package is also needed if you
+When using listings, you also need to make use of LaTeX package
+\"listings\"e. The \"color\" LaTeX package is also needed if you
would like color too. These can simply be added to
`org-latex-packages-alist', using customise or something like:
@@ -963,27 +963,12 @@ (defcustom org-latex-listings nil
There are two further options for more comprehensive
fontification. The first can be set with,
- (setq org-latex-listings \\='engraved)
+ (setq org-latex-src-block-backend \\='minted)
-which causes source code to be run through
-`engrave-faces-latex-buffer', which generates colorings using
-Emacs' font-lock information. This requires the engrave-faces
-package (availible from ELPA), and the fvextra LaTeX package be
-installed.
-
-The styling of the engraved result can customised with
-`org-latex-engraved-preamble' and `org-latex-engraved-options'.
-The default preamble also uses the tcolorbox LaTeX package in
-addition to fvextra.
-
-The second more comprehensive option can be set with,
-
- (setq org-latex-listings \\='minted)
-
-which causes source code to be exported using the minted package
-as opposed to listings. If you want to use minted, you need to
-add the minted package to `org-latex-packages-alist', for example
-using customize, or with
+which causes source code to be exported using the LaTeX package
+minted as opposed to listings. If you want to use minted, you
+need to add the minted package to `org-latex-packages-alist', for
+example using customize, or with
(require \\='ox-latex)
(add-to-list \\='org-latex-packages-alist \\='(\"newfloat\" \"minted\"))
@@ -996,14 +981,29 @@ (defcustom org-latex-listings nil
The minted choice has possible repercussions on the preview of
latex fragments (see `org-preview-latex-fragment'). If you run
into previewing problems, please consult
-URL `https://orgmode.org/worg/org-tutorials/org-latex-preview.html'."
+URL `https://orgmode.org/worg/org-tutorials/org-latex-preview.html'.
+
+The most comprehensive option can be set with,
+
+ (setq org-latex-src-block-backend \\='engraved)
+
+which causes source code to be run through
+`engrave-faces-latex-buffer', which generates colorings using
+Emacs' font-lock information. This requires the Emacs package
+engrave-faces (availible from ELPA), and the LaTeX package
+fvextra be installed.
+
+The styling of the engraved result can customised with
+`org-latex-engraved-preamble' and `org-latex-engraved-options'.
+The default preamble also uses the LaTeX package tcolorbox in
+addition to fvextra."
:group 'org-export-latex
:type '(choice
- (const :tag "Use listings" t)
+ (const :tag "Use listings" listings)
(const :tag "Use minted" minted)
(const :tag "Use engrave-faces-latex" engraved)
- (const :tag "Export verbatim" nil))
- :safe (lambda (s) (memq s '(t nil minted engraved))))
+ (const :tag "Export verbatim" verbatim))
+ :safe (lambda (s) (memq s '(listings minted engraved verbatim))))
(defcustom org-latex-listings-langs
'((emacs-lisp "Lisp") (lisp "Lisp") (clojure "Lisp")
@@ -1203,7 +1203,7 @@ (defcustom org-latex-engraved-preamble
[LISTINGS-SETUP]"
"Preamble content injected when using engrave-faces-latex for source blocks.
-This is relevant when `org-latex-listings' is set to `engraved'.
+This is relevant when `org-latex-src-block-backend' is set to `engraved'.
There is quite a lot of flexibility in what this preamble can be,
as long as it:
@@ -1526,7 +1526,8 @@ (defun org-latex--caption/label-string (element info)
main)
(and (eq type 'src-block)
(not (plist-get attr :float))
- (null (plist-get info :latex-listings)))))
+ (memq (plist-get info :latex-src-block-backend)
+ '(verbatim nil)))))
(short (org-export-get-caption element t))
(caption-from-attr-latex (plist-get attr :caption)))
(cond
@@ -1546,7 +1547,8 @@ (defun org-latex--caption/label-string (element info)
(paragraph "figure")
(image "figure")
(special-block "figure")
- (src-block (if (plist-get info :latex-listings)
+ (src-block (if (not (memq (plist-get info :latex-src-block-backend)
+ '(verbatim nil)))
"listing"
"figure"))
(t (symbol-name type*)))
@@ -1933,7 +1935,7 @@ (defun org-latex-template (contents info)
(and (stringp template)
(format-spec template spec)))
;; engrave-faces-latex preamble
- (when (and (eq org-latex-listings 'engraved)
+ (when (and (eq org-latex-src-block-backend 'engraved)
(org-element-map (plist-get info :parse-tree)
'(src-block inline-src-block) #'identity
info t))
@@ -2321,11 +2323,17 @@ (defun org-latex-inline-src-block (inline-src-block _contents info)
contextual information."
(let ((code (org-element-property :value inline-src-block))
(lang (org-element-property :language inline-src-block)))
- (pcase (plist-get info :latex-listings)
- ('nil (org-latex--text-markup code 'code info))
- ('minted (org-latex-inline-src-block--minted info code lang))
- ('engraved (org-latex-inline-src-block--engraved info code lang))
- (_ (org-latex-inline-src-block--listings info code lang)))))
+ (pcase (plist-get info :latex-src-block-backend)
+ (`verbatim (org-latex--text-markup code 'code info))
+ (`minted (org-latex-inline-src-block--minted info code lang))
+ (`engraved (org-latex-inline-src-block--engraved info code lang))
+ (`listings (org-latex-inline-src-block--listings info code lang))
+ (oldval
+ (message "Please update the LaTeX src-block-backend to %s"
+ (if oldval "listings" "verbatim"))
+ (if oldval
+ (org-latex-inline-src-block--listings info code lang)
+ (org-latex--text-markup code 'code info))))))
(defun org-latex-inline-src-block--minted (info code lang)
"Transcode an inline src block's content from Org to LaTeX, using minted.
@@ -2508,7 +2516,7 @@ (defun org-latex-keyword (keyword _contents info)
(concat depth (and depth "\n") "\\tableofcontents"))))
((string-match-p "\\<tables\\>" value) "\\listoftables")
((string-match-p "\\<listings\\>" value)
- (cl-case (plist-get info :latex-listings)
+ (cl-case (plist-get info :latex-src-block-backend)
((nil) "\\listoffigures")
(minted "\\listoflistings")
(engraved "\\listoflistings")
@@ -3195,15 +3203,20 @@ (defun org-latex-src-block (src-block _contents info)
(num-start (org-export-get-loc src-block info))
(retain-labels (org-element-property :retain-labels src-block))
(attributes (org-export-read-attribute :attr_latex src-block))
- (float (plist-get attributes :float))
- (listings (plist-get info :latex-listings)))
+ (float (plist-get attributes :float)))
(funcall
- (pcase listings
- ((or (pred not) (guard (not lang))) #'org-latex-src-block--verbatim)
+ (pcase (plist-get info :latex-src-block-backend)
+ ((or `verbatim (guard (not lang))) #'org-latex-src-block--verbatim)
+ (`minted #'org-latex-src-block--minted)
+ (`engraved #'org-latex-src-block--engraved)
+ (`listings #'org-latex-src-block--listings)
((guard custom-env) #'org-latex-src-block--custom)
- ('minted #'org-latex-src-block--minted)
- ('engraved #'org-latex-src-block--engraved)
- (_ #'org-latex-src-block--listings))
+ (oldval
+ (message "Please update the LaTeX src-block-backend to %s"
+ (if oldval "listings" "verbatim"))
+ (if oldval
+ #'org-latex-src-block--listings
+ #'org-latex-src-block--verbatim)))
:src-block src-block
:info info
:lang lang
diff --git a/testing/lisp/test-ox.el b/testing/lisp/test-ox.el
index 25e02b258..28f950813 100644
--- a/testing/lisp/test-ox.el
+++ b/testing/lisp/test-ox.el
@@ -3978,7 +3978,7 @@ (ert-deftest test-org-export/latex-src-block-verbatim-caption ()
\\end{verbatim}
\\caption{Caption is below, 60\\%s}
\\end{figure*}"
- (let ((org-latex-listings 'minted) ; inactive due to missing lang
+ (let ((org-latex-src-block-backend 'minted) ; inactive due to missing lang
(org-latex-default-figure-position "tp"))
;; Namely "multicolumn" value to get just figure environment
;; looks like a bug.
--
2.35.3
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #9: 0008-ox-latex-Support-setting-the-engraved-theme.patch --]
[-- Type: text/x-patch, Size: 3213 bytes --]
From 7bc1f26f126449d8e457d88d6344aa1b5d439dfe Mon Sep 17 00:00:00 2001
From: TEC <tec@tecosaur.com>
Date: Sun, 8 May 2022 02:01:34 +0800
Subject: [PATCH 08/13] ox-latex: Support setting the engraved theme
* lisp/ox-latex.el (org-latex-generate-engraved-preamble,
org-latex-engraved-theme): Introduce the new export keyword
LATEX_ENGRAVED_THEME with default value given by
`org-latex-engraved-theme'. This is used to set the engraved theme used
in org-latex-engraved-theme.
This bumps the minimum required version of engrave-faces from v0.2 to
v0.3.
---
lisp/ox-latex.el | 15 +++++++++++++--
1 file changed, 13 insertions(+), 2 deletions(-)
diff --git a/lisp/ox-latex.el b/lisp/ox-latex.el
index f81625b45..e367e9040 100644
--- a/lisp/ox-latex.el
+++ b/lisp/ox-latex.el
@@ -129,6 +129,7 @@ (org-export-define-backend 'latex
(:latex-diary-timestamp-format nil nil org-latex-diary-timestamp-format)
(:latex-engraved-options nil nil org-latex-engraved-options)
(:latex-engraved-preamble nil nil org-latex-engraved-preamble)
+ (:latex-engraved-theme "LATEX_ENGRAVED_THEME" nil org-latex-engraved-theme)
(:latex-footnote-defined-format nil nil org-latex-footnote-defined-format)
(:latex-footnote-separator nil nil org-latex-footnote-separator)
(:latex-format-drawer-function nil nil org-latex-format-drawer-function)
@@ -1270,6 +1271,14 @@ (defcustom org-latex-engraved-options
:type '(alist :key-type (string :tag "option")
:value-type (string :tag "value")))
+(defcustom org-latex-engraved-theme nil
+ "The theme that should be used for engraved code, when non-nil.
+This can be set to any theme defined in `engrave-faces-themes' or
+loadable by Emacs. When set to t, the current Emacs theme is
+used. When nil, no theme is applied."
+ :group 'org-export-latex
+ :type 'symbol)
+
(defun org-latex-generate-engraved-preamble (info syntax-colours-p)
"Generate the preamble to setup engraved code.
The result is constructed from the :latex-engraved-preamble and
@@ -1278,7 +1287,8 @@ (defun org-latex-generate-engraved-preamble (info syntax-colours-p)
`org-latex-engraved-options' respectively."
(let* ((engraved-options
(plist-get info :latex-engraved-options))
- (engraved-preamble (plist-get info :latex-engraved-preamble)))
+ (engraved-preamble (plist-get info :latex-engraved-preamble))
+ (engraved-theme (plist-get info :latex-engraved-theme)))
(when (string-match "^[ \t]*\\[FVEXTRA-SETUP\\][ \t]*\n?" engraved-preamble)
(setq engraved-preamble
(replace-match
@@ -1310,7 +1320,8 @@ (defun org-latex-generate-engraved-preamble (info syntax-colours-p)
engraved-preamble
"\n\n% Setup for code blocks [2/2]: syntax highlighting colors\n"
(if (require 'engrave-faces-latex nil t)
- (engrave-faces-latex-gen-preamble)
+ (engrave-faces-latex-gen-preamble
+ (when engraved-theme (intern engraved-theme)))
(message "Cannot engrave source blocks. Consider installing `engrave-faces'.")
"% WARNING syntax highlighting unavailible as engrave-faces-latex was missing.\n")
"\n")
--
2.35.3
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #10: 0009-ox-latex-Support-setting-engraved-theme-per-block.patch --]
[-- Type: text/x-patch, Size: 9236 bytes --]
From 24db3cc69c2e28e4207532ac5181e27a28456eae Mon Sep 17 00:00:00 2001
From: TEC <tec@tecosaur.com>
Date: Sun, 8 May 2022 15:28:29 +0800
Subject: [PATCH 09/13] ox-latex: Support setting engraved theme per-block
* lisp/ox-latex.el (org-latex-src-block--engraved,
org-latex-src--engrave-code, org-latex-inline-src-block--engraved,
org-latex-generate-engraved-preamble): Allow for the engraved theme used
to be set on a per-src-block basis with #+attr_latex: :engraved-theme
THEME. Extra setup code is now generated in
`org-latex-generate-engraved-preamble'. To facilitate the application
of themes to src blocks, `org-latex-src--engrave-code' now takes on a
larger portion of the transcoding work.
---
lisp/ox-latex.el | 120 +++++++++++++++++++++++++++++++++++++----------
1 file changed, 96 insertions(+), 24 deletions(-)
diff --git a/lisp/ox-latex.el b/lisp/ox-latex.el
index e367e9040..9634461bd 100644
--- a/lisp/ox-latex.el
+++ b/lisp/ox-latex.el
@@ -1288,7 +1288,27 @@ (defun org-latex-generate-engraved-preamble (info syntax-colours-p)
(let* ((engraved-options
(plist-get info :latex-engraved-options))
(engraved-preamble (plist-get info :latex-engraved-preamble))
- (engraved-theme (plist-get info :latex-engraved-theme)))
+ (engraved-theme (plist-get info :latex-engraved-theme))
+ (engraved-themes
+ (cl-delete-duplicates
+ (org-element-map
+ (plist-get info :parse-tree)
+ '(src-block inline-src-block)
+ (lambda (src)
+ (plist-get
+ (org-export-read-attribute :attr_latex src)
+ :engraved-theme))
+ info)))
+ (gen-theme-spec
+ (lambda (theme)
+ (if (eq engrave-faces-latex-output-style 'preset)
+ (engrave-faces-latex-gen-preamble (when theme (intern theme)))
+ (engrave-faces-latex-gen-preamble-line
+ 'default
+ (alist-get 'default
+ (if theme
+ (engrave-faces-get-theme (intern theme))
+ engrave-faces-current-preset-style)))))))
(when (string-match "^[ \t]*\\[FVEXTRA-SETUP\\][ \t]*\n?" engraved-preamble)
(setq engraved-preamble
(replace-match
@@ -1318,10 +1338,31 @@ (defun org-latex-generate-engraved-preamble (info syntax-colours-p)
(concat
"\n% Setup for code blocks [1/2]\n\n"
engraved-preamble
- "\n\n% Setup for code blocks [2/2]: syntax highlighting colors\n"
+ "\n\n% Setup for code blocks [2/2]: syntax highlighting colors\n\n"
(if (require 'engrave-faces-latex nil t)
- (engrave-faces-latex-gen-preamble
- (when engraved-theme (intern engraved-theme)))
+ (if engraved-themes
+ (concat
+ (mapconcat
+ (lambda (theme)
+ (format
+ "\n\\newcommand{\\engravedtheme%s}{%%\n%s\n}"
+ (replace-regexp-in-string "[^A-Za-z]" "" theme)
+ (replace-regexp-in-string
+ "newcommand" "renewcommand"
+ (replace-regexp-in-string
+ "#" "##"
+ (funcall gen-theme-spec theme)))))
+ engraved-themes
+ "\n")
+ "\n\n"
+ (cond
+ ((memq engraved-theme engraved-themes)
+ (concat "\\engravedtheme"
+ (replace-regexp-in-string
+ "[^A-Za-z]" "" engraved-theme)
+ "\n"))
+ (t (funcall gen-theme-spec engraved-theme))))
+ (funcall gen-theme-spec engraved-theme))
(message "Cannot engrave source blocks. Consider installing `engrave-faces'.")
"% WARNING syntax highlighting unavailible as engrave-faces-latex was missing.\n")
"\n")
@@ -2359,10 +2400,11 @@ (defun org-latex-inline-src-block--minted (info code lang)
mint-lang
code)))
-(defun org-latex-inline-src-block--engraved (_info code lang)
+(defun org-latex-inline-src-block--engraved (info code lang)
"Transcode an inline src block's content from Org to LaTeX, using engrave-faces.
INFO, CODE, and LANG are provided by `org-latex-inline-src-block'."
- (format "\\Verb{%s}" (org-latex-src--engrave-code code lang)))
+ (org-latex-src--engrave-code
+ code lang nil (plist-get info :latex-engraved-options) t))
(defun org-latex-inline-src-block--listings (info code lang)
"Transcode an inline src block's content from Org to LaTeX, using lstlistings.
@@ -3347,13 +3389,25 @@ (cl-defun org-latex-src-block--minted
;; Return value.
(format float-env body)))
-(defun org-latex-src--engrave-code (content lang)
- "Engrave CONTENT to LaTeX in a LANG-mode buffer, and give the result."
+(defun org-latex-src--engrave-code (content lang &optional theme options inline)
+ "Engrave CONTENT to LaTeX in a LANG-mode buffer, and give the result.
+When the THEME symbol is non-nil, that theme will be used.
+
+When INLINE is nil, a Verbatim environment wrapped in a Code
+environment will be used. When t, a Verb command will be used.
+
+When OPTIONS is provided, as either a string or list of key-value
+pairs accepted by `org-latex--make-option-string', it is passed
+to the Verbatim environment or Verb command."
(if (require 'engrave-faces-latex nil t)
(let* ((lang-mode (and lang (org-src-get-lang-mode lang)))
+ (engrave-faces-current-preset-style
+ (if theme
+ (engrave-faces-get-theme theme)
+ engrave-faces-current-preset-style))
(engraved-buffer
(with-temp-buffer
- (insert content)
+ (insert (string-trim-right content "\n"))
(when lang-mode
(if (functionp lang-mode)
(funcall lang-mode)
@@ -3362,9 +3416,27 @@ (defun org-latex-src--engrave-code (content lang)
(engrave-faces-latex-buffer)))
(engraved-code
(with-current-buffer engraved-buffer
- (buffer-string))))
+ (buffer-string)))
+ (engraved-options
+ (when options
+ (concat "["
+ (if (listp options)
+ (org-latex--make-option-string options)
+ options)
+ "]")))
+ (engraved-wrapped
+ (if inline
+ (concat "\\Verb" engraved-options "{" engraved-code "}")
+ (concat "\\begin{Code}\n\\begin{Verbatim}" engraved-options "\n"
+ engraved-code "\n\\end{Verbatim}\n\\end{Code}"))))
(kill-buffer engraved-buffer)
- engraved-code)
+ (if theme
+ (concat "{\\engravedtheme"
+ (replace-regexp-in-string "[^A-Za-z]" ""
+ (symbol-name theme))
+ engraved-wrapped
+ "}")
+ engraved-wrapped))
(user-error "Cannot engrave code as `engrave-faces-latex' is unavailible.")))
(cl-defun org-latex-src-block--engraved
@@ -3392,7 +3464,15 @@ (cl-defun org-latex-src-block--engraved
placement)
"%s\n\\end{listing}"))
(t "%s")))
- (options (plist-get info :latex-engraved-options))
+ (options
+ (let ((engraved-options (plist-get info :latex-engraved-options))
+ (local-options (plist-get attributes :options)))
+ (append
+ (when (and num-start (not (assoc "linenos" engraved-options)))
+ `(("linenos")
+ ("firstnumber" ,(number-to-string (1+ num-start)))))
+ (and local-options (list local-options)))))
+ (engraved-theme (plist-get attributes :engraved-theme))
(content
(let* ((code-info (org-export-unravel-code src-block))
(max-width
@@ -3414,18 +3494,10 @@ (cl-defun org-latex-src-block--engraved
(format "(%s)" ref)))))
nil (and retain-labels (cdr code-info)))))
(body
- (format
- "\\begin{Code}\n\\begin{Verbatim}[%s]\n%s\\end{Verbatim}\n\\end{Code}"
- ;; Options.
- (concat
- (org-latex--make-option-string
- (append
- (when (and num-start (not (assoc "linenos" options)))
- `(("linenos")
- ("firstnumber" ,(number-to-string (1+ num-start)))))
- (let ((local-options (plist-get attributes :options)))
- (and local-options (list local-options))))))
- (org-latex-src--engrave-code content lang))))
+ (org-latex-src--engrave-code
+ content lang
+ (when engraved-theme (intern engraved-theme))
+ options)))
(format float-env body)))
(cl-defun org-latex-src-block--listings
--
2.35.3
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #11: 0010-ox-latex-Fix-captions-in-minted-engraved-code.patch --]
[-- Type: text/x-patch, Size: 4986 bytes --]
From 7d9306fe8ada094ff6964422cc527645eb9ffc55 Mon Sep 17 00:00:00 2001
From: TEC <tec@tecosaur.com>
Date: Mon, 9 May 2022 00:04:10 +0800
Subject: [PATCH 10/13] ox-latex: Fix %-captions in minted/engraved code
* lisp/ox-latex.el (org-latex-src-block--engraved,
org-latex-src-block--minted): Refactor float-env to be clearer, and
switch from `format' to `concat' to fix the bug where %-chars in
captions are interpreted as a format specifier.
---
lisp/ox-latex.el | 55 +++++++++++++++++++++---------------------------
1 file changed, 24 insertions(+), 31 deletions(-)
diff --git a/lisp/ox-latex.el b/lisp/ox-latex.el
index 9634461bd..ceb1bd483 100644
--- a/lisp/ox-latex.el
+++ b/lisp/ox-latex.el
@@ -3330,23 +3330,20 @@ (cl-defun org-latex-src-block--minted
(let* ((caption-str (org-latex--caption/label-string src-block info))
(placement (or (org-unbracket-string "[" "]" (plist-get attributes :placement))
(plist-get info :latex-default-figure-position)))
+ (multicolumn-p (string= "multicolumn" float))
(float-env
(cond
- ((string= "multicolumn" float)
- (format "\\begin{listing*}[%s]\n%s%%s\n%s\\end{listing*}"
- placement
- (if caption-above-p caption-str "")
- (if caption-above-p "" caption-str)))
- (caption
- (format "\\begin{listing}[%s]\n%s%%s\n%s\\end{listing}"
- placement
- (if caption-above-p caption-str "")
- (if caption-above-p "" caption-str)))
+ ((or caption multicolumn-p)
+ (cons
+ (concat "\\begin{listing" (when multicolumn-p "*")
+ "}[" placement "]\n"
+ (if caption-above-p caption-str ""))
+ (concat "\n" (if caption-above-p "" caption-str)
+ "\\end{listing" (when multicolumn-p "*") "}")))
((string= "t" float)
- (concat (format "\\begin{listing}[%s]\n"
- placement)
- "%s\n\\end{listing}"))
- (t "%s")))
+ (cons
+ (concat "\\begin{listing}[" placement "]\n")
+ "\n\\end{listing}"))))
(options (plist-get info :latex-minted-options))
(body
(format
@@ -3386,8 +3383,7 @@ (cl-defun org-latex-src-block--minted
?\s)
(format "(%s)" ref)))))
nil (and retain-labels (cdr code-info)))))))
- ;; Return value.
- (format float-env body)))
+ (concat (car float-env) body (cdr float-env))))
(defun org-latex-src--engrave-code (content lang &optional theme options inline)
"Engrave CONTENT to LaTeX in a LANG-mode buffer, and give the result.
@@ -3447,23 +3443,20 @@ (cl-defun org-latex-src-block--engraved
(let* ((caption-str (org-latex--caption/label-string src-block info))
(placement (or (org-unbracket-string "[" "]" (plist-get attributes :placement))
(plist-get info :latex-default-figure-position)))
+ (multicolumn-p (string= "multicolumn" float))
(float-env
(cond
- ((string= "multicolumn" float)
- (format "\\begin{listing*}[%s]\n%s%%s\n%s\\end{listing*}"
- placement
- (if caption-above-p caption-str "")
- (if caption-above-p "" caption-str)))
- (caption
- (format "\\begin{listing}[%s]\n%s%%s\n%s\\end{listing}"
- placement
- (if caption-above-p caption-str "")
- (if caption-above-p "" caption-str)))
+ ((or caption multicolumn-p)
+ (cons
+ (concat "\\begin{listing" (when multicolumn-p "*")
+ "}[" placement "]\n"
+ (if caption-above-p caption-str ""))
+ (concat "\n" (if caption-above-p "" caption-str)
+ "\\end{listing" (when multicolumn-p "*") "}")))
((string= "t" float)
- (concat (format "\\begin{listing}[%s]\n"
- placement)
- "%s\n\\end{listing}"))
- (t "%s")))
+ (cons
+ (concat "\\begin{listing}[" placement "]\n")
+ "\n\\end{listing}"))))
(options
(let ((engraved-options (plist-get info :latex-engraved-options))
(local-options (plist-get attributes :options)))
@@ -3498,7 +3491,7 @@ (cl-defun org-latex-src-block--engraved
content lang
(when engraved-theme (intern engraved-theme))
options)))
- (format float-env body)))
+ (concat (car float-env) body (cdr float-env))))
(cl-defun org-latex-src-block--listings
(&key src-block info lang caption caption-above-p label num-start retain-labels attributes float &allow-other-keys)
--
2.35.3
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #12: 0011-ox-latex-Support-mathescape-d-code-with-engraved.patch --]
[-- Type: text/x-patch, Size: 3891 bytes --]
From 5fdbbbe811a4d15fa1f7fa4bfad9d3e11e6f4eb8 Mon Sep 17 00:00:00 2001
From: TEC <tec@tecosaur.com>
Date: Wed, 11 May 2022 23:18:19 +0800
Subject: [PATCH 11/13] ox-latex: Support mathescape'd code with engraved
* lisp/ox-latex.el (org-latex-src-block--engraved,
org-latex-src--engrave-mathescape-p): Using the mathescape functionality
in engrave-faces-latex v0.3.1, we can support the mathescape option of
fvextra well. Along the way, we fix a minor issue with the localoptions
list in `org-latex-src-block--engraved`.
---
lisp/ox-latex.el | 46 +++++++++++++++++++++++++++++++++++++++++-----
1 file changed, 41 insertions(+), 5 deletions(-)
diff --git a/lisp/ox-latex.el b/lisp/ox-latex.el
index ceb1bd483..29543f8e9 100644
--- a/lisp/ox-latex.el
+++ b/lisp/ox-latex.el
@@ -3385,6 +3385,40 @@ (cl-defun org-latex-src-block--minted
nil (and retain-labels (cdr code-info)))))))
(concat (car float-env) body (cdr float-env))))
+(defun org-latex-src--engrave-mathescape-p (info options)
+ "From the export INFO plist, and the per-block OPTIONS, determine mathescape."
+ (let ((default-options (plist-get info :latex-engraved-options))
+ (mathescape-status
+ (lambda (opts)
+ (cl-some
+ (lambda (opt)
+ (or (and
+ (null (cdr opt))
+ (cond
+ ((string-match-p
+ "\\(?:^\\|,\\)mathescape=false\\(?:,\\|$\\)"
+ (car opt))
+ 'no)
+ ((or (string-match-p
+ "\\(?:^\\|,\\)mathescape\\(?:=true\\)?\\(?:,\\|$\\)"
+ (car opt))
+ (string= "mathescape" (car opt)))
+ 'yes)))
+ (and
+ (string= (car opt) "mathescape")
+ (cond
+ ((or (and (stringp (cdr opt)) (string= (cdr opt) "true"))
+ (equal '("true") (cdr opt)))
+ 'yes)
+ ((or (and (stringp (cdr opt)) (string= "false" (cdr opt)))
+ (equal '("false") (cdr opt)))
+ 'no)))))
+ opts))))
+ (if-let ((mathescape (or (funcall mathescape-status default-options)
+ (funcall mathescape-status options))))
+ (when (eq mathescape 'yes)
+ (or engrave-faces-latex-mathescape t)))))
+
(defun org-latex-src--engrave-code (content lang &optional theme options inline)
"Engrave CONTENT to LaTeX in a LANG-mode buffer, and give the result.
When the THEME symbol is non-nil, that theme will be used.
@@ -3464,7 +3498,7 @@ (cl-defun org-latex-src-block--engraved
(when (and num-start (not (assoc "linenos" engraved-options)))
`(("linenos")
("firstnumber" ,(number-to-string (1+ num-start)))))
- (and local-options (list local-options)))))
+ (and local-options `((,local-options))))))
(engraved-theme (plist-get attributes :engraved-theme))
(content
(let* ((code-info (org-export-unravel-code src-block))
@@ -3487,10 +3521,12 @@ (cl-defun org-latex-src-block--engraved
(format "(%s)" ref)))))
nil (and retain-labels (cdr code-info)))))
(body
- (org-latex-src--engrave-code
- content lang
- (when engraved-theme (intern engraved-theme))
- options)))
+ (let ((engrave-faces-latex-mathescape
+ (org-latex-src--engrave-mathescape-p info options)))
+ (org-latex-src--engrave-code
+ content lang
+ (when engraved-theme (intern engraved-theme))
+ options))))
(concat (car float-env) body (cdr float-env))))
(cl-defun org-latex-src-block--listings
--
2.35.3
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #13: 0012-news-and-manual-Mention-ox-latex-s-engraved-code.patch --]
[-- Type: text/x-patch, Size: 4727 bytes --]
From a57baf2c0f863aba49264875fd93d62a602ec0d9 Mon Sep 17 00:00:00 2001
From: TEC <tec@tecosaur.com>
Date: Thu, 12 May 2022 00:03:11 +0800
Subject: [PATCH 12/13] news and manual: Mention ox-latex's engraved code
* etc/ORG-NEWS: Mention the addition of the "engraved" source block
transcoding backend.
* doc/org-manual.org (Footnotes, LaTeX specific properties, Source
blocks in LaTeX export): Basic documentation on the "engraved" source
block transcoding backend.
---
doc/org-manual.org | 25 ++++++++++++++++---------
etc/ORG-NEWS | 9 +++++++++
2 files changed, 25 insertions(+), 9 deletions(-)
diff --git a/doc/org-manual.org b/doc/org-manual.org
index 60bded419..7cba5f18d 100644
--- a/doc/org-manual.org
+++ b/doc/org-manual.org
@@ -13811,22 +13811,26 @@ *** Source blocks in LaTeX export
#+vindex: org-latex-listings-options
#+vindex: org-latex-minted-options
+#+vindex: org-latex-engraved-options
The LaTeX export back-end passes string values in =:options= to LaTeX
packages for customization of that specific source block. In the
-example below, the =:options= are set for Minted. Minted is a source
-code highlighting LaTeX package with many configurable options[fn:134].
+example below, the =:options= are set for Engraved or Minted. Minted
+is a source code highlighting LaTeX package with many configurable
+options[fn:134]. Both Minted and Engraved are built on [[https://www.ctan.org/pkg/fvextra][fvextra]], and
+so support many of the same options.
#+begin_example
-,#+ATTR_LATEX: :options commentstyle=\bfseries
+,#+ATTR_LATEX: :options mathescape
,#+BEGIN_SRC emacs-lisp
- (defun Fib (n)
+ (defun Fib (n) ; $n_i = n_{i-2} + n_{i-1}$
(if (< n 2) n (+ (Fib (- n 1)) (Fib (- n 2)))))
,#+END_SRC
#+end_example
-To apply similar configuration options for all source blocks in
-a file, use the ~org-latex-listings-options~ and
-~org-latex-minted-options~ variables.
+To apply similar configuration options for all source blocks in a
+file, use the ~org-latex-listings-options~,
+~org-latex-engraved-options~, and ~org-latex-minted-options~
+variables.
*** Example blocks in LaTeX export
:PROPERTIES:
@@ -16289,6 +16293,9 @@ **** LaTeX specific properties
| ~:latex-default-table-environment~ | ~org-latex-default-table-environment~ |
| ~:latex-default-table-mode~ | ~org-latex-default-table-mode~ |
| ~:latex-diary-timestamp-format~ | ~org-latex-diary-timestamp-format~ |
+| ~:latex-engraved-options~ | ~org-latex-engraved-options~ |
+| ~:latex-engraved-preamble~ | ~org-latex-engraved-preamble~ |
+| ~:latex-engraved-theme~ | ~org-latex-engraved-theme~ |
| ~:latex-footnote-defined-format~ | ~org-latex-footnote-defined-format~ |
| ~:latex-footnote-separator~ | ~org-latex-footnote-separator~ |
| ~:latex-format-drawer-function~ | ~org-latex-format-drawer-function~ |
@@ -22255,8 +22262,8 @@ * Footnotes
[fn:114] This works automatically for the HTML backend (it requires
version 1.34 of the =htmlize.el= package, which you need to install).
Fontified code chunks in LaTeX can be achieved using either the
-[[https://www.ctan.org/pkg/listings][listings]] package or the [[https://www.ctan.org/pkg/minted][minted]] package. Refer to
-~org-latex-src-block-backend~ for details.
+[[https://www.ctan.org/pkg/listings][listings]] LaTeX package, [[https://www.ctan.org/pkg/minted][minted]] LaTeX package, or by using
+[[https://elpa.gnu.org/packages/engrave-faces.html][engrave-faces]] . Refer to ~org-latex-src-block-backend~ for details.
[fn:115] Source code in code blocks may also be evaluated either
interactively or on export. See [[*Working with Source Code]] for more
diff --git a/etc/ORG-NEWS b/etc/ORG-NEWS
index ebb3cd649..582816534 100644
--- a/etc/ORG-NEWS
+++ b/etc/ORG-NEWS
@@ -180,6 +180,15 @@ commands.
=:noweb-prefix= can be set to =no= to prevent the prefix characters
from being repeated when expanding a multiline noweb reference.
+*** New LaTeX source block backend using =engraved-faces-latex=
+
+When ~org-latex-src-block-backend~ is set to ~engraved~,
+=engrave-faces-latex= from [[http://elpa.gnu.org/packages/engrave-faces.html][engrave-faces]] is used to transcode source
+blocks to LaTeX. This requires the =fvextra=, =float=, and (by
+default, but not necessarily) =tcolorbox= LaTeX packages be
+installed. It uses Emacs' font-lock information, and so tends to
+produce results superior to Minted or Listings.
+
** New functions and changes in function arguments
*** New function ~org-element-cache-map~ for quick mapping across Org elements
--
2.35.3
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #14: 0013-ox-latex-Prefix-lst-to-source-block-labels.patch --]
[-- Type: text/x-patch, Size: 848 bytes --]
From c3851e657611424af10859a2236c0b4e183cc1d7 Mon Sep 17 00:00:00 2001
From: TEC <tec@tecosaur.com>
Date: Wed, 11 May 2022 21:50:36 +0800
Subject: [PATCH 13/13] ox-latex: Prefix lst: to source block labels
* lisp/ox-latex.el (org-latex--label): Use the "lst:" prefix when
generating source block labels ("lst" contracted from "listing").
---
lisp/ox-latex.el | 1 +
1 file changed, 1 insertion(+)
diff --git a/lisp/ox-latex.el b/lisp/ox-latex.el
index 29543f8e9..998f2238d 100644
--- a/lisp/ox-latex.el
+++ b/lisp/ox-latex.el
@@ -1554,6 +1554,7 @@ (defun org-latex--label (datum info &optional force full)
(`paragraph
(and (org-element-property :caption datum)
"fig:"))
+ (`src-block "lst:")
(_ nil))
(org-export-get-reference datum info))))))
(cond ((not full) label)
--
2.35.3
^ permalink raw reply related [relevance 5%]
* Re: [PATCH] New LaTeX code export option: engraved
2022-05-10 1:13 93% ` Timothy
@ 2022-05-10 16:10 93% ` Timothy
0 siblings, 0 replies; 200+ results
From: Timothy @ 2022-05-10 16:10 UTC (permalink / raw)
To: sebastien.miquel; +Cc: emacs-orgmode
[-- Attachment #1: Type: text/plain, Size: 757 bytes --]
Hi Sebastien,
>> 1. engrave-faces-generate-preset generates emacs colors such as
>> `:foreground “grey70”` which are not supported by
>> engrave-faces-latex-gen-preamble-line and co.
>
> I’ll see if I can incorporate this into engrave-faces v0.3.1.
Done.
>> 2. `minted` supports a `mathescape` option to render math content
>> inside code. `fvextra` supports the same option, but maths
>> characters are escaped by engrave-faces-latex-face-mapper.
>
> I’l also take a look at this :)
Implemented in engrave-faces-latex, but not worked into ox-html yet. If you
could check it out on the engrave-faces-latex side and check it’s behaving
sanely, that would be helpful.
All the best,
Timothy
^ permalink raw reply [relevance 93%]
* Re: [PATCH] New LaTeX code export option: engraved
@ 2022-05-10 1:13 93% ` Timothy
2022-05-10 16:10 93% ` Timothy
0 siblings, 1 reply; 200+ results
From: Timothy @ 2022-05-10 1:13 UTC (permalink / raw)
To: sebastien.miquel; +Cc: emacs-orgmode
[-- Attachment #1: Type: text/plain, Size: 1087 bytes --]
Hi Sebastien,
> I’m quite exited and impressed to see this alternative to minted,
> thank you.
That’s great to hear!
> I haven’t been able to test your patches to org, but I have tried
> engrave-faces.el. Here’s a couple issues I’ve run into.
Still helpful, thanks.
> 1. engrave-faces-generate-preset generates emacs colors such as
> `:foreground “grey70”` which are not supported by
> engrave-faces-latex-gen-preamble-line and co.
Ah. I’ve just found this snippet from `list-colors-print'
┌────
│ (apply 'format "#%02x%02x%02x"
│ (mapcar (lambda (c) (ash c -8))
│ (color-values (car color))))
└────
I’ll see if I can incorporate this into engrave-faces v0.3.1.
> 2. `minted` supports a `mathescape` option to render math content
> inside code. `fvextra` supports the same option, but maths
> characters are escaped by engrave-faces-latex-face-mapper.
I’l also take a look at this :)
Thanks for the comments Sebastien.
All the best,
Timothy
^ permalink raw reply [relevance 93%]
* Re: [PATCH] (v2) New LaTeX code export option: engraved
@ 2022-05-09 12:57 81% ` Timothy
0 siblings, 0 replies; 200+ results
From: Timothy @ 2022-05-09 12:57 UTC (permalink / raw)
To: Ihor Radchenko; +Cc: Daniel Fleischer, emacs-orgmode, Nicolas Goaziou
[-- Attachment #1: Type: text/plain, Size: 5007 bytes --]
Hi Ihor,
> Before merging, could you also try to implement tests at least for
> engraved feature? If I recall correctly, we do not currently have
> backend-specific tests. But it would certainly help if we did. You might
> as well write a small “nucleus” test for ox-latex.
Probably not a bad idea, I’m just not sure what/how I’d go about this.
> Also, unless I miss something, there is no support for coderefs in the
> patchset. Is it intentional?
I think you’ve missed something. It has the same coderefs support as minted.
> It appears that the code for caption-str is duplicated. It could be
> also factored out.
It could, but I’m not sure this is actually a good idea as the duplication is
more the result of chance than a common dependency.
>> + (format-spec custom-env
>> + `((?s . ,formatted-src)
>> + (?c . ,caption)
>> + (?f . ,float)
>> + (?l . ,(org-latex–label src-block info))
>> + (?o . ,(or (plist-get attributes :options) “”)))))))
>
> I do not see a definition of `format-spec’ function. There is only
> `spec’ above in the code. Can you double check? Either I am missing
> something or something fishy is going on.
This code isn’t introduced by my patches, just relocated. FWIW `format-spec' is
provided by Emacs, and I don’t think is new.
>> + (let ((code (org-element-property :value inline-src-block))
>> + (lang (org-element-property :language inline-src-block)))
>> + (pcase (plist-get info :latex-listings)
>> + (’nil (org-latex–text-markup code ’code info))
>> + (’minted (org-latex-inline-src-block–minted info code lang))
>> + (_ (org-latex-inline-src-block–listings info code lang)))))
>
> Please use `nil and `minted. Using ’ may create issues in older Emacs.
Done.
>> +% In case engrave-faces-latex-gen-preamble has not been run.
>> +\
>> +\
>
> What is the difference between EfD and EFD? EfD is also not documented.
Documentation added. EfD is the background colour.
>> +FVEXTRA-SETUP sets fvextra’s defaults according to
>> +`org-latex-engraved-options’, and LISTINGS-SETUP creates the
>> +listings environment and defines \.“
>
> It is unclear what listings environment does given that we use engraved
> package. Can you provide a bit more details in the docstring on what the
> user will get if [LISTINGS-SETUP] is present.
> It may catch users by surprise that deleting this will make captions
> disappear.
It does the same thing as minted’s `listings' environment, hence the choice of
name. Documentation added.
> Why not just
> (org-element-map (plist-get info :parse-tree)
> ’(src-block inline-src-block example-block fixed-width) #’identity
> info t)
Ah, in my config I’m also using some engraved info for example/fixed-width
blocks. I’ll leave this out for now.
>> (pcase (plist-get info :latex-listings)
>> (’nil (org-latex–text-markup code ’code info))
>> …
> Same comment about ` in pcase.
Done.
> What will happen if there is no [LISTINGS-SETUP]?
Captioned/Floating code blocks won’t work.
>> +(defcustom org-latex-engraved-theme nil
> Docstring does not explain what happens when set to nil.
> Also, does :type ’symbol allow t and nil?
I think so, `symbolp' says they’re symbols if nothing else.
> Will it work when engraved-theme is t?
Yes.
> What about example-block and fixed-width? I may be missing something,
> but earlier in the patchset you had conditionals of the type
> (or src-p fixedw-p). So, does engrave-faces do anything with fixedw-type
> elements?
Resolved earlier.
>> + (gen-theme-spec
>> + (lambda (theme) …
>
> This appears to be not guarded by (require ’engrave-faces-latex nil t).
It is before it’s actually called.
>> -(defun org-latex-src–engrave-code (content lang)
>> - “Engrave CONTENT to LaTeX in a LANG-mode buffer, and give the result.”
>> +(defun org-latex-src–engrave-code (content lang &optional theme options inline)
>> + “Engrave CONTENT to LaTeX in a LANG-mode buffer, and give the result.
>> +When THEME is non-nil, it will be used.”
>
> You did not document the remaining two arguments. (this makes me ask a
> question whether you checked compile warnings). Also, consider running
> M-x checkdoc on ox-latex.el.
Now documented.
I have checked compile warnings (there are none), but checkdoc is currently a
bit dodgy on the Emacs commit I’m on.
>> - (insert content)
>> + (insert (string-trim-right content “”))
>
> As a theoretical possibility, what will happen if content has something
> like “%”?
Discussed in DMs. It just gets rid of trailing newlines, and it’s fine with
escaping.
All the best,
Timothy
^ permalink raw reply [relevance 81%]
* Re: [PATCH] (v2) New LaTeX code export option: engraved
@ 2022-05-08 14:30 6% ` Timothy
2022-05-11 16:05 5% ` [PATCH] (v3) " Timothy
0 siblings, 2 replies; 200+ results
From: Timothy @ 2022-05-08 14:30 UTC (permalink / raw)
To: Daniel Fleischer; +Cc: Ihor Radchenko, emacs-orgmode, Nicolas Goaziou
[-- Attachment #1: Type: text/plain, Size: 2337 bytes --]
Hi Daniel & co.,
I have a new set of patches (attached), which make use of a major new feature in
engrave-faces v0.3: engraved themes.
Now, the theme used for source blocks can be set by the document keyword
`#+latex_engraved_theme: THEME-NAME'. Furthermore, the theme can be customised on
a per-code-block basis with `#+attr_latex: :engraved-theme THEME-NAME'.
If you try this out, make sure you have the most recent commit of engrave-faces
(531ea687e, soon to be released in v0.3.1).
I’ve also fixed the “Bug: Percentage in caption (even escaped) does not work in
LaTeX export” that Max raised
(<https://list.orgmode.org/YT2PR01MB45101E27DC6251D8F8B7B366F6EC9@YT2PR01MB4510.CANPRD01.PROD.OUTLOOK.COM>).
Daniel Fleischer <danflscr@gmail.com> writes:
> Very nice set of patches, it looks good.
Glad to hear you’ve been able to have a look over the patches. With the feedback
I’ve received here so far, if no issues come up in the next few days I’m
inclined to merge this, add documentation, and see what feedback pops up.
> I must admit it’s not clear how to customize faces since engrave is a bridge
> between major modes choices and latex but maybe show one or two examples (say
> elisp and python) of how to change/override some face.
Sure. The result should be visually identical to what you’d see in elisp/python
buffer, but possibly with a different theme.
Say you wanted to use a tweaked version of the default theme, this could be
accomplished like so:
┌────
│ (setq default2 (alist-get 'default engrave-faces-themes))
│ ;; Make comments hot pink
│ (plist-put (alist-get 'font-lock-comment-face default2) :foreground "#ff69b4")
│ ;; Any other customisations...
│ (add-to-list 'engrave-faces-themes (cons 'default2 default2))
└────
Then in the Org file you can use the “default2” engraved theme with
`#+latex_engraved_theme: default2'.
Let me know if there are any other examples you’d like to see.
> I think next we should apply these patches and be open to feedback
> about source code latex export using these new changes. I also wish
> there was a bit more documentation, but we can add more with time.
> Maybe some feedback from Nicolas G.?
👍 see my earlier comment on merging.
All the best,
Timothy
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-ox-latex-Refactor-org-latex-src-block.patch --]
[-- Type: text/x-patch, Size: 15944 bytes --]
From 18adbd0e1226cf3307090861e09e92bfa9cdfbf1 Mon Sep 17 00:00:00 2001
From: TEC <tec@tecosaur.com>
Date: Sun, 21 Nov 2021 14:35:34 +0800
Subject: [PATCH 01/10] ox-latex: Refactor `org-latex-src-block'
* lisp/ox-latex.el (org-latex-src-block): Extract the per-format logic
from `org-latex-src-block' into new dedicated functions:
+ `org-latex-src-block--verbatim'
+ `org-latex-src-block--custom'
+ `org-latex-src-block--minted'
+ `org-latex-src-block--listings'
This makes `org-latex-src-block' much less monolithic, taking it from
175 lines to 30, and I find also makes it easier to understand.
---
lisp/ox-latex.el | 339 ++++++++++++++++++++++++++---------------------
1 file changed, 185 insertions(+), 154 deletions(-)
diff --git a/lisp/ox-latex.el b/lisp/ox-latex.el
index 841ad48bc..c2f728a1c 100644
--- a/lisp/ox-latex.el
+++ b/lisp/ox-latex.el
@@ -2997,164 +2997,195 @@ (defun org-latex-src-block (src-block _contents info)
(float (plist-get attributes :float))
(listings (plist-get info :latex-listings)))
(cond
- ;; Case 1. No source fontification.
((or (not lang) (not listings))
- (let ((caption-str (org-latex--caption/label-string src-block info))
- (verbatim (format "\\begin{verbatim}\n%s\\end{verbatim}"
- (org-export-format-code-default src-block info))))
- (cond ((string= "multicolumn" float)
- (format "\\begin{figure*}[%s]\n%s%s\n%s\\end{figure*}"
- (plist-get info :latex-default-figure-position)
- (if caption-above-p caption-str "")
- verbatim
- (if caption-above-p "" caption-str)))
- (caption (concat
- (if caption-above-p caption-str "")
- verbatim
- (if caption-above-p "" (concat "\n" caption-str))))
- (t verbatim))))
- ;; Case 2. Custom environment.
+ (org-latex-src-block--verbatim src-block info lang caption caption-above-p label
+ num-start retain-labels attributes float))
(custom-env
- (let ((caption-str (org-latex--caption/label-string src-block info))
- (formatted-src (org-export-format-code-default src-block info)))
- (if (string-match-p "\\`[a-zA-Z0-9]+\\'" custom-env)
- (format "\\begin{%s}\n%s\\end{%s}\n"
- custom-env
- (concat (and caption-above-p caption-str)
- formatted-src
- (and (not caption-above-p) caption-str))
- custom-env)
- (format-spec custom-env
- `((?s . ,formatted-src)
- (?c . ,caption)
- (?f . ,float)
- (?l . ,(org-latex--label src-block info))
- (?o . ,(or (plist-get attributes :options) "")))))))
- ;; Case 3. Use minted package.
+ (org-latex-src-block--custom src-block info lang caption caption-above-p label
+ num-start retain-labels attributes float custom-env))
((eq listings 'minted)
- (let* ((caption-str (org-latex--caption/label-string src-block info))
- (placement (or (org-unbracket-string "[" "]" (plist-get attributes :placement))
- (plist-get info :latex-default-figure-position)))
- (float-env
- (cond
- ((string= "multicolumn" float)
- (format "\\begin{listing*}[%s]\n%s%%s\n%s\\end{listing*}"
- placement
- (if caption-above-p caption-str "")
- (if caption-above-p "" caption-str)))
- (caption
- (format "\\begin{listing}[%s]\n%s%%s\n%s\\end{listing}"
- placement
- (if caption-above-p caption-str "")
- (if caption-above-p "" caption-str)))
- ((string= "t" float)
- (concat (format "\\begin{listing}[%s]\n"
- placement)
- "%s\n\\end{listing}"))
- (t "%s")))
- (options (plist-get info :latex-minted-options))
- (body
- (format
- "\\begin{minted}[%s]{%s}\n%s\\end{minted}"
- ;; Options.
- (concat
- (org-latex--make-option-string
- (if (or (not num-start) (assoc "linenos" options))
- options
- (append
- `(("linenos")
- ("firstnumber" ,(number-to-string (1+ num-start))))
- options)))
- (let ((local-options (plist-get attributes :options)))
- (and local-options (concat "," local-options))))
- ;; Language.
- (or (cadr (assq (intern lang)
- (plist-get info :latex-minted-langs)))
- (downcase lang))
- ;; Source code.
- (let* ((code-info (org-export-unravel-code src-block))
- (max-width
- (apply 'max
- (mapcar 'length
- (org-split-string (car code-info)
- "\n")))))
- (org-export-format-code
- (car code-info)
- (lambda (loc _num ref)
- (concat
- loc
- (when ref
- ;; Ensure references are flushed to the right,
- ;; separated with 6 spaces from the widest line
- ;; of code.
- (concat (make-string (+ (- max-width (length loc)) 6)
- ?\s)
- (format "(%s)" ref)))))
- nil (and retain-labels (cdr code-info)))))))
- ;; Return value.
- (format float-env body)))
- ;; Case 4. Use listings package.
+ (org-latex-src-block--minted src-block info lang caption caption-above-p label
+ num-start retain-labels attributes float))
(t
- (let ((lst-lang
- (or (cadr (assq (intern lang)
- (plist-get info :latex-listings-langs)))
- lang))
- (caption-str
- (when caption
- (let ((main (org-export-get-caption src-block))
- (secondary (org-export-get-caption src-block t)))
- (if (not secondary)
- (format "{%s}" (org-export-data main info))
- (format "{[%s]%s}"
- (org-export-data secondary info)
- (org-export-data main info))))))
- (lst-opt (plist-get info :latex-listings-options)))
- (concat
- ;; Options.
- (format
- "\\lstset{%s}\n"
- (concat
- (org-latex--make-option-string
- (append
- lst-opt
- (cond
- ((and (not float) (plist-member attributes :float)) nil)
- ((string= "multicolumn" float) '(("float" "*")))
- ((and float (not (assoc "float" lst-opt)))
- `(("float" ,(plist-get info :latex-default-figure-position)))))
- `(("language" ,lst-lang))
- (if label
- `(("label" ,(org-latex--label src-block info)))
- '(("label" " ")))
- (if caption-str `(("caption" ,caption-str)) '(("caption" " ")))
- `(("captionpos" ,(if caption-above-p "t" "b")))
- (cond ((assoc "numbers" lst-opt) nil)
- ((not num-start) '(("numbers" "none")))
- (t `(("firstnumber" ,(number-to-string (1+ num-start)))
- ("numbers" "left"))))))
- (let ((local-options (plist-get attributes :options)))
- (and local-options (concat "," local-options)))))
- ;; Source code.
- (format
- "\\begin{lstlisting}\n%s\\end{lstlisting}"
- (let* ((code-info (org-export-unravel-code src-block))
- (max-width
- (apply 'max
- (mapcar 'length
- (org-split-string (car code-info) "\n")))))
- (org-export-format-code
- (car code-info)
- (lambda (loc _num ref)
- (concat
- loc
- (when ref
- ;; Ensure references are flushed to the right,
- ;; separated with 6 spaces from the widest line of
- ;; code
- (concat (make-string (+ (- max-width (length loc)) 6) ?\s)
- (format "(%s)" ref)))))
- nil (and retain-labels (cdr code-info))))))))))))
-
+ (org-latex-src-block--listings src-block info lang caption caption-above-p label
+ num-start retain-labels attributes float))))))
+
+(defun org-latex-src-block--verbatim
+ (src-block info _lang caption caption-above-p _label
+ _num-start _retain-labels _attributes float)
+ "Transcode a SRC-BLOCK element from Org to LaTeX, using verbatim.
+LANG, CAPTION, CAPTION-ABOVE-P, LABEL, NUM-START, RETAIN-LABELS, ATTRIBUTES
+and FLOAT are extracted from SRC-BLOCK and INFO in `org-latex-src-block'."
+ (let ((caption-str (org-latex--caption/label-string src-block info))
+ (verbatim (format "\\begin{verbatim}\n%s\\end{verbatim}"
+ (org-export-format-code-default src-block info))))
+ (cond ((string= "multicolumn" float)
+ (format "\\begin{figure*}[%s]\n%s%s\n%s\\end{figure*}"
+ (plist-get info :latex-default-figure-position)
+ (if caption-above-p caption-str "")
+ verbatim
+ (if caption-above-p "" caption-str)))
+ (caption (concat
+ (if caption-above-p caption-str "")
+ verbatim
+ (if caption-above-p "" (concat "\n" caption-str))))
+ (t verbatim))))
+
+(defun org-latex-src-block--custom
+ (src-block info _lang caption caption-above-p _label
+ _num-start _retain-labels attributes float custom-env)
+ "Transcode a SRC-BLOCK element from Org to LaTeX, using a custom environment.
+LANG, CAPTION, CAPTION-ABOVE-P, LABEL, NUM-START, RETAIN-LABELS, ATTRIBUTES
+and FLOAT are extracted from SRC-BLOCK and INFO in `org-latex-src-block'."
+ (let ((caption-str (org-latex--caption/label-string src-block info))
+ (formatted-src (org-export-format-code-default src-block info)))
+ (if (string-match-p "\\`[a-zA-Z0-9]+\\'" custom-env)
+ (format "\\begin{%s}\n%s\\end{%s}\n"
+ custom-env
+ (concat (and caption-above-p caption-str)
+ formatted-src
+ (and (not caption-above-p) caption-str))
+ custom-env)
+ (format-spec custom-env
+ `((?s . ,formatted-src)
+ (?c . ,caption)
+ (?f . ,float)
+ (?l . ,(org-latex--label src-block info))
+ (?o . ,(or (plist-get attributes :options) "")))))))
+
+(defun org-latex-src-block--minted
+ (src-block info lang caption caption-above-p _label
+ num-start retain-labels attributes float)
+ "Transcode a SRC-BLOCK element from Org to LaTeX, using minted.
+LANG, CAPTION, CAPTION-ABOVE-P, LABEL, NUM-START, RETAIN-LABELS, ATTRIBUTES
+and FLOAT are extracted from SRC-BLOCK and INFO in `org-latex-src-block'."
+ (let* ((caption-str (org-latex--caption/label-string src-block info))
+ (placement (or (org-unbracket-string "[" "]" (plist-get attributes :placement))
+ (plist-get info :latex-default-figure-position)))
+ (float-env
+ (cond
+ ((string= "multicolumn" float)
+ (format "\\begin{listing*}[%s]\n%s%%s\n%s\\end{listing*}"
+ placement
+ (if caption-above-p caption-str "")
+ (if caption-above-p "" caption-str)))
+ (caption
+ (format "\\begin{listing}[%s]\n%s%%s\n%s\\end{listing}"
+ placement
+ (if caption-above-p caption-str "")
+ (if caption-above-p "" caption-str)))
+ ((string= "t" float)
+ (concat (format "\\begin{listing}[%s]\n"
+ placement)
+ "%s\n\\end{listing}"))
+ (t "%s")))
+ (options (plist-get info :latex-minted-options))
+ (body
+ (format
+ "\\begin{minted}[%s]{%s}\n%s\\end{minted}"
+ ;; Options.
+ (concat
+ (org-latex--make-option-string
+ (if (or (not num-start) (assoc "linenos" options))
+ options
+ (append
+ `(("linenos")
+ ("firstnumber" ,(number-to-string (1+ num-start))))
+ options)))
+ (let ((local-options (plist-get attributes :options)))
+ (and local-options (concat "," local-options))))
+ ;; Language.
+ (or (cadr (assq (intern lang)
+ (plist-get info :latex-minted-langs)))
+ (downcase lang))
+ ;; Source code.
+ (let* ((code-info (org-export-unravel-code src-block))
+ (max-width
+ (apply 'max
+ (mapcar 'length
+ (org-split-string (car code-info)
+ "\n")))))
+ (org-export-format-code
+ (car code-info)
+ (lambda (loc _num ref)
+ (concat
+ loc
+ (when ref
+ ;; Ensure references are flushed to the right,
+ ;; separated with 6 spaces from the widest line
+ ;; of code.
+ (concat (make-string (+ (- max-width (length loc)) 6)
+ ?\s)
+ (format "(%s)" ref)))))
+ nil (and retain-labels (cdr code-info)))))))
+ ;; Return value.
+ (format float-env body)))
+
+(defun org-latex-src-block--listings
+ (src-block info lang caption caption-above-p label
+ num-start retain-labels attributes float)
+ "Transcode a SRC-BLOCK element from Org to LaTeX, using listings.
+LANG, CAPTION, CAPTION-ABOVE-P, LABEL, NUM-START, RETAIN-LABELS, ATTRIBUTES
+and FLOAT are extracted from SRC-BLOCK and INFO in `org-latex-src-block'."
+ (let ((lst-lang
+ (or (cadr (assq (intern lang)
+ (plist-get info :latex-listings-langs)))
+ lang))
+ (caption-str
+ (when caption
+ (let ((main (org-export-get-caption src-block))
+ (secondary (org-export-get-caption src-block t)))
+ (if (not secondary)
+ (format "{%s}" (org-export-data main info))
+ (format "{[%s]%s}"
+ (org-export-data secondary info)
+ (org-export-data main info))))))
+ (lst-opt (plist-get info :latex-listings-options)))
+ (concat
+ ;; Options.
+ (format
+ "\\lstset{%s}\n"
+ (concat
+ (org-latex--make-option-string
+ (append
+ lst-opt
+ (cond
+ ((and (not float) (plist-member attributes :float)) nil)
+ ((string= "multicolumn" float) '(("float" "*")))
+ ((and float (not (assoc "float" lst-opt)))
+ `(("float" ,(plist-get info :latex-default-figure-position)))))
+ `(("language" ,lst-lang))
+ (if label
+ `(("label" ,(org-latex--label src-block info)))
+ '(("label" " ")))
+ (if caption-str `(("caption" ,caption-str)) '(("caption" " ")))
+ `(("captionpos" ,(if caption-above-p "t" "b")))
+ (cond ((assoc "numbers" lst-opt) nil)
+ ((not num-start) '(("numbers" "none")))
+ (t `(("firstnumber" ,(number-to-string (1+ num-start)))
+ ("numbers" "left"))))))
+ (let ((local-options (plist-get attributes :options)))
+ (and local-options (concat "," local-options)))))
+ ;; Source code.
+ (format
+ "\\begin{lstlisting}\n%s\\end{lstlisting}"
+ (let* ((code-info (org-export-unravel-code src-block))
+ (max-width
+ (apply 'max
+ (mapcar 'length
+ (org-split-string (car code-info) "\n")))))
+ (org-export-format-code
+ (car code-info)
+ (lambda (loc _num ref)
+ (concat
+ loc
+ (when ref
+ ;; Ensure references are flushed to the right,
+ ;; separated with 6 spaces from the widest line of
+ ;; code
+ (concat (make-string (+ (- max-width (length loc)) 6) ?\s)
+ (format "(%s)" ref)))))
+ nil (and retain-labels (cdr code-info))))))))
;;;; Statistics Cookie
--
2.35.3
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #3: 0002-ox-latex-Refactor-org-latex-inline-src-block.patch --]
[-- Type: text/x-patch, Size: 4018 bytes --]
From 6635b72356192c3b0be500984b327d0b4ebd8e2b Mon Sep 17 00:00:00 2001
From: TEC <tec@tecosaur.com>
Date: Wed, 4 May 2022 18:53:10 +0800
Subject: [PATCH 02/10] ox-latex: Refactor `org-latex-inline-src-block'
* lisp/ox-latex.el (org-latex-inline-src-block,
org-latex-inline-src-block--minted,
org-latex-inline-src-block--listings): Extract the minted and listings
specific logic out of `org-latex-inline-src-block` into the new
functions `org-latex-inline-src-block--minted` and
`org-latex-inline-src-block--listings`.
---
lisp/ox-latex.el | 62 +++++++++++++++++++++++++-----------------------
1 file changed, 32 insertions(+), 30 deletions(-)
diff --git a/lisp/ox-latex.el b/lisp/ox-latex.el
index c2f728a1c..38f36a1f3 100644
--- a/lisp/ox-latex.el
+++ b/lisp/ox-latex.el
@@ -2127,36 +2127,38 @@ (defun org-latex-inline-src-block (inline-src-block _contents info)
"Transcode an INLINE-SRC-BLOCK element from Org to LaTeX.
CONTENTS holds the contents of the item. INFO is a plist holding
contextual information."
- (let* ((code (org-element-property :value inline-src-block))
- (separator (org-latex--find-verb-separator code)))
- (cl-case (plist-get info :latex-listings)
- ;; Do not use a special package: transcode it verbatim, as code.
- ((nil) (org-latex--text-markup code 'code info))
- ;; Use minted package.
- (minted
- (let* ((org-lang (org-element-property :language inline-src-block))
- (mint-lang (or (cadr (assq (intern org-lang)
- (plist-get info :latex-minted-langs)))
- (downcase org-lang)))
- (options (org-latex--make-option-string
- (plist-get info :latex-minted-options))))
- (format "\\mintinline%s{%s}{%s}"
- (if (string= options "") "" (format "[%s]" options))
- mint-lang
- code)))
- ;; Use listings package.
- (otherwise
- ;; Maybe translate language's name.
- (let* ((org-lang (org-element-property :language inline-src-block))
- (lst-lang (or (cadr (assq (intern org-lang)
- (plist-get info :latex-listings-langs)))
- org-lang))
- (options (org-latex--make-option-string
- (append (plist-get info :latex-listings-options)
- `(("language" ,lst-lang))))))
- (concat (format "\\lstinline[%s]" options)
- separator code separator))))))
-
+ (let ((code (org-element-property :value inline-src-block))
+ (lang (org-element-property :language inline-src-block)))
+ (pcase (plist-get info :latex-listings)
+ ('nil (org-latex--text-markup code 'code info))
+ ('minted (org-latex-inline-src-block--minted info code lang))
+ (_ (org-latex-inline-src-block--listings info code lang)))))
+
+(defun org-latex-inline-src-block--minted (info code lang)
+ "Transcode an inline src block's content from Org to LaTeX, using minted.
+INFO, CODE, and LANG are provided by `org-latex-inline-src-block'."
+ (let ((mint-lang (or (cadr (assq (intern lang)
+ (plist-get info :latex-minted-langs)))
+ (downcase lang)))
+ (options (org-latex--make-option-string
+ (plist-get info :latex-minted-options))))
+ (format "\\mintinline%s{%s}{%s}"
+ (if (string= options "") "" (format "[%s]" options))
+ mint-lang
+ code)))
+
+(defun org-latex-inline-src-block--listings (info code lang)
+ "Transcode an inline src block's content from Org to LaTeX, using lstlistings.
+INFO, CODE, and LANG are provided by `org-latex-inline-src-block'."
+ (let* ((lst-lang (or (cadr (assq (intern lang)
+ (plist-get info :latex-listings-langs)))
+ lang))
+ (separator (org-latex--find-verb-separator code))
+ (options (org-latex--make-option-string
+ (append (plist-get info :latex-listings-options)
+ `(("language" ,lst-lang))))))
+ (concat (format "\\lstinline[%s]" options)
+ separator code separator)))
;;;; Inlinetask
--
2.35.3
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #4: 0003-ox-latex-More-versitile-option-construction.patch --]
[-- Type: text/x-patch, Size: 4118 bytes --]
From 108f321a80de89c72974fc25fcde36c85023daca Mon Sep 17 00:00:00 2001
From: TEC <tec@tecosaur.com>
Date: Wed, 4 May 2022 23:31:59 +0800
Subject: [PATCH 03/10] ox-latex: More versitile option construction
* lisp/ox-latex.el (org-latex--make-option-string): Support a custom
option seperator string.
(org-latex--make-option-string, org-latex-minted-options,
org-latex-listings-options): The first line of the docstrings for
`org-latex-minted-options` and `org-latex-listings-options` describe the
variables as "association lists", yet `org-latex--make-option-string`
does not handle association lists and an example of two-value lists is
provided. To make the behaviour match the docstring,
`org-latex--make-option-string` is modified to work with either a list
two-value lists or an association list, and the examples in
`org-latex-minted-options` and `org-latex-listings-options` updated
accordingly.
---
lisp/ox-latex.el | 38 ++++++++++++++++++++++++--------------
1 file changed, 24 insertions(+), 14 deletions(-)
diff --git a/lisp/ox-latex.el b/lisp/ox-latex.el
index 38f36a1f3..2d4b3bace 100644
--- a/lisp/ox-latex.el
+++ b/lisp/ox-latex.el
@@ -1006,12 +1006,16 @@ (defcustom org-latex-listings-options nil
These options are supplied as a comma-separated list to the
\\lstset command. Each element of the association list should be
-a list containing two strings: the name of the option, and the
-value. For example,
+a list or cons cell containing two strings: the name of the
+option, and the value. For example,
(setq org-latex-listings-options
\\='((\"basicstyle\" \"\\\\small\")
(\"keywordstyle\" \"\\\\color{black}\\\\bfseries\\\\underbar\")))
+ ; or
+ (setq org-latex-listings-options
+ \\='((\"basicstyle\" . \"\\\\small\")
+ (\"keywordstyle\" . \"\\\\color{black}\\\\bfseries\\\\underbar\")))
will typeset the code in a small size font with underlined, bold
black keywords.
@@ -1059,11 +1063,14 @@ (defcustom org-latex-minted-options nil
These options are supplied within square brackets in
\\begin{minted} environments. Each element of the alist should
-be a list containing two strings: the name of the option, and the
-value. For example,
+be a list or cons cell containing two strings: the name of the
+option, and the value. For example,
(setq org-latex-minted-options
\\='((\"bgcolor\" \"bg\") (\"frame\" \"lines\")))
+ ; or
+ (setq org-latex-minted-options
+ \\='((\"bgcolor\" . \"bg\") (\"frame\" . \"lines\")))
will result in source blocks being exported with
@@ -1506,21 +1513,24 @@ (defun org-latex--find-verb-separator (s)
when (not (string-match (regexp-quote (char-to-string c)) s))
return (char-to-string c))))
-(defun org-latex--make-option-string (options)
+(defun org-latex--make-option-string (options &optional seperator)
"Return a comma separated string of keywords and values.
OPTIONS is an alist where the key is the options keyword as
a string, and the value a list containing the keyword value, or
nil."
(mapconcat (lambda (pair)
- (pcase-let ((`(,keyword ,value) pair))
- (concat keyword
- (and (> (length value) 0)
- (concat "="
- (if (string-match-p (rx (any "[]")) value)
- (format "{%s}" value)
- value))))))
- options
- ","))
+ (let ((keyword (car pair))
+ (value (pcase (cdr pair)
+ ((pred stringp) (cdr pair))
+ ((pred consp) (cadr pair)))))
+ (concat keyword
+ (when value
+ (concat "="
+ (if (string-match-p (rx (any "[]")) value)
+ (format "{%s}" value)
+ value))))))
+ options
+ (or seperator ",")))
(defun org-latex--wrap-label (element output info)
"Wrap label associated to ELEMENT around OUTPUT, if appropriate.
--
2.35.3
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #5: 0004-ox-latex-Introduce-engraved-code-highlighting.patch --]
[-- Type: text/x-patch, Size: 18190 bytes --]
From 6f2edb89ff4dd5ce7d6618fc13fa83cbeb028e7b Mon Sep 17 00:00:00 2001
From: TEC <tec@tecosaur.com>
Date: Sun, 21 Nov 2021 20:04:12 +0800
Subject: [PATCH 04/10] ox-latex: Introduce "engraved" code highlighting
* lisp/ox-latex.el (org-latex-src-block, org-latex-src-block--engraved,
org-latex-inline-src-block, org-latex-inline-src-block--engraved,
org-latex-src--engrave-code, org-latex-template, org-latex-listings):
Make use of the engraved-faces package (available on ELPA) to provide an
alternative LaTeX code highlighting backend which functions similarly to
htmlize.el for HTML exports.
(org-latex-engraved-preamble, org-latex-engraved-options): Introduce
variables to construct the preamble for engraved code blocks.
* lisp/ox-beamer.el (org-beamer-template): Modify to add engrave-faces
preamble when applicable.
---
lisp/ox-beamer.el | 11 ++
lisp/ox-latex.el | 294 ++++++++++++++++++++++++++++++++++++++++++++--
2 files changed, 296 insertions(+), 9 deletions(-)
diff --git a/lisp/ox-beamer.el b/lisp/ox-beamer.el
index 6be73c91e..4d40f6a1d 100644
--- a/lisp/ox-beamer.el
+++ b/lisp/ox-beamer.el
@@ -857,6 +857,17 @@ (defun org-beamer-template (contents info)
(let ((template (plist-get info :latex-hyperref-template)))
(and (stringp template)
(format-spec template (org-latex--format-spec info))))
+ ;; engrave-faces-latex preamble
+ (when (eq org-latex-listings 'engraved)
+ (let ((src-p (org-element-map (plist-get info :parse-tree)
+ '(src-block inline-src-block) #'identity
+ info t))
+ (fixedw-p
+ (org-element-map (plist-get info :parse-tree)
+ '(example-block fixed-width) #'identity
+ info t)))
+ (when (or src-p fixedw-p)
+ (org-latex-generate-engraved-preamble info src-p))))
;; Document start.
"\\begin{document}\n\n"
;; Title command.
diff --git a/lisp/ox-latex.el b/lisp/ox-latex.el
index 2d4b3bace..1f4d4007d 100644
--- a/lisp/ox-latex.el
+++ b/lisp/ox-latex.el
@@ -37,6 +37,8 @@ (defvar org-latex-default-packages-alist)
(defvar org-latex-packages-alist)
(defvar orgtbl-exp-regexp)
+(declare-function engrave-faces-latex-gen-preamble "ext:engrave-faces-latex")
+(declare-function engrave-faces-latex-buffer "ext:engrave-faces-latex")
\f
;;; Define Back-End
@@ -125,6 +127,8 @@ (org-export-define-backend 'latex
(:latex-default-quote-environment nil nil org-latex-default-quote-environment)
(:latex-default-table-mode nil nil org-latex-default-table-mode)
(:latex-diary-timestamp-format nil nil org-latex-diary-timestamp-format)
+ (:latex-engraved-options nil nil org-latex-engraved-options)
+ (:latex-engraved-preamble nil nil org-latex-engraved-preamble)
(:latex-footnote-defined-format nil nil org-latex-footnote-defined-format)
(:latex-footnote-separator nil nil org-latex-footnote-separator)
(:latex-format-drawer-function nil nil org-latex-format-drawer-function)
@@ -937,22 +941,48 @@ (defcustom org-latex-listings nil
"Non-nil means export source code using the listings package.
This package will fontify source code, possibly even with color.
-If you want to use this, you also need to make LaTeX use the
-listings package, and if you want to have color, the color
-package. Just add these to `org-latex-packages-alist', for
-example using customize, or with something like:
+There are four implementations of this functionality you may
+choose from (ordered from least to most capable):
+1. Verbatim (nil)
+2. Listings (t)
+3. Minted (minted)
+4. Engraved (engraved)
+
+The first two options provide basic syntax
+highlighting (listings), or none at all (verbatim).
+
+When using listings, you also need to make use of the LaTeX
+\"listings\" package. The \"color\" package is also needed if you
+would like color too. These can simply be added to
+`org-latex-packages-alist', using customise or something like:
(require \\='ox-latex)
(add-to-list \\='org-latex-packages-alist \\='(\"\" \"listings\"))
(add-to-list \\='org-latex-packages-alist \\='(\"\" \"color\"))
-Alternatively,
+There are two further options for more comprehensive
+fontification. The first can be set with,
+
+ (setq org-latex-listings \\='engraved)
+
+which causes source code to be run through
+`engrave-faces-latex-buffer', which generates colorings using
+Emacs' font-lock information. This requires the engrave-faces
+package (availible from ELPA), and the fvextra LaTeX package be
+installed.
+
+The styling of the engraved result can customised with
+`org-latex-engraved-preamble' and `org-latex-engraved-options'.
+The default preamble also uses the tcolorbox LaTeX package in
+addition to fvextra.
+
+The second more comprehensive option can be set with,
(setq org-latex-listings \\='minted)
-causes source code to be exported using the minted package as
-opposed to listings. If you want to use minted, you need to add
-the minted package to `org-latex-packages-alist', for example
+which causes source code to be exported using the minted package
+as opposed to listings. If you want to use minted, you need to
+add the minted package to `org-latex-packages-alist', for example
using customize, or with
(require \\='ox-latex)
@@ -971,8 +1001,9 @@ (defcustom org-latex-listings nil
:type '(choice
(const :tag "Use listings" t)
(const :tag "Use minted" minted)
+ (const :tag "Use engrave-faces-latex" engraved)
(const :tag "Export verbatim" nil))
- :safe (lambda (s) (memq s '(t nil minted))))
+ :safe (lambda (s) (memq s '(t nil minted engraved))))
(defcustom org-latex-listings-langs
'((emacs-lisp "Lisp") (lisp "Lisp") (clojure "Lisp")
@@ -1142,6 +1173,148 @@ (defcustom org-latex-custom-lang-environments nil
:version "26.1"
:package-version '(Org . "9.0"))
+(defcustom org-latex-engraved-preamble
+ "\\usepackage{fvextra}
+
+[FVEXTRA-SETUP]
+
+% Make line numbers smaller and grey.
+\\renewcommand\\theFancyVerbLine{\\footnotesize\\color{black!40!white}\\arabic{FancyVerbLine}}
+
+\\usepackage{xcolor}
+
+% In case engrave-faces-latex-gen-preamble has not been run.
+\\providecolor{EfD}{HTML}{f7f7f7}
+\\providecolor{EFD}{HTML}{28292e}
+
+% Define a Code environment to prettily wrap the fontified code.
+\\usepackage[breakable,xparse]{tcolorbox}
+\\DeclareTColorBox[]{Code}{o}%
+{colback=EfD!98!EFD, colframe=EfD!95!EFD,
+ fontupper=\\footnotesize\\setlength{\\fboxsep}{0pt},
+ colupper=EFD,
+ IfNoValueTF={#1}%
+ {boxsep=2pt, arc=2.5pt, outer arc=2.5pt,
+ boxrule=0.5pt, left=2pt}%
+ {boxsep=2.5pt, arc=0pt, outer arc=0pt,
+ boxrule=0pt, leftrule=1.5pt, left=0.5pt},
+ right=2pt, top=1pt, bottom=0.5pt,
+ breakable}
+
+[LISTINGS-SETUP]"
+ "Preamble content injected when using engrave-faces-latex for source blocks.
+This is relevant when `org-latex-listings' is set to `engraved'.
+
+There is quite a lot of flexibility in what this preamble can be,
+as long as it:
+- Loads the fvextra package.
+- Loads the package xcolor (if it is not already loaded elsewhere).
+- Defines a \"Code\" environment (note the capital C), which all
+ \"Verbatim\" environments (provided by fvextra) will be wrapped with.
+
+In the default value the color \"EFD\" is provided as this is the
+foreground colour provided by engrave-faces-latex. When there
+are example/fixed-width blocks only, the engraved generated
+preamble is not included, and so it is provided so we may use it
+anyway.
+
+Within this preamble there are two recognised macro-like placeholders:
+
+ [FVEXTRA-SETUP]
+
+ [LISTINGS-SETUP]
+
+FVEXTRA-SETUP sets fvextra's defaults according to
+`org-latex-engraved-options', and LISTINGS-SETUP creates the
+listings environment and defines \\listoflistings."
+ :group 'org-export-latex
+ :type 'string
+ :package-version '(Org . "9.6"))
+
+(defcustom org-latex-engraved-options
+ '(("commandchars" . "\\\\\\{\\}")
+ ("highlightcolor" . "white!95!black!80!blue")
+ ("breaklines" . "true")
+ ("breaksymbol" . "\\color{white!60!black}\\tiny\\ensuremath{\\hookrightarrow}"))
+ "Association list of options for the latex fvextra package when engraving code.
+
+These options are set using \\fvset{...} in the preamble of the
+LaTeX export. Each element of the alist should be a list or cons
+cell containing two strings: the name of the option, and the
+value. For example,
+
+ (setq org-latex-engraved-options
+ \\='((\"highlightcolor\" \"green\") (\"frame\" \"lines\")))
+ ; or
+ (setq org-latex-engraved-options
+ \\='((\"highlightcolor\" . \"green\") (\"frame\" . \"lines\")))
+
+will result in the following LaTeX in the preamble
+
+\\fvset{%
+ bgcolor=bg,
+ frame=lines}
+
+This will affect all fvextra environments. Note that the same
+options will be applied to all blocks. If you need
+block-specific options, you may use the following syntax:
+
+ #+ATTR_LATEX: :options key1=value1,key2=value2
+ #+BEGIN_SRC <LANG>
+ ...
+ #+END_SRC"
+ :group 'org-export-latex
+ :type '(alist :key-type (string :tag "option")
+ :value-type (string :tag "value")))
+
+(defun org-latex-generate-engraved-preamble (info syntax-colours-p)
+ "Generate the preamble to setup engraved code.
+The result is constructed from the :latex-engraved-preamble and
+:latex-engraved-optionsn export options, the default values of
+which are given by `org-latex-engraved-preamble' and
+`org-latex-engraved-options' respectively."
+ (let* ((engraved-options
+ (plist-get info :latex-engraved-options))
+ (engraved-preamble (plist-get info :latex-engraved-preamble)))
+ (when (string-match "^[ \t]*\\[FVEXTRA-SETUP\\][ \t]*\n?" engraved-preamble)
+ (setq engraved-preamble
+ (replace-match
+ (concat
+ "\\fvset{%\n "
+ (org-latex--make-option-string engraved-options ",\n ")
+ "}\n")
+ t t
+ engraved-preamble)))
+ (when (string-match "^[ \t]*\\[LISTINGS-SETUP\\][ \t]*\n?" engraved-preamble)
+ (setq engraved-preamble
+ (replace-match
+ (format
+ "%% Support listings with captions
+\\usepackage{float}
+\\floatstyle{%s}
+\\newfloat{listing}{htbp}{lst}
+\\newcommand{\\listingsname}{Listing}
+\\floatname{listing}{\\listingsname}
+\\newcommand{\\listoflistingsname}{List of Listings}
+\\providecommand{\\listoflistings}{\\listof{listing}{\\listoflistingsname}}\n"
+ (if (memq 'src-block org-latex-caption-above)
+ "plaintop" "plain"))
+ t t
+ engraved-preamble)))
+ (if syntax-colours-p
+ (concat
+ "\n% Setup for code blocks [1/2]\n\n"
+ engraved-preamble
+ "\n\n% Setup for code blocks [2/2]: syntax highlighting colors\n"
+ (if (require 'engrave-faces-latex nil t)
+ (engrave-faces-latex-gen-preamble)
+ (message "Cannot engrave source blocks. Consider installing `engrave-faces'.")
+ "% WARNING syntax highlighting unavailible as engrave-faces-latex was missing.\n")
+ "\n")
+ (concat
+ "\n% Setup for code blocks\n\n"
+ engraved-preamble
+ "\n"))))
;;;; Compilation
@@ -1756,6 +1929,17 @@ (defun org-latex-template (contents info)
(let ((template (plist-get info :latex-hyperref-template)))
(and (stringp template)
(format-spec template spec)))
+ ;; engrave-faces-latex preamble
+ (when (eq org-latex-listings 'engraved)
+ (let ((src-p (org-element-map (plist-get info :parse-tree)
+ '(src-block inline-src-block) #'identity
+ info t))
+ (fixedw-p
+ (org-element-map (plist-get info :parse-tree)
+ '(example-block fixed-width) #'identity
+ info t)))
+ (when (or src-p fixedw-p)
+ (org-latex-generate-engraved-preamble info src-p))))
;; Document start.
"\\begin{document}\n\n"
;; Title command.
@@ -2142,6 +2326,7 @@ (defun org-latex-inline-src-block (inline-src-block _contents info)
(pcase (plist-get info :latex-listings)
('nil (org-latex--text-markup code 'code info))
('minted (org-latex-inline-src-block--minted info code lang))
+ ('engraved (org-latex-inline-src-block--engraved info code lang))
(_ (org-latex-inline-src-block--listings info code lang)))))
(defun org-latex-inline-src-block--minted (info code lang)
@@ -2157,6 +2342,11 @@ (defun org-latex-inline-src-block--minted (info code lang)
mint-lang
code)))
+(defun org-latex-inline-src-block--engraved (_info code lang)
+ "Transcode an inline src block's content from Org to LaTeX, using engrave-faces.
+INFO, CODE, and LANG are provided by `org-latex-inline-src-block'."
+ (format "\\Verb{%s}" (org-latex-src--engrave-code code lang)))
+
(defun org-latex-inline-src-block--listings (info code lang)
"Transcode an inline src block's content from Org to LaTeX, using lstlistings.
INFO, CODE, and LANG are provided by `org-latex-inline-src-block'."
@@ -2323,6 +2513,7 @@ (defun org-latex-keyword (keyword _contents info)
(cl-case (plist-get info :latex-listings)
((nil) "\\listoffigures")
(minted "\\listoflistings")
+ (engraved "\\listoflistings")
(otherwise "\\lstlistoflistings")))))))))
@@ -3017,6 +3208,9 @@ (defun org-latex-src-block (src-block _contents info)
num-start retain-labels attributes float custom-env))
((eq listings 'minted)
(org-latex-src-block--minted src-block info lang caption caption-above-p label
+ num-start retain-labels attributes float))
+ ((eq listings 'engraved)
+ (org-latex-src-block--engraved src-block info lang caption caption-above-p label
num-start retain-labels attributes float))
(t
(org-latex-src-block--listings src-block info lang caption caption-above-p label
@@ -3133,6 +3327,88 @@ (defun org-latex-src-block--minted
;; Return value.
(format float-env body)))
+(defun org-latex-src--engrave-code (content lang)
+ "Engrave CONTENT to LaTeX in a LANG-mode buffer, and give the result."
+ (if (require 'engrave-faces-latex nil t)
+ (let* ((lang-mode (and lang (org-src-get-lang-mode lang)))
+ (engraved-buffer
+ (with-temp-buffer
+ (insert content)
+ (when lang-mode
+ (if (functionp lang-mode)
+ (funcall lang-mode)
+ (message "Cannot engrave code as %s. %s is undefined."
+ lang lang-mode)))
+ (engrave-faces-latex-buffer)))
+ (engraved-code
+ (with-current-buffer engraved-buffer
+ (buffer-string))))
+ (kill-buffer engraved-buffer)
+ engraved-code)
+ (user-error "Cannot engrave code as `engrave-faces-latex' is unavailible.")))
+
+(defun org-latex-src-block--engraved
+ (src-block info lang caption caption-above-p _label
+ num-start retain-labels attributes float)
+ "Transcode a SRC-BLOCK element from Org to LaTeX, using engrave-faces-latex.
+LANG, CAPTION, CAPTION-ABOVE-P, LABEL, NUM-START, RETAIN-LABELS, ATTRIBUTES
+and FLOAT are extracted from SRC-BLOCK and INFO in `org-latex-src-block'."
+ (let* ((caption-str (org-latex--caption/label-string src-block info))
+ (placement (or (org-unbracket-string "[" "]" (plist-get attributes :placement))
+ (plist-get info :latex-default-figure-position)))
+ (float-env
+ (cond
+ ((string= "multicolumn" float)
+ (format "\\begin{listing*}[%s]\n%s%%s\n%s\\end{listing*}"
+ placement
+ (if caption-above-p caption-str "")
+ (if caption-above-p "" caption-str)))
+ (caption
+ (format "\\begin{listing}[%s]\n%s%%s\n%s\\end{listing}"
+ placement
+ (if caption-above-p caption-str "")
+ (if caption-above-p "" caption-str)))
+ ((string= "t" float)
+ (concat (format "\\begin{listing}[%s]\n"
+ placement)
+ "%s\n\\end{listing}"))
+ (t "%s")))
+ (options (plist-get info :latex-engraved-options))
+ (content
+ (let* ((code-info (org-export-unravel-code src-block))
+ (max-width
+ (apply 'max
+ (mapcar 'string-width
+ (org-split-string (car code-info)
+ "\n")))))
+ (org-export-format-code
+ (car code-info)
+ (lambda (loc _num ref)
+ (concat
+ loc
+ (when ref
+ ;; Ensure references are flushed to the right,
+ ;; separated with 6 spaces from the widest line
+ ;; of code.
+ (concat (make-string (+ (- max-width (length loc)) 6)
+ ?\s)
+ (format "(%s)" ref)))))
+ nil (and retain-labels (cdr code-info)))))
+ (body
+ (format
+ "\\begin{Code}\n\\begin{Verbatim}[%s]\n%s\\end{Verbatim}\n\\end{Code}"
+ ;; Options.
+ (concat
+ (org-latex--make-option-string
+ (append
+ (when (and num-start (not (assoc "linenos" options)))
+ `(("linenos")
+ ("firstnumber" ,(number-to-string (1+ num-start)))))
+ (let ((local-options (plist-get attributes :options)))
+ (and local-options (list local-options))))))
+ (org-latex-src--engrave-code content lang))))
+ (format float-env body)))
+
(defun org-latex-src-block--listings
(src-block info lang caption caption-above-p label
num-start retain-labels attributes float)
--
2.35.3
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #6: 0005-ox-latex-Don-t-use-length-to-get-string-width.patch --]
[-- Type: text/x-patch, Size: 1539 bytes --]
From 27a83b36b77e267feb3267d6a4dffd16fdf1d5a7 Mon Sep 17 00:00:00 2001
From: TEC <tec@tecosaur.com>
Date: Sat, 7 May 2022 13:59:13 +0800
Subject: [PATCH 05/10] ox-latex: Don't use `length' to get string width
* lisp/ox-latex.el (org-latex-src-block--listings,
org-latex-src-block--engraved, org-latex-src-block--minted): Use
`string-width' instead of `length' to gauge the displayed width of the
string in LaTeX. This may not be a perfect match, but it should be an
improvement.
---
lisp/ox-latex.el | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/lisp/ox-latex.el b/lisp/ox-latex.el
index 1f4d4007d..13ba6cd8c 100644
--- a/lisp/ox-latex.el
+++ b/lisp/ox-latex.el
@@ -3308,7 +3308,7 @@ (defun org-latex-src-block--minted
(let* ((code-info (org-export-unravel-code src-block))
(max-width
(apply 'max
- (mapcar 'length
+ (mapcar 'string-width
(org-split-string (car code-info)
"\n")))))
(org-export-format-code
@@ -3460,7 +3460,7 @@ (defun org-latex-src-block--listings
(let* ((code-info (org-export-unravel-code src-block))
(max-width
(apply 'max
- (mapcar 'length
+ (mapcar 'string-width
(org-split-string (car code-info) "\n")))))
(org-export-format-code
(car code-info)
--
2.35.3
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #7: 0006-ox-latex-Refactor-source-block-transcode-fun-sigs.patch --]
[-- Type: text/x-patch, Size: 7299 bytes --]
From ce7b8d8d1eafa6f2e6d0e247661000fc5272a24c Mon Sep 17 00:00:00 2001
From: TEC <tec@tecosaur.com>
Date: Sat, 7 May 2022 14:02:44 +0800
Subject: [PATCH 06/10] ox-latex: Refactor source block transcode fun sigs
* lisp/ox-latex.el (org-latex-src-block--listings,
org-latex-src-block--engraved, org-latex-src-block--minted,
org-latex-src-block--custom): Refactor these --backend functions to use
cl-defun with keys instead of having an 11-argument signature.
(org-latex-src-block): Adjust for the change in signature of the
--backend functions, and refactor the `cond' statement to use `pcase'.
---
lisp/ox-latex.el | 82 +++++++++++++++++++++++-------------------------
1 file changed, 39 insertions(+), 43 deletions(-)
diff --git a/lisp/ox-latex.el b/lisp/ox-latex.el
index 13ba6cd8c..4421bb8f5 100644
--- a/lisp/ox-latex.el
+++ b/lisp/ox-latex.el
@@ -3188,37 +3188,37 @@ (defun org-latex-src-block (src-block _contents info)
contextual information."
(when (org-string-nw-p (org-element-property :value src-block))
(let* ((lang (org-element-property :language src-block))
- (caption (org-element-property :caption src-block))
- (caption-above-p (org-latex--caption-above-p src-block info))
- (label (org-element-property :name src-block))
- (custom-env (and lang
- (cadr (assq (intern lang)
- org-latex-custom-lang-environments))))
- (num-start (org-export-get-loc src-block info))
- (retain-labels (org-element-property :retain-labels src-block))
- (attributes (org-export-read-attribute :attr_latex src-block))
- (float (plist-get attributes :float))
- (listings (plist-get info :latex-listings)))
- (cond
- ((or (not lang) (not listings))
- (org-latex-src-block--verbatim src-block info lang caption caption-above-p label
- num-start retain-labels attributes float))
- (custom-env
- (org-latex-src-block--custom src-block info lang caption caption-above-p label
- num-start retain-labels attributes float custom-env))
- ((eq listings 'minted)
- (org-latex-src-block--minted src-block info lang caption caption-above-p label
- num-start retain-labels attributes float))
- ((eq listings 'engraved)
- (org-latex-src-block--engraved src-block info lang caption caption-above-p label
- num-start retain-labels attributes float))
- (t
- (org-latex-src-block--listings src-block info lang caption caption-above-p label
- num-start retain-labels attributes float))))))
-
-(defun org-latex-src-block--verbatim
- (src-block info _lang caption caption-above-p _label
- _num-start _retain-labels _attributes float)
+ (caption (org-element-property :caption src-block))
+ (caption-above-p (org-latex--caption-above-p src-block info))
+ (label (org-element-property :name src-block))
+ (custom-env (and lang
+ (cadr (assq (intern lang)
+ org-latex-custom-lang-environments))))
+ (num-start (org-export-get-loc src-block info))
+ (retain-labels (org-element-property :retain-labels src-block))
+ (attributes (org-export-read-attribute :attr_latex src-block))
+ (float (plist-get attributes :float))
+ (listings (plist-get info :latex-listings)))
+ (funcall
+ (pcase listings
+ ((or (pred not) (guard (not lang))) #'org-latex-src-block--verbatim)
+ ((guard custom-env) #'org-latex-src-block--custom)
+ ('minted #'org-latex-src-block--minted)
+ ('engraved #'org-latex-src-block--engraved)
+ (_ #'org-latex-src-block--listings))
+ :src-block src-block
+ :info info
+ :lang lang
+ :caption caption
+ :caption-above-p caption-above-p
+ :label label
+ :num-start num-start
+ :retain-labels retain-labels
+ :attributes attributes
+ :float float))))
+
+(cl-defun org-latex-src-block--verbatim
+ (&key src-block info caption caption-above-p float &allow-other-keys)
"Transcode a SRC-BLOCK element from Org to LaTeX, using verbatim.
LANG, CAPTION, CAPTION-ABOVE-P, LABEL, NUM-START, RETAIN-LABELS, ATTRIBUTES
and FLOAT are extracted from SRC-BLOCK and INFO in `org-latex-src-block'."
@@ -3237,9 +3237,8 @@ (defun org-latex-src-block--verbatim
(if caption-above-p "" (concat "\n" caption-str))))
(t verbatim))))
-(defun org-latex-src-block--custom
- (src-block info _lang caption caption-above-p _label
- _num-start _retain-labels attributes float custom-env)
+(cl-defun org-latex-src-block--custom
+ (&key src-block info caption caption-above-p attributes float custom-env &allow-other-keys)
"Transcode a SRC-BLOCK element from Org to LaTeX, using a custom environment.
LANG, CAPTION, CAPTION-ABOVE-P, LABEL, NUM-START, RETAIN-LABELS, ATTRIBUTES
and FLOAT are extracted from SRC-BLOCK and INFO in `org-latex-src-block'."
@@ -3259,9 +3258,8 @@ (defun org-latex-src-block--custom
(?l . ,(org-latex--label src-block info))
(?o . ,(or (plist-get attributes :options) "")))))))
-(defun org-latex-src-block--minted
- (src-block info lang caption caption-above-p _label
- num-start retain-labels attributes float)
+(cl-defun org-latex-src-block--minted
+ (&key src-block info lang caption caption-above-p num-start retain-labels attributes float &allow-other-keys)
"Transcode a SRC-BLOCK element from Org to LaTeX, using minted.
LANG, CAPTION, CAPTION-ABOVE-P, LABEL, NUM-START, RETAIN-LABELS, ATTRIBUTES
and FLOAT are extracted from SRC-BLOCK and INFO in `org-latex-src-block'."
@@ -3347,9 +3345,8 @@ (defun org-latex-src--engrave-code (content lang)
engraved-code)
(user-error "Cannot engrave code as `engrave-faces-latex' is unavailible.")))
-(defun org-latex-src-block--engraved
- (src-block info lang caption caption-above-p _label
- num-start retain-labels attributes float)
+(cl-defun org-latex-src-block--engraved
+ (&key src-block info lang caption caption-above-p num-start retain-labels attributes float &allow-other-keys)
"Transcode a SRC-BLOCK element from Org to LaTeX, using engrave-faces-latex.
LANG, CAPTION, CAPTION-ABOVE-P, LABEL, NUM-START, RETAIN-LABELS, ATTRIBUTES
and FLOAT are extracted from SRC-BLOCK and INFO in `org-latex-src-block'."
@@ -3409,9 +3406,8 @@ (defun org-latex-src-block--engraved
(org-latex-src--engrave-code content lang))))
(format float-env body)))
-(defun org-latex-src-block--listings
- (src-block info lang caption caption-above-p label
- num-start retain-labels attributes float)
+(cl-defun org-latex-src-block--listings
+ (&key src-block info lang caption caption-above-p label num-start retain-labels attributes float &allow-other-keys)
"Transcode a SRC-BLOCK element from Org to LaTeX, using listings.
LANG, CAPTION, CAPTION-ABOVE-P, LABEL, NUM-START, RETAIN-LABELS, ATTRIBUTES
and FLOAT are extracted from SRC-BLOCK and INFO in `org-latex-src-block'."
--
2.35.3
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #8: 0007-ox-latex-Replace-org-latex-listings.patch --]
[-- Type: text/x-patch, Size: 16058 bytes --]
From 17e91e6816eeeed398a7f2779108e499729005c8 Mon Sep 17 00:00:00 2001
From: TEC <tec@tecosaur.com>
Date: Sat, 7 May 2022 14:46:28 +0800
Subject: [PATCH 07/10] ox-latex: Replace `org-latex-listings'
* lisp/ox-latex.el (org-latex-src-block, org-latex-keyword,
org-latex-inline-src-block, org-latex-template,
org-latex--caption/label-string, org-latex-engraved-preamble,
org-latex-listings): Replace `org-latex-listings' with
`org-latex-src-block-backend', which now can be set to listings/verbatim
and no longer advertises t/nil as valid values.
* lisp/ox-beamer.el (org-beamer-template): Update in the same manner as
`org-latex-template'.
* lisp/org-compat.el: Make `org-latex-listings' an obsolete alias for
`org-latex-src-block-backend'.
* testing/lisp/test-ox.el: Replace `org-latex-listings' reference with
`org-latex-src-block-backend'.
* doc/org-manual.org (Footnotes, LaTeX specific properties, Literal
Examples): Replace references to `org-latex-listings' with
`org-latex-src-block-backend'.
* etc/ORG-NEWS: Add a news entry noting this change.
The variable `org-latex-listings' originally indicated whether source
blocks should use the listings LaTeX package, or not. This usage has
evolved over the years, and now it sets one of four different
fontification backends. This renaming should make the variable name a
bit less misleading.
---
doc/org-manual.org | 6 +--
etc/ORG-NEWS | 9 ++++
lisp/org-compat.el | 2 +
lisp/ox-beamer.el | 2 +-
lisp/ox-latex.el | 111 ++++++++++++++++++++++------------------
testing/lisp/test-ox.el | 2 +-
6 files changed, 78 insertions(+), 54 deletions(-)
diff --git a/doc/org-manual.org b/doc/org-manual.org
index c0d38cd8c..60bded419 100644
--- a/doc/org-manual.org
+++ b/doc/org-manual.org
@@ -11159,7 +11159,7 @@ ** Literal Examples
#+end_example
#+cindex: formatting source code, markup rules
-#+vindex: org-latex-listings
+#+vindex: org-latex-src-block-backend
If the example is source code from a programming language, or any
other text that can be marked up by Font Lock in Emacs, you can ask
for the example to look like the fontified Emacs buffer[fn:114]. This
@@ -16304,12 +16304,12 @@ **** LaTeX specific properties
| ~:latex-link-with-unknown-path-format~ | ~org-latex-link-with-unknown-path-format~ |
| ~:latex-listings-langs~ | ~org-latex-listings-langs~ |
| ~:latex-listings-options~ | ~org-latex-listings-options~ |
-| ~:latex-listings~ | ~org-latex-listings~ |
| ~:latex-minted-langs~ | ~org-latex-minted-langs~ |
| ~:latex-minted-options~ | ~org-latex-minted-options~ |
| ~:latex-prefer-user-labels~ | ~org-latex-prefer-user-labels~ |
| ~:latex-subtitle-format~ | ~org-latex-subtitle-format~ |
| ~:latex-subtitle-separate~ | ~org-latex-subtitle-separate~ |
+| ~:latex-src-block-backend~ | ~org-latex-src-block-backend~ |
| ~:latex-table-scientific-notation~ | ~org-latex-table-scientific-notation~ |
| ~:latex-tables-booktabs~ | ~org-latex-tables-booktabs~ |
| ~:latex-tables-centered~ | ~org-latex-tables-centered~ |
@@ -22256,7 +22256,7 @@ * Footnotes
version 1.34 of the =htmlize.el= package, which you need to install).
Fontified code chunks in LaTeX can be achieved using either the
[[https://www.ctan.org/pkg/listings][listings]] package or the [[https://www.ctan.org/pkg/minted][minted]] package. Refer to
-~org-latex-listings~ for details.
+~org-latex-src-block-backend~ for details.
[fn:115] Source code in code blocks may also be evaluated either
interactively or on export. See [[*Working with Source Code]] for more
diff --git a/etc/ORG-NEWS b/etc/ORG-NEWS
index 27de6da62..ebb3cd649 100644
--- a/etc/ORG-NEWS
+++ b/etc/ORG-NEWS
@@ -273,6 +273,15 @@ Chmod-style permissions are based on the new variable
~org-babel-tangle-default-file-mode~.
*** A new custom setting =org-agenda-clock-report-header= to add a header to org agenda clock report
+
+*** ~org-latex-listings~ has been replaced with ~org-latex-src-block-backend~
+
+~org-latex-listings~ has been renamed to better reflect the current
+purpose of the variable. The replacement variable
+~org-latex-src-block-backend~ acts in exactly the same way, however it
+accepts =listings= and =verbatim= in place of =t= and =nil= (which
+still work, but are no longer listed as valid options).
+
* Version 9.5
** Important announcements and breaking changes
diff --git a/lisp/org-compat.el b/lisp/org-compat.el
index a29f206a4..704197645 100644
--- a/lisp/org-compat.el
+++ b/lisp/org-compat.el
@@ -324,6 +324,8 @@ (define-obsolete-variable-alias 'org-latex-create-formula-image-program
'org-preview-latex-default-process "9.0")
(define-obsolete-variable-alias 'org-latex-preview-ltxpng-directory
'org-preview-latex-image-directory "9.0")
+(define-obsolete-variable-alias 'org-latex-listings
+ 'org-latex-src-block-backend "9.6")
(define-obsolete-function-alias 'org-table-p 'org-at-table-p "9.0")
(define-obsolete-function-alias 'org-on-heading-p 'org-at-heading-p "9.0")
(define-obsolete-function-alias 'org-at-regexp-p 'org-in-regexp "8.3")
diff --git a/lisp/ox-beamer.el b/lisp/ox-beamer.el
index 4d40f6a1d..3baa4e26e 100644
--- a/lisp/ox-beamer.el
+++ b/lisp/ox-beamer.el
@@ -858,7 +858,7 @@ (defun org-beamer-template (contents info)
(and (stringp template)
(format-spec template (org-latex--format-spec info))))
;; engrave-faces-latex preamble
- (when (eq org-latex-listings 'engraved)
+ (when (eq org-latex-src-block-backend 'engraved)
(let ((src-p (org-element-map (plist-get info :parse-tree)
'(src-block inline-src-block) #'identity
info t))
diff --git a/lisp/ox-latex.el b/lisp/ox-latex.el
index 4421bb8f5..cc6ac291a 100644
--- a/lisp/ox-latex.el
+++ b/lisp/ox-latex.el
@@ -143,7 +143,7 @@ (org-export-define-backend 'latex
(:latex-inactive-timestamp-format nil nil org-latex-inactive-timestamp-format)
(:latex-inline-image-rules nil nil org-latex-inline-image-rules)
(:latex-link-with-unknown-path-format nil nil org-latex-link-with-unknown-path-format)
- (:latex-listings nil nil org-latex-listings)
+ (:latex-src-block-backend nil nil org-latex-src-block-backend)
(:latex-listings-langs nil nil org-latex-listings-langs)
(:latex-listings-options nil nil org-latex-listings-options)
(:latex-minted-langs nil nil org-latex-minted-langs)
@@ -937,22 +937,22 @@ (defcustom org-latex-format-inlinetask-function
;; Src blocks
-(defcustom org-latex-listings nil
- "Non-nil means export source code using the listings package.
+(defcustom org-latex-src-block-backend 'verbatim
+ "Backend used to generate source code listings.
-This package will fontify source code, possibly even with color.
-There are four implementations of this functionality you may
+This sets the behaviour for fontifying source code, possibly even with
+color. There are four implementations of this functionality you may
choose from (ordered from least to most capable):
-1. Verbatim (nil)
-2. Listings (t)
-3. Minted (minted)
-4. Engraved (engraved)
+1. Verbatim
+2. Listings
+3. Minted
+4. Engraved
The first two options provide basic syntax
highlighting (listings), or none at all (verbatim).
-When using listings, you also need to make use of the LaTeX
-\"listings\" package. The \"color\" package is also needed if you
+When using listings, you also need to make use of LaTeX package
+\"listings\"e. The \"color\" LaTeX package is also needed if you
would like color too. These can simply be added to
`org-latex-packages-alist', using customise or something like:
@@ -963,27 +963,12 @@ (defcustom org-latex-listings nil
There are two further options for more comprehensive
fontification. The first can be set with,
- (setq org-latex-listings \\='engraved)
+ (setq org-latex-src-block-backend \\='minted)
-which causes source code to be run through
-`engrave-faces-latex-buffer', which generates colorings using
-Emacs' font-lock information. This requires the engrave-faces
-package (availible from ELPA), and the fvextra LaTeX package be
-installed.
-
-The styling of the engraved result can customised with
-`org-latex-engraved-preamble' and `org-latex-engraved-options'.
-The default preamble also uses the tcolorbox LaTeX package in
-addition to fvextra.
-
-The second more comprehensive option can be set with,
-
- (setq org-latex-listings \\='minted)
-
-which causes source code to be exported using the minted package
-as opposed to listings. If you want to use minted, you need to
-add the minted package to `org-latex-packages-alist', for example
-using customize, or with
+which causes source code to be exported using the LaTeX package
+minted as opposed to listings. If you want to use minted, you
+need to add the minted package to `org-latex-packages-alist', for
+example using customize, or with
(require \\='ox-latex)
(add-to-list \\='org-latex-packages-alist \\='(\"newfloat\" \"minted\"))
@@ -996,14 +981,29 @@ (defcustom org-latex-listings nil
The minted choice has possible repercussions on the preview of
latex fragments (see `org-preview-latex-fragment'). If you run
into previewing problems, please consult
-URL `https://orgmode.org/worg/org-tutorials/org-latex-preview.html'."
+URL `https://orgmode.org/worg/org-tutorials/org-latex-preview.html'.
+
+The most comprehensive option can be set with,
+
+ (setq org-latex-src-block-backend \\='engraved)
+
+which causes source code to be run through
+`engrave-faces-latex-buffer', which generates colorings using
+Emacs' font-lock information. This requires the Emacs package
+engrave-faces (availible from ELPA), and the LaTeX package
+fvextra be installed.
+
+The styling of the engraved result can customised with
+`org-latex-engraved-preamble' and `org-latex-engraved-options'.
+The default preamble also uses the LaTeX package tcolorbox in
+addition to fvextra."
:group 'org-export-latex
:type '(choice
- (const :tag "Use listings" t)
+ (const :tag "Use listings" listings)
(const :tag "Use minted" minted)
(const :tag "Use engrave-faces-latex" engraved)
- (const :tag "Export verbatim" nil))
- :safe (lambda (s) (memq s '(t nil minted engraved))))
+ (const :tag "Export verbatim" verbatim))
+ :safe (lambda (s) (memq s '(listings minted engraved verbatim))))
(defcustom org-latex-listings-langs
'((emacs-lisp "Lisp") (lisp "Lisp") (clojure "Lisp")
@@ -1203,7 +1203,7 @@ (defcustom org-latex-engraved-preamble
[LISTINGS-SETUP]"
"Preamble content injected when using engrave-faces-latex for source blocks.
-This is relevant when `org-latex-listings' is set to `engraved'.
+This is relevant when `org-latex-src-block-backend' is set to `engraved'.
There is quite a lot of flexibility in what this preamble can be,
as long as it:
@@ -1523,7 +1523,8 @@ (defun org-latex--caption/label-string (element info)
main)
(and (eq type 'src-block)
(not (plist-get attr :float))
- (null (plist-get info :latex-listings)))))
+ (memq (plist-get info :latex-src-block-backend)
+ '(verbatim nil)))))
(short (org-export-get-caption element t))
(caption-from-attr-latex (plist-get attr :caption)))
(cond
@@ -1543,7 +1544,8 @@ (defun org-latex--caption/label-string (element info)
(paragraph "figure")
(image "figure")
(special-block "figure")
- (src-block (if (plist-get info :latex-listings)
+ (src-block (if (not (memq (plist-get info :latex-src-block-backend)
+ '(verbatim nil)))
"listing"
"figure"))
(t (symbol-name type*)))
@@ -1930,7 +1932,7 @@ (defun org-latex-template (contents info)
(and (stringp template)
(format-spec template spec)))
;; engrave-faces-latex preamble
- (when (eq org-latex-listings 'engraved)
+ (when (eq org-latex-src-block-backend 'engraved)
(let ((src-p (org-element-map (plist-get info :parse-tree)
'(src-block inline-src-block) #'identity
info t))
@@ -2323,11 +2325,17 @@ (defun org-latex-inline-src-block (inline-src-block _contents info)
contextual information."
(let ((code (org-element-property :value inline-src-block))
(lang (org-element-property :language inline-src-block)))
- (pcase (plist-get info :latex-listings)
- ('nil (org-latex--text-markup code 'code info))
+ (pcase (plist-get info :latex-src-block-backend)
+ ('verbatim (org-latex--text-markup code 'code info))
('minted (org-latex-inline-src-block--minted info code lang))
('engraved (org-latex-inline-src-block--engraved info code lang))
- (_ (org-latex-inline-src-block--listings info code lang)))))
+ ('listings (org-latex-inline-src-block--listings info code lang))
+ (oldval
+ (message "Please update the LaTeX src-block-backend to %s"
+ (if oldval "listings" "verbatim"))
+ (if oldval
+ (org-latex-inline-src-block--listings info code lang)
+ (org-latex--text-markup code 'code info))))))
(defun org-latex-inline-src-block--minted (info code lang)
"Transcode an inline src block's content from Org to LaTeX, using minted.
@@ -2510,7 +2518,7 @@ (defun org-latex-keyword (keyword _contents info)
(concat depth (and depth "\n") "\\tableofcontents"))))
((string-match-p "\\<tables\\>" value) "\\listoftables")
((string-match-p "\\<listings\\>" value)
- (cl-case (plist-get info :latex-listings)
+ (cl-case (plist-get info :latex-src-block-backend)
((nil) "\\listoffigures")
(minted "\\listoflistings")
(engraved "\\listoflistings")
@@ -3197,15 +3205,20 @@ (defun org-latex-src-block (src-block _contents info)
(num-start (org-export-get-loc src-block info))
(retain-labels (org-element-property :retain-labels src-block))
(attributes (org-export-read-attribute :attr_latex src-block))
- (float (plist-get attributes :float))
- (listings (plist-get info :latex-listings)))
+ (float (plist-get attributes :float)))
(funcall
- (pcase listings
- ((or (pred not) (guard (not lang))) #'org-latex-src-block--verbatim)
- ((guard custom-env) #'org-latex-src-block--custom)
+ (pcase (plist-get info :latex-src-block-backend)
+ ((or 'verbatim (guard (not lang))) #'org-latex-src-block--verbatim)
('minted #'org-latex-src-block--minted)
('engraved #'org-latex-src-block--engraved)
- (_ #'org-latex-src-block--listings))
+ ('listings #'org-latex-src-block--listings)
+ ((guard custom-env) #'org-latex-src-block--custom)
+ (oldval
+ (message "Please update the LaTeX src-block-backend to %s"
+ (if oldval "listings" "verbatim"))
+ (if oldval
+ #'org-latex-src-block--listings
+ #'org-latex-src-block--verbatim)))
:src-block src-block
:info info
:lang lang
diff --git a/testing/lisp/test-ox.el b/testing/lisp/test-ox.el
index 25e02b258..28f950813 100644
--- a/testing/lisp/test-ox.el
+++ b/testing/lisp/test-ox.el
@@ -3978,7 +3978,7 @@ (ert-deftest test-org-export/latex-src-block-verbatim-caption ()
\\end{verbatim}
\\caption{Caption is below, 60\\%s}
\\end{figure*}"
- (let ((org-latex-listings 'minted) ; inactive due to missing lang
+ (let ((org-latex-src-block-backend 'minted) ; inactive due to missing lang
(org-latex-default-figure-position "tp"))
;; Namely "multicolumn" value to get just figure environment
;; looks like a bug.
--
2.35.3
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #9: 0008-ox-latex-Support-setting-the-engraved-theme.patch --]
[-- Type: text/x-patch, Size: 3181 bytes --]
From 146146df02434f8b224b21293753f260d0d624b2 Mon Sep 17 00:00:00 2001
From: TEC <tec@tecosaur.com>
Date: Sun, 8 May 2022 02:01:34 +0800
Subject: [PATCH 08/10] ox-latex: Support setting the engraved theme
* lisp/ox-latex.el (org-latex-generate-engraved-preamble,
org-latex-engraved-theme): Introduce the new export keyword
LATEX_ENGRAVED_THEME with default value given by
`org-latex-engraved-theme'. This is used to set the engraved theme used
in org-latex-engraved-theme.
This bumps the minimum required version of engrave-faces from v0.2 to
v0.3.
---
lisp/ox-latex.el | 15 +++++++++++++--
1 file changed, 13 insertions(+), 2 deletions(-)
diff --git a/lisp/ox-latex.el b/lisp/ox-latex.el
index cc6ac291a..21541e9aa 100644
--- a/lisp/ox-latex.el
+++ b/lisp/ox-latex.el
@@ -129,6 +129,7 @@ (org-export-define-backend 'latex
(:latex-diary-timestamp-format nil nil org-latex-diary-timestamp-format)
(:latex-engraved-options nil nil org-latex-engraved-options)
(:latex-engraved-preamble nil nil org-latex-engraved-preamble)
+ (:latex-engraved-theme "LATEX_ENGRAVED_THEME" nil org-latex-engraved-theme)
(:latex-footnote-defined-format nil nil org-latex-footnote-defined-format)
(:latex-footnote-separator nil nil org-latex-footnote-separator)
(:latex-format-drawer-function nil nil org-latex-format-drawer-function)
@@ -1267,6 +1268,14 @@ (defcustom org-latex-engraved-options
:type '(alist :key-type (string :tag "option")
:value-type (string :tag "value")))
+(defcustom org-latex-engraved-theme nil
+ "The theme that should be used for engraved code, when non-nil.
+This can be set to any theme defined in `engrave-faces-themes' or
+loadable by Emacs. When set to t, the current Emacs theme is
+used."
+ :group 'org-export-latex
+ :type 'symbol)
+
(defun org-latex-generate-engraved-preamble (info syntax-colours-p)
"Generate the preamble to setup engraved code.
The result is constructed from the :latex-engraved-preamble and
@@ -1275,7 +1284,8 @@ (defun org-latex-generate-engraved-preamble (info syntax-colours-p)
`org-latex-engraved-options' respectively."
(let* ((engraved-options
(plist-get info :latex-engraved-options))
- (engraved-preamble (plist-get info :latex-engraved-preamble)))
+ (engraved-preamble (plist-get info :latex-engraved-preamble))
+ (engraved-theme (plist-get info :latex-engraved-theme)))
(when (string-match "^[ \t]*\\[FVEXTRA-SETUP\\][ \t]*\n?" engraved-preamble)
(setq engraved-preamble
(replace-match
@@ -1307,7 +1317,8 @@ (defun org-latex-generate-engraved-preamble (info syntax-colours-p)
engraved-preamble
"\n\n% Setup for code blocks [2/2]: syntax highlighting colors\n"
(if (require 'engrave-faces-latex nil t)
- (engrave-faces-latex-gen-preamble)
+ (engrave-faces-latex-gen-preamble
+ (when engraved-theme (intern engraved-theme)))
(message "Cannot engrave source blocks. Consider installing `engrave-faces'.")
"% WARNING syntax highlighting unavailible as engrave-faces-latex was missing.\n")
"\n")
--
2.35.3
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #10: 0009-ox-latex-Support-setting-engraved-theme-per-block.patch --]
[-- Type: text/x-patch, Size: 8907 bytes --]
From dc4989ccf41f09e7fce08036f89e9274ead4e257 Mon Sep 17 00:00:00 2001
From: TEC <tec@tecosaur.com>
Date: Sun, 8 May 2022 15:28:29 +0800
Subject: [PATCH 09/10] ox-latex: Support setting engraved theme per-block
* lisp/ox-latex.el (org-latex-src-block--engraved,
org-latex-src--engrave-code, org-latex-inline-src-block--engraved,
org-latex-generate-engraved-preamble): Allow for the engraved theme used
to be set on a per-src-block basis with #+attr_latex: :engraved-theme
THEME. Extra setup code is now generated in
`org-latex-generate-engraved-preamble'. To facilitate the application
of themes to src blocks, `org-latex-src--engrave-code' now takes on a
larger portion of the transcoding work.
---
lisp/ox-latex.el | 113 +++++++++++++++++++++++++++++++++++++----------
1 file changed, 89 insertions(+), 24 deletions(-)
diff --git a/lisp/ox-latex.el b/lisp/ox-latex.el
index 21541e9aa..528243a59 100644
--- a/lisp/ox-latex.el
+++ b/lisp/ox-latex.el
@@ -1285,7 +1285,27 @@ (defun org-latex-generate-engraved-preamble (info syntax-colours-p)
(let* ((engraved-options
(plist-get info :latex-engraved-options))
(engraved-preamble (plist-get info :latex-engraved-preamble))
- (engraved-theme (plist-get info :latex-engraved-theme)))
+ (engraved-theme (plist-get info :latex-engraved-theme))
+ (engraved-themes
+ (cl-delete-duplicates
+ (org-element-map
+ (plist-get info :parse-tree)
+ '(src-block inline-src-block)
+ (lambda (src)
+ (plist-get
+ (org-export-read-attribute :attr_latex src)
+ :engraved-theme))
+ info)))
+ (gen-theme-spec
+ (lambda (theme)
+ (if (eq engrave-faces-latex-output-style 'preset)
+ (engrave-faces-latex-gen-preamble (when theme (intern theme)))
+ (engrave-faces-latex-gen-preamble-line
+ 'default
+ (alist-get 'default
+ (if theme
+ (engrave-faces-get-theme (intern theme))
+ engrave-faces-current-preset-style)))))))
(when (string-match "^[ \t]*\\[FVEXTRA-SETUP\\][ \t]*\n?" engraved-preamble)
(setq engraved-preamble
(replace-match
@@ -1315,10 +1335,31 @@ (defun org-latex-generate-engraved-preamble (info syntax-colours-p)
(concat
"\n% Setup for code blocks [1/2]\n\n"
engraved-preamble
- "\n\n% Setup for code blocks [2/2]: syntax highlighting colors\n"
+ "\n\n% Setup for code blocks [2/2]: syntax highlighting colors\n\n"
(if (require 'engrave-faces-latex nil t)
- (engrave-faces-latex-gen-preamble
- (when engraved-theme (intern engraved-theme)))
+ (if engraved-themes
+ (concat
+ (mapconcat
+ (lambda (theme)
+ (format
+ "\n\\newcommand{\\engravedtheme%s}{%%\n%s\n}"
+ (replace-regexp-in-string "[^A-Za-z]" "" theme)
+ (replace-regexp-in-string
+ "newcommand" "renewcommand"
+ (replace-regexp-in-string
+ "#" "##"
+ (funcall gen-theme-spec theme)))))
+ engraved-themes
+ "\n")
+ "\n\n"
+ (cond
+ ((memq engraved-theme engraved-themes)
+ (concat "\\engravedtheme"
+ (replace-regexp-in-string
+ "[^A-Za-z]" "" engraved-theme)
+ "\n"))
+ (t (funcall gen-theme-spec engraved-theme))))
+ (funcall gen-theme-spec engraved-theme))
(message "Cannot engrave source blocks. Consider installing `engrave-faces'.")
"% WARNING syntax highlighting unavailible as engrave-faces-latex was missing.\n")
"\n")
@@ -2361,10 +2402,11 @@ (defun org-latex-inline-src-block--minted (info code lang)
mint-lang
code)))
-(defun org-latex-inline-src-block--engraved (_info code lang)
+(defun org-latex-inline-src-block--engraved (info code lang)
"Transcode an inline src block's content from Org to LaTeX, using engrave-faces.
INFO, CODE, and LANG are provided by `org-latex-inline-src-block'."
- (format "\\Verb{%s}" (org-latex-src--engrave-code code lang)))
+ (org-latex-src--engrave-code
+ code lang nil (plist-get info :latex-engraved-options) t))
(defun org-latex-inline-src-block--listings (info code lang)
"Transcode an inline src block's content from Org to LaTeX, using lstlistings.
@@ -3349,13 +3391,18 @@ (cl-defun org-latex-src-block--minted
;; Return value.
(format float-env body)))
-(defun org-latex-src--engrave-code (content lang)
- "Engrave CONTENT to LaTeX in a LANG-mode buffer, and give the result."
+(defun org-latex-src--engrave-code (content lang &optional theme options inline)
+ "Engrave CONTENT to LaTeX in a LANG-mode buffer, and give the result.
+When THEME is non-nil, it will be used."
(if (require 'engrave-faces-latex nil t)
(let* ((lang-mode (and lang (org-src-get-lang-mode lang)))
+ (engrave-faces-current-preset-style
+ (if theme
+ (engrave-faces-get-theme theme)
+ engrave-faces-current-preset-style))
(engraved-buffer
(with-temp-buffer
- (insert content)
+ (insert (string-trim-right content "\n"))
(when lang-mode
(if (functionp lang-mode)
(funcall lang-mode)
@@ -3364,9 +3411,27 @@ (defun org-latex-src--engrave-code (content lang)
(engrave-faces-latex-buffer)))
(engraved-code
(with-current-buffer engraved-buffer
- (buffer-string))))
+ (buffer-string)))
+ (engraved-options
+ (when options
+ (concat "["
+ (if (listp options)
+ (org-latex--make-option-string options)
+ options)
+ "]")))
+ (engraved-wrapped
+ (if inline
+ (concat "\\Verb" engraved-options "{" engraved-code "}")
+ (concat "\\begin{Code}\\begin{Verbatim}" engraved-options "\n"
+ engraved-code "\n\\end{Verbatim}\n\\end{Code}"))))
(kill-buffer engraved-buffer)
- engraved-code)
+ (if theme
+ (concat "{\\engravedtheme"
+ (replace-regexp-in-string "[^A-Za-z]" ""
+ (symbol-name theme))
+ engraved-wrapped
+ "}")
+ engraved-wrapped))
(user-error "Cannot engrave code as `engrave-faces-latex' is unavailible.")))
(cl-defun org-latex-src-block--engraved
@@ -3394,7 +3459,15 @@ (cl-defun org-latex-src-block--engraved
placement)
"%s\n\\end{listing}"))
(t "%s")))
- (options (plist-get info :latex-engraved-options))
+ (options
+ (let ((engraved-options (plist-get info :latex-engraved-options))
+ (local-options (plist-get attributes :options)))
+ (append
+ (when (and num-start (not (assoc "linenos" engraved-options)))
+ `(("linenos")
+ ("firstnumber" ,(number-to-string (1+ num-start)))))
+ (and local-options (list local-options)))))
+ (engraved-theme (plist-get attributes :engraved-theme))
(content
(let* ((code-info (org-export-unravel-code src-block))
(max-width
@@ -3416,18 +3489,10 @@ (cl-defun org-latex-src-block--engraved
(format "(%s)" ref)))))
nil (and retain-labels (cdr code-info)))))
(body
- (format
- "\\begin{Code}\n\\begin{Verbatim}[%s]\n%s\\end{Verbatim}\n\\end{Code}"
- ;; Options.
- (concat
- (org-latex--make-option-string
- (append
- (when (and num-start (not (assoc "linenos" options)))
- `(("linenos")
- ("firstnumber" ,(number-to-string (1+ num-start)))))
- (let ((local-options (plist-get attributes :options)))
- (and local-options (list local-options))))))
- (org-latex-src--engrave-code content lang))))
+ (org-latex-src--engrave-code
+ content lang
+ (when engraved-theme (intern engraved-theme))
+ options)))
(format float-env body)))
(cl-defun org-latex-src-block--listings
--
2.35.3
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #11: 0010-ox-latex-Fix-captions-in-minted-engraved-code.patch --]
[-- Type: text/x-patch, Size: 4986 bytes --]
From ec560f6f037b902d603e9f34bbe593cb4c6bf4a9 Mon Sep 17 00:00:00 2001
From: TEC <tec@tecosaur.com>
Date: Mon, 9 May 2022 00:04:10 +0800
Subject: [PATCH 10/10] ox-latex: Fix %-captions in minted/engraved code
* lisp/ox-latex.el (org-latex-src-block--engraved,
org-latex-src-block--minted): Refactor float-env to be clearer, and
switch from `format' to `concat' to fix the bug where %-chars in
captions are interpreted as a format specifier.
---
lisp/ox-latex.el | 55 +++++++++++++++++++++---------------------------
1 file changed, 24 insertions(+), 31 deletions(-)
diff --git a/lisp/ox-latex.el b/lisp/ox-latex.el
index 528243a59..bb8072230 100644
--- a/lisp/ox-latex.el
+++ b/lisp/ox-latex.el
@@ -3332,23 +3332,20 @@ (cl-defun org-latex-src-block--minted
(let* ((caption-str (org-latex--caption/label-string src-block info))
(placement (or (org-unbracket-string "[" "]" (plist-get attributes :placement))
(plist-get info :latex-default-figure-position)))
+ (multicolumn-p (string= "multicolumn" float))
(float-env
(cond
- ((string= "multicolumn" float)
- (format "\\begin{listing*}[%s]\n%s%%s\n%s\\end{listing*}"
- placement
- (if caption-above-p caption-str "")
- (if caption-above-p "" caption-str)))
- (caption
- (format "\\begin{listing}[%s]\n%s%%s\n%s\\end{listing}"
- placement
- (if caption-above-p caption-str "")
- (if caption-above-p "" caption-str)))
+ ((or caption multicolumn-p)
+ (cons
+ (concat "\\begin{listing" (when multicolumn-p "*")
+ "}[" placement "]\n"
+ (if caption-above-p caption-str ""))
+ (concat "\n" (if caption-above-p "" caption-str)
+ "\\end{listing" (when multicolumn-p "*") "}")))
((string= "t" float)
- (concat (format "\\begin{listing}[%s]\n"
- placement)
- "%s\n\\end{listing}"))
- (t "%s")))
+ (cons
+ (concat "\\begin{listing}[" placement "]\n")
+ "\n\\end{listing}"))))
(options (plist-get info :latex-minted-options))
(body
(format
@@ -3388,8 +3385,7 @@ (cl-defun org-latex-src-block--minted
?\s)
(format "(%s)" ref)))))
nil (and retain-labels (cdr code-info)))))))
- ;; Return value.
- (format float-env body)))
+ (concat (car float-env) body (cdr float-env))))
(defun org-latex-src--engrave-code (content lang &optional theme options inline)
"Engrave CONTENT to LaTeX in a LANG-mode buffer, and give the result.
@@ -3442,23 +3438,20 @@ (cl-defun org-latex-src-block--engraved
(let* ((caption-str (org-latex--caption/label-string src-block info))
(placement (or (org-unbracket-string "[" "]" (plist-get attributes :placement))
(plist-get info :latex-default-figure-position)))
+ (multicolumn-p (string= "multicolumn" float))
(float-env
(cond
- ((string= "multicolumn" float)
- (format "\\begin{listing*}[%s]\n%s%%s\n%s\\end{listing*}"
- placement
- (if caption-above-p caption-str "")
- (if caption-above-p "" caption-str)))
- (caption
- (format "\\begin{listing}[%s]\n%s%%s\n%s\\end{listing}"
- placement
- (if caption-above-p caption-str "")
- (if caption-above-p "" caption-str)))
+ ((or caption multicolumn-p)
+ (cons
+ (concat "\\begin{listing" (when multicolumn-p "*")
+ "}[" placement "]\n"
+ (if caption-above-p caption-str ""))
+ (concat "\n" (if caption-above-p "" caption-str)
+ "\\end{listing" (when multicolumn-p "*") "}")))
((string= "t" float)
- (concat (format "\\begin{listing}[%s]\n"
- placement)
- "%s\n\\end{listing}"))
- (t "%s")))
+ (cons
+ (concat "\\begin{listing}[" placement "]\n")
+ "\n\\end{listing}"))))
(options
(let ((engraved-options (plist-get info :latex-engraved-options))
(local-options (plist-get attributes :options)))
@@ -3493,7 +3486,7 @@ (cl-defun org-latex-src-block--engraved
content lang
(when engraved-theme (intern engraved-theme))
options)))
- (format float-env body)))
+ (concat (car float-env) body (cdr float-env))))
(cl-defun org-latex-src-block--listings
(&key src-block info lang caption caption-above-p label num-start retain-labels attributes float &allow-other-keys)
--
2.35.3
^ permalink raw reply related [relevance 6%]
* Re: [PATCH] New LaTeX code export option: engraved
2022-05-07 6:57 7% ` Timothy
@ 2022-05-07 10:40 8% ` Timothy
0 siblings, 1 reply; 200+ results
From: Timothy @ 2022-05-07 10:40 UTC (permalink / raw)
To: Ihor Radchenko; +Cc: emacs-orgmode, Daniel Fleischer, Nicolas Goaziou
[-- Attachment #1: Type: text/plain, Size: 131 bytes --]
Ooops, a paren error managed to slip in there.
Here’s a new set, with a little extra refactoring slipped in.
–
Timothy
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-ox-latex-Refactor-org-latex-src-block.patch --]
[-- Type: text/x-patch, Size: 15942 bytes --]
From d231437e2c9f96bf70520d9ddda810a95667fcdd Mon Sep 17 00:00:00 2001
From: TEC <tec@tecosaur.com>
Date: Sun, 21 Nov 2021 14:35:34 +0800
Subject: [PATCH 1/7] ox-latex: Refactor `org-latex-src-block'
* lisp/ox-latex.el (org-latex-src-block): Extract the per-format logic
from `org-latex-src-block' into new dedicated functions:
+ `org-latex-src-block--verbatim'
+ `org-latex-src-block--custom'
+ `org-latex-src-block--minted'
+ `org-latex-src-block--listings'
This makes `org-latex-src-block' much less monolithic, taking it from
175 lines to 30, and I find also makes it easier to understand.
---
lisp/ox-latex.el | 339 ++++++++++++++++++++++++++---------------------
1 file changed, 185 insertions(+), 154 deletions(-)
diff --git a/lisp/ox-latex.el b/lisp/ox-latex.el
index 841ad48bc..c2f728a1c 100644
--- a/lisp/ox-latex.el
+++ b/lisp/ox-latex.el
@@ -2997,164 +2997,195 @@ (defun org-latex-src-block (src-block _contents info)
(float (plist-get attributes :float))
(listings (plist-get info :latex-listings)))
(cond
- ;; Case 1. No source fontification.
((or (not lang) (not listings))
- (let ((caption-str (org-latex--caption/label-string src-block info))
- (verbatim (format "\\begin{verbatim}\n%s\\end{verbatim}"
- (org-export-format-code-default src-block info))))
- (cond ((string= "multicolumn" float)
- (format "\\begin{figure*}[%s]\n%s%s\n%s\\end{figure*}"
- (plist-get info :latex-default-figure-position)
- (if caption-above-p caption-str "")
- verbatim
- (if caption-above-p "" caption-str)))
- (caption (concat
- (if caption-above-p caption-str "")
- verbatim
- (if caption-above-p "" (concat "\n" caption-str))))
- (t verbatim))))
- ;; Case 2. Custom environment.
+ (org-latex-src-block--verbatim src-block info lang caption caption-above-p label
+ num-start retain-labels attributes float))
(custom-env
- (let ((caption-str (org-latex--caption/label-string src-block info))
- (formatted-src (org-export-format-code-default src-block info)))
- (if (string-match-p "\\`[a-zA-Z0-9]+\\'" custom-env)
- (format "\\begin{%s}\n%s\\end{%s}\n"
- custom-env
- (concat (and caption-above-p caption-str)
- formatted-src
- (and (not caption-above-p) caption-str))
- custom-env)
- (format-spec custom-env
- `((?s . ,formatted-src)
- (?c . ,caption)
- (?f . ,float)
- (?l . ,(org-latex--label src-block info))
- (?o . ,(or (plist-get attributes :options) "")))))))
- ;; Case 3. Use minted package.
+ (org-latex-src-block--custom src-block info lang caption caption-above-p label
+ num-start retain-labels attributes float custom-env))
((eq listings 'minted)
- (let* ((caption-str (org-latex--caption/label-string src-block info))
- (placement (or (org-unbracket-string "[" "]" (plist-get attributes :placement))
- (plist-get info :latex-default-figure-position)))
- (float-env
- (cond
- ((string= "multicolumn" float)
- (format "\\begin{listing*}[%s]\n%s%%s\n%s\\end{listing*}"
- placement
- (if caption-above-p caption-str "")
- (if caption-above-p "" caption-str)))
- (caption
- (format "\\begin{listing}[%s]\n%s%%s\n%s\\end{listing}"
- placement
- (if caption-above-p caption-str "")
- (if caption-above-p "" caption-str)))
- ((string= "t" float)
- (concat (format "\\begin{listing}[%s]\n"
- placement)
- "%s\n\\end{listing}"))
- (t "%s")))
- (options (plist-get info :latex-minted-options))
- (body
- (format
- "\\begin{minted}[%s]{%s}\n%s\\end{minted}"
- ;; Options.
- (concat
- (org-latex--make-option-string
- (if (or (not num-start) (assoc "linenos" options))
- options
- (append
- `(("linenos")
- ("firstnumber" ,(number-to-string (1+ num-start))))
- options)))
- (let ((local-options (plist-get attributes :options)))
- (and local-options (concat "," local-options))))
- ;; Language.
- (or (cadr (assq (intern lang)
- (plist-get info :latex-minted-langs)))
- (downcase lang))
- ;; Source code.
- (let* ((code-info (org-export-unravel-code src-block))
- (max-width
- (apply 'max
- (mapcar 'length
- (org-split-string (car code-info)
- "\n")))))
- (org-export-format-code
- (car code-info)
- (lambda (loc _num ref)
- (concat
- loc
- (when ref
- ;; Ensure references are flushed to the right,
- ;; separated with 6 spaces from the widest line
- ;; of code.
- (concat (make-string (+ (- max-width (length loc)) 6)
- ?\s)
- (format "(%s)" ref)))))
- nil (and retain-labels (cdr code-info)))))))
- ;; Return value.
- (format float-env body)))
- ;; Case 4. Use listings package.
+ (org-latex-src-block--minted src-block info lang caption caption-above-p label
+ num-start retain-labels attributes float))
(t
- (let ((lst-lang
- (or (cadr (assq (intern lang)
- (plist-get info :latex-listings-langs)))
- lang))
- (caption-str
- (when caption
- (let ((main (org-export-get-caption src-block))
- (secondary (org-export-get-caption src-block t)))
- (if (not secondary)
- (format "{%s}" (org-export-data main info))
- (format "{[%s]%s}"
- (org-export-data secondary info)
- (org-export-data main info))))))
- (lst-opt (plist-get info :latex-listings-options)))
- (concat
- ;; Options.
- (format
- "\\lstset{%s}\n"
- (concat
- (org-latex--make-option-string
- (append
- lst-opt
- (cond
- ((and (not float) (plist-member attributes :float)) nil)
- ((string= "multicolumn" float) '(("float" "*")))
- ((and float (not (assoc "float" lst-opt)))
- `(("float" ,(plist-get info :latex-default-figure-position)))))
- `(("language" ,lst-lang))
- (if label
- `(("label" ,(org-latex--label src-block info)))
- '(("label" " ")))
- (if caption-str `(("caption" ,caption-str)) '(("caption" " ")))
- `(("captionpos" ,(if caption-above-p "t" "b")))
- (cond ((assoc "numbers" lst-opt) nil)
- ((not num-start) '(("numbers" "none")))
- (t `(("firstnumber" ,(number-to-string (1+ num-start)))
- ("numbers" "left"))))))
- (let ((local-options (plist-get attributes :options)))
- (and local-options (concat "," local-options)))))
- ;; Source code.
- (format
- "\\begin{lstlisting}\n%s\\end{lstlisting}"
- (let* ((code-info (org-export-unravel-code src-block))
- (max-width
- (apply 'max
- (mapcar 'length
- (org-split-string (car code-info) "\n")))))
- (org-export-format-code
- (car code-info)
- (lambda (loc _num ref)
- (concat
- loc
- (when ref
- ;; Ensure references are flushed to the right,
- ;; separated with 6 spaces from the widest line of
- ;; code
- (concat (make-string (+ (- max-width (length loc)) 6) ?\s)
- (format "(%s)" ref)))))
- nil (and retain-labels (cdr code-info))))))))))))
-
+ (org-latex-src-block--listings src-block info lang caption caption-above-p label
+ num-start retain-labels attributes float))))))
+
+(defun org-latex-src-block--verbatim
+ (src-block info _lang caption caption-above-p _label
+ _num-start _retain-labels _attributes float)
+ "Transcode a SRC-BLOCK element from Org to LaTeX, using verbatim.
+LANG, CAPTION, CAPTION-ABOVE-P, LABEL, NUM-START, RETAIN-LABELS, ATTRIBUTES
+and FLOAT are extracted from SRC-BLOCK and INFO in `org-latex-src-block'."
+ (let ((caption-str (org-latex--caption/label-string src-block info))
+ (verbatim (format "\\begin{verbatim}\n%s\\end{verbatim}"
+ (org-export-format-code-default src-block info))))
+ (cond ((string= "multicolumn" float)
+ (format "\\begin{figure*}[%s]\n%s%s\n%s\\end{figure*}"
+ (plist-get info :latex-default-figure-position)
+ (if caption-above-p caption-str "")
+ verbatim
+ (if caption-above-p "" caption-str)))
+ (caption (concat
+ (if caption-above-p caption-str "")
+ verbatim
+ (if caption-above-p "" (concat "\n" caption-str))))
+ (t verbatim))))
+
+(defun org-latex-src-block--custom
+ (src-block info _lang caption caption-above-p _label
+ _num-start _retain-labels attributes float custom-env)
+ "Transcode a SRC-BLOCK element from Org to LaTeX, using a custom environment.
+LANG, CAPTION, CAPTION-ABOVE-P, LABEL, NUM-START, RETAIN-LABELS, ATTRIBUTES
+and FLOAT are extracted from SRC-BLOCK and INFO in `org-latex-src-block'."
+ (let ((caption-str (org-latex--caption/label-string src-block info))
+ (formatted-src (org-export-format-code-default src-block info)))
+ (if (string-match-p "\\`[a-zA-Z0-9]+\\'" custom-env)
+ (format "\\begin{%s}\n%s\\end{%s}\n"
+ custom-env
+ (concat (and caption-above-p caption-str)
+ formatted-src
+ (and (not caption-above-p) caption-str))
+ custom-env)
+ (format-spec custom-env
+ `((?s . ,formatted-src)
+ (?c . ,caption)
+ (?f . ,float)
+ (?l . ,(org-latex--label src-block info))
+ (?o . ,(or (plist-get attributes :options) "")))))))
+
+(defun org-latex-src-block--minted
+ (src-block info lang caption caption-above-p _label
+ num-start retain-labels attributes float)
+ "Transcode a SRC-BLOCK element from Org to LaTeX, using minted.
+LANG, CAPTION, CAPTION-ABOVE-P, LABEL, NUM-START, RETAIN-LABELS, ATTRIBUTES
+and FLOAT are extracted from SRC-BLOCK and INFO in `org-latex-src-block'."
+ (let* ((caption-str (org-latex--caption/label-string src-block info))
+ (placement (or (org-unbracket-string "[" "]" (plist-get attributes :placement))
+ (plist-get info :latex-default-figure-position)))
+ (float-env
+ (cond
+ ((string= "multicolumn" float)
+ (format "\\begin{listing*}[%s]\n%s%%s\n%s\\end{listing*}"
+ placement
+ (if caption-above-p caption-str "")
+ (if caption-above-p "" caption-str)))
+ (caption
+ (format "\\begin{listing}[%s]\n%s%%s\n%s\\end{listing}"
+ placement
+ (if caption-above-p caption-str "")
+ (if caption-above-p "" caption-str)))
+ ((string= "t" float)
+ (concat (format "\\begin{listing}[%s]\n"
+ placement)
+ "%s\n\\end{listing}"))
+ (t "%s")))
+ (options (plist-get info :latex-minted-options))
+ (body
+ (format
+ "\\begin{minted}[%s]{%s}\n%s\\end{minted}"
+ ;; Options.
+ (concat
+ (org-latex--make-option-string
+ (if (or (not num-start) (assoc "linenos" options))
+ options
+ (append
+ `(("linenos")
+ ("firstnumber" ,(number-to-string (1+ num-start))))
+ options)))
+ (let ((local-options (plist-get attributes :options)))
+ (and local-options (concat "," local-options))))
+ ;; Language.
+ (or (cadr (assq (intern lang)
+ (plist-get info :latex-minted-langs)))
+ (downcase lang))
+ ;; Source code.
+ (let* ((code-info (org-export-unravel-code src-block))
+ (max-width
+ (apply 'max
+ (mapcar 'length
+ (org-split-string (car code-info)
+ "\n")))))
+ (org-export-format-code
+ (car code-info)
+ (lambda (loc _num ref)
+ (concat
+ loc
+ (when ref
+ ;; Ensure references are flushed to the right,
+ ;; separated with 6 spaces from the widest line
+ ;; of code.
+ (concat (make-string (+ (- max-width (length loc)) 6)
+ ?\s)
+ (format "(%s)" ref)))))
+ nil (and retain-labels (cdr code-info)))))))
+ ;; Return value.
+ (format float-env body)))
+
+(defun org-latex-src-block--listings
+ (src-block info lang caption caption-above-p label
+ num-start retain-labels attributes float)
+ "Transcode a SRC-BLOCK element from Org to LaTeX, using listings.
+LANG, CAPTION, CAPTION-ABOVE-P, LABEL, NUM-START, RETAIN-LABELS, ATTRIBUTES
+and FLOAT are extracted from SRC-BLOCK and INFO in `org-latex-src-block'."
+ (let ((lst-lang
+ (or (cadr (assq (intern lang)
+ (plist-get info :latex-listings-langs)))
+ lang))
+ (caption-str
+ (when caption
+ (let ((main (org-export-get-caption src-block))
+ (secondary (org-export-get-caption src-block t)))
+ (if (not secondary)
+ (format "{%s}" (org-export-data main info))
+ (format "{[%s]%s}"
+ (org-export-data secondary info)
+ (org-export-data main info))))))
+ (lst-opt (plist-get info :latex-listings-options)))
+ (concat
+ ;; Options.
+ (format
+ "\\lstset{%s}\n"
+ (concat
+ (org-latex--make-option-string
+ (append
+ lst-opt
+ (cond
+ ((and (not float) (plist-member attributes :float)) nil)
+ ((string= "multicolumn" float) '(("float" "*")))
+ ((and float (not (assoc "float" lst-opt)))
+ `(("float" ,(plist-get info :latex-default-figure-position)))))
+ `(("language" ,lst-lang))
+ (if label
+ `(("label" ,(org-latex--label src-block info)))
+ '(("label" " ")))
+ (if caption-str `(("caption" ,caption-str)) '(("caption" " ")))
+ `(("captionpos" ,(if caption-above-p "t" "b")))
+ (cond ((assoc "numbers" lst-opt) nil)
+ ((not num-start) '(("numbers" "none")))
+ (t `(("firstnumber" ,(number-to-string (1+ num-start)))
+ ("numbers" "left"))))))
+ (let ((local-options (plist-get attributes :options)))
+ (and local-options (concat "," local-options)))))
+ ;; Source code.
+ (format
+ "\\begin{lstlisting}\n%s\\end{lstlisting}"
+ (let* ((code-info (org-export-unravel-code src-block))
+ (max-width
+ (apply 'max
+ (mapcar 'length
+ (org-split-string (car code-info) "\n")))))
+ (org-export-format-code
+ (car code-info)
+ (lambda (loc _num ref)
+ (concat
+ loc
+ (when ref
+ ;; Ensure references are flushed to the right,
+ ;; separated with 6 spaces from the widest line of
+ ;; code
+ (concat (make-string (+ (- max-width (length loc)) 6) ?\s)
+ (format "(%s)" ref)))))
+ nil (and retain-labels (cdr code-info))))))))
;;;; Statistics Cookie
--
2.35.3
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #3: 0002-ox-latex-Refactor-org-latex-inline-src-block.patch --]
[-- Type: text/x-patch, Size: 4016 bytes --]
From aa8406ce64507b870322495e8f9b54317930ed24 Mon Sep 17 00:00:00 2001
From: TEC <tec@tecosaur.com>
Date: Wed, 4 May 2022 18:53:10 +0800
Subject: [PATCH 2/7] ox-latex: Refactor `org-latex-inline-src-block'
* lisp/ox-latex.el (org-latex-inline-src-block,
org-latex-inline-src-block--minted,
org-latex-inline-src-block--listings): Extract the minted and listings
specific logic out of `org-latex-inline-src-block` into the new
functions `org-latex-inline-src-block--minted` and
`org-latex-inline-src-block--listings`.
---
lisp/ox-latex.el | 62 +++++++++++++++++++++++++-----------------------
1 file changed, 32 insertions(+), 30 deletions(-)
diff --git a/lisp/ox-latex.el b/lisp/ox-latex.el
index c2f728a1c..38f36a1f3 100644
--- a/lisp/ox-latex.el
+++ b/lisp/ox-latex.el
@@ -2127,36 +2127,38 @@ (defun org-latex-inline-src-block (inline-src-block _contents info)
"Transcode an INLINE-SRC-BLOCK element from Org to LaTeX.
CONTENTS holds the contents of the item. INFO is a plist holding
contextual information."
- (let* ((code (org-element-property :value inline-src-block))
- (separator (org-latex--find-verb-separator code)))
- (cl-case (plist-get info :latex-listings)
- ;; Do not use a special package: transcode it verbatim, as code.
- ((nil) (org-latex--text-markup code 'code info))
- ;; Use minted package.
- (minted
- (let* ((org-lang (org-element-property :language inline-src-block))
- (mint-lang (or (cadr (assq (intern org-lang)
- (plist-get info :latex-minted-langs)))
- (downcase org-lang)))
- (options (org-latex--make-option-string
- (plist-get info :latex-minted-options))))
- (format "\\mintinline%s{%s}{%s}"
- (if (string= options "") "" (format "[%s]" options))
- mint-lang
- code)))
- ;; Use listings package.
- (otherwise
- ;; Maybe translate language's name.
- (let* ((org-lang (org-element-property :language inline-src-block))
- (lst-lang (or (cadr (assq (intern org-lang)
- (plist-get info :latex-listings-langs)))
- org-lang))
- (options (org-latex--make-option-string
- (append (plist-get info :latex-listings-options)
- `(("language" ,lst-lang))))))
- (concat (format "\\lstinline[%s]" options)
- separator code separator))))))
-
+ (let ((code (org-element-property :value inline-src-block))
+ (lang (org-element-property :language inline-src-block)))
+ (pcase (plist-get info :latex-listings)
+ ('nil (org-latex--text-markup code 'code info))
+ ('minted (org-latex-inline-src-block--minted info code lang))
+ (_ (org-latex-inline-src-block--listings info code lang)))))
+
+(defun org-latex-inline-src-block--minted (info code lang)
+ "Transcode an inline src block's content from Org to LaTeX, using minted.
+INFO, CODE, and LANG are provided by `org-latex-inline-src-block'."
+ (let ((mint-lang (or (cadr (assq (intern lang)
+ (plist-get info :latex-minted-langs)))
+ (downcase lang)))
+ (options (org-latex--make-option-string
+ (plist-get info :latex-minted-options))))
+ (format "\\mintinline%s{%s}{%s}"
+ (if (string= options "") "" (format "[%s]" options))
+ mint-lang
+ code)))
+
+(defun org-latex-inline-src-block--listings (info code lang)
+ "Transcode an inline src block's content from Org to LaTeX, using lstlistings.
+INFO, CODE, and LANG are provided by `org-latex-inline-src-block'."
+ (let* ((lst-lang (or (cadr (assq (intern lang)
+ (plist-get info :latex-listings-langs)))
+ lang))
+ (separator (org-latex--find-verb-separator code))
+ (options (org-latex--make-option-string
+ (append (plist-get info :latex-listings-options)
+ `(("language" ,lst-lang))))))
+ (concat (format "\\lstinline[%s]" options)
+ separator code separator)))
;;;; Inlinetask
--
2.35.3
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #4: 0003-ox-latex-More-versitile-option-construction.patch --]
[-- Type: text/x-patch, Size: 4116 bytes --]
From 62d6703f0dd622916dff8aab960db6df4cb58cf7 Mon Sep 17 00:00:00 2001
From: TEC <tec@tecosaur.com>
Date: Wed, 4 May 2022 23:31:59 +0800
Subject: [PATCH 3/7] ox-latex: More versitile option construction
* lisp/ox-latex.el (org-latex--make-option-string): Support a custom
option seperator string.
(org-latex--make-option-string, org-latex-minted-options,
org-latex-listings-options): The first line of the docstrings for
`org-latex-minted-options` and `org-latex-listings-options` describe the
variables as "association lists", yet `org-latex--make-option-string`
does not handle association lists and an example of two-value lists is
provided. To make the behaviour match the docstring,
`org-latex--make-option-string` is modified to work with either a list
two-value lists or an association list, and the examples in
`org-latex-minted-options` and `org-latex-listings-options` updated
accordingly.
---
lisp/ox-latex.el | 38 ++++++++++++++++++++++++--------------
1 file changed, 24 insertions(+), 14 deletions(-)
diff --git a/lisp/ox-latex.el b/lisp/ox-latex.el
index 38f36a1f3..2d4b3bace 100644
--- a/lisp/ox-latex.el
+++ b/lisp/ox-latex.el
@@ -1006,12 +1006,16 @@ (defcustom org-latex-listings-options nil
These options are supplied as a comma-separated list to the
\\lstset command. Each element of the association list should be
-a list containing two strings: the name of the option, and the
-value. For example,
+a list or cons cell containing two strings: the name of the
+option, and the value. For example,
(setq org-latex-listings-options
\\='((\"basicstyle\" \"\\\\small\")
(\"keywordstyle\" \"\\\\color{black}\\\\bfseries\\\\underbar\")))
+ ; or
+ (setq org-latex-listings-options
+ \\='((\"basicstyle\" . \"\\\\small\")
+ (\"keywordstyle\" . \"\\\\color{black}\\\\bfseries\\\\underbar\")))
will typeset the code in a small size font with underlined, bold
black keywords.
@@ -1059,11 +1063,14 @@ (defcustom org-latex-minted-options nil
These options are supplied within square brackets in
\\begin{minted} environments. Each element of the alist should
-be a list containing two strings: the name of the option, and the
-value. For example,
+be a list or cons cell containing two strings: the name of the
+option, and the value. For example,
(setq org-latex-minted-options
\\='((\"bgcolor\" \"bg\") (\"frame\" \"lines\")))
+ ; or
+ (setq org-latex-minted-options
+ \\='((\"bgcolor\" . \"bg\") (\"frame\" . \"lines\")))
will result in source blocks being exported with
@@ -1506,21 +1513,24 @@ (defun org-latex--find-verb-separator (s)
when (not (string-match (regexp-quote (char-to-string c)) s))
return (char-to-string c))))
-(defun org-latex--make-option-string (options)
+(defun org-latex--make-option-string (options &optional seperator)
"Return a comma separated string of keywords and values.
OPTIONS is an alist where the key is the options keyword as
a string, and the value a list containing the keyword value, or
nil."
(mapconcat (lambda (pair)
- (pcase-let ((`(,keyword ,value) pair))
- (concat keyword
- (and (> (length value) 0)
- (concat "="
- (if (string-match-p (rx (any "[]")) value)
- (format "{%s}" value)
- value))))))
- options
- ","))
+ (let ((keyword (car pair))
+ (value (pcase (cdr pair)
+ ((pred stringp) (cdr pair))
+ ((pred consp) (cadr pair)))))
+ (concat keyword
+ (when value
+ (concat "="
+ (if (string-match-p (rx (any "[]")) value)
+ (format "{%s}" value)
+ value))))))
+ options
+ (or seperator ",")))
(defun org-latex--wrap-label (element output info)
"Wrap label associated to ELEMENT around OUTPUT, if appropriate.
--
2.35.3
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #5: 0004-ox-latex-Introduce-engraved-code-highlighting.patch --]
[-- Type: text/x-patch, Size: 17212 bytes --]
From 81155a80fb261812718dcb991fd22f87bb1d5ef6 Mon Sep 17 00:00:00 2001
From: TEC <tec@tecosaur.com>
Date: Sun, 21 Nov 2021 20:04:12 +0800
Subject: [PATCH 4/7] ox-latex: Introduce "engraved" code highlighting
* lisp/ox-latex.el (org-latex-src-block, org-latex-src-block--engraved,
org-latex-inline-src-block, org-latex-inline-src-block--engraved,
org-latex-src--engrave-code, org-latex-template, org-latex-listings):
Make use of the engraved-faces package (available on ELPA) to provide an
alternative LaTeX code highlighting backend which functions similarly to
htmlize.el for HTML exports.
(org-latex-engraved-preamble, org-latex-engraved-options): Introduce
variables to construct the preamble for engraved code blocks.
* lisp/ox-beamer.el (org-beamer-template): Modify to add engrave-faces
preamble when applicable.
tweak
---
lisp/ox-beamer.el | 11 ++
lisp/ox-latex.el | 272 ++++++++++++++++++++++++++++++++++++++++++++--
2 files changed, 274 insertions(+), 9 deletions(-)
diff --git a/lisp/ox-beamer.el b/lisp/ox-beamer.el
index 6be73c91e..4d40f6a1d 100644
--- a/lisp/ox-beamer.el
+++ b/lisp/ox-beamer.el
@@ -857,6 +857,17 @@ (defun org-beamer-template (contents info)
(let ((template (plist-get info :latex-hyperref-template)))
(and (stringp template)
(format-spec template (org-latex--format-spec info))))
+ ;; engrave-faces-latex preamble
+ (when (eq org-latex-listings 'engraved)
+ (let ((src-p (org-element-map (plist-get info :parse-tree)
+ '(src-block inline-src-block) #'identity
+ info t))
+ (fixedw-p
+ (org-element-map (plist-get info :parse-tree)
+ '(example-block fixed-width) #'identity
+ info t)))
+ (when (or src-p fixedw-p)
+ (org-latex-generate-engraved-preamble info src-p))))
;; Document start.
"\\begin{document}\n\n"
;; Title command.
diff --git a/lisp/ox-latex.el b/lisp/ox-latex.el
index 2d4b3bace..10cd6d76d 100644
--- a/lisp/ox-latex.el
+++ b/lisp/ox-latex.el
@@ -37,6 +37,8 @@ (defvar org-latex-default-packages-alist)
(defvar org-latex-packages-alist)
(defvar orgtbl-exp-regexp)
+(declare-function engrave-faces-latex-gen-preamble "ext:engrave-faces-latex")
+(declare-function engrave-faces-latex-buffer "ext:engrave-faces-latex")
\f
;;; Define Back-End
@@ -125,6 +127,8 @@ (org-export-define-backend 'latex
(:latex-default-quote-environment nil nil org-latex-default-quote-environment)
(:latex-default-table-mode nil nil org-latex-default-table-mode)
(:latex-diary-timestamp-format nil nil org-latex-diary-timestamp-format)
+ (:latex-engraved-options nil nil org-latex-engraved-options)
+ (:latex-engraved-preamble nil nil org-latex-engraved-preamble)
(:latex-footnote-defined-format nil nil org-latex-footnote-defined-format)
(:latex-footnote-separator nil nil org-latex-footnote-separator)
(:latex-format-drawer-function nil nil org-latex-format-drawer-function)
@@ -937,22 +941,48 @@ (defcustom org-latex-listings nil
"Non-nil means export source code using the listings package.
This package will fontify source code, possibly even with color.
-If you want to use this, you also need to make LaTeX use the
-listings package, and if you want to have color, the color
-package. Just add these to `org-latex-packages-alist', for
-example using customize, or with something like:
+There are four implementations of this functionality you may
+choose from (ordered from least to most capable):
+1. Verbatim (nil)
+2. Listings (t)
+3. Minted (minted)
+4. Engraved (engraved)
+
+The first two options provide basic syntax
+highlighting (listings), or none at all (verbatim).
+
+When using listings, you also need to make use of the LaTeX
+\"listings\" package. The \"color\" package is also needed if you
+would like color too. These can simply be added to
+`org-latex-packages-alist', using customise or something like:
(require \\='ox-latex)
(add-to-list \\='org-latex-packages-alist \\='(\"\" \"listings\"))
(add-to-list \\='org-latex-packages-alist \\='(\"\" \"color\"))
-Alternatively,
+There are two further options for more comprehensive
+fontification. The first can be set with,
+
+ (setq org-latex-listings \\='engraved)
+
+which causes source code to be run through
+`engrave-faces-latex-buffer', which generates colorings using
+Emacs' font-lock information. This requires the engrave-faces
+package (availible from ELPA), and the fvextra LaTeX package be
+installed.
+
+The styling of the engraved result can customised with
+`org-latex-engraved-preamble' and `org-latex-engraved-options'.
+The default preamble also uses the tcolorbox LaTeX package in
+addition to fvextra.
+
+The second more comprehensive option can be set with,
(setq org-latex-listings \\='minted)
-causes source code to be exported using the minted package as
-opposed to listings. If you want to use minted, you need to add
-the minted package to `org-latex-packages-alist', for example
+which causes source code to be exported using the minted package
+as opposed to listings. If you want to use minted, you need to
+add the minted package to `org-latex-packages-alist', for example
using customize, or with
(require \\='ox-latex)
@@ -971,8 +1001,9 @@ (defcustom org-latex-listings nil
:type '(choice
(const :tag "Use listings" t)
(const :tag "Use minted" minted)
+ (const :tag "Use engrave-faces-latex" engraved)
(const :tag "Export verbatim" nil))
- :safe (lambda (s) (memq s '(t nil minted))))
+ :safe (lambda (s) (memq s '(t nil minted engraved))))
(defcustom org-latex-listings-langs
'((emacs-lisp "Lisp") (lisp "Lisp") (clojure "Lisp")
@@ -1142,6 +1173,127 @@ (defcustom org-latex-custom-lang-environments nil
:version "26.1"
:package-version '(Org . "9.0"))
+(defcustom org-latex-engraved-preamble
+ "\\usepackage{fvextra}
+
+[FVEXTRA-SETUP]
+
+% Make line numbers smaller and grey.
+\\renewcommand\\theFancyVerbLine{\\footnotesize\\color{black!40!white}\\arabic{FancyVerbLine}}
+
+\\usepackage{xcolor}
+
+\\providecolor{codebackground}{HTML}{f7f7f7}
+\\providecolor{codeborder}{HTML}{f0f0f0}
+\\providecolor{EFD}{HTML}{28292e}
+
+% Define a Code environment to prettily wrap the fontified code.
+\\usepackage[breakable,xparse]{tcolorbox}
+\\DeclareTColorBox[]{Code}{o}%
+{colback=codebackground, colframe=codeborder,
+ fontupper=\\footnotesize\\setlength{\\fboxsep}{0pt},
+ colupper=EFD,
+ IfNoValueTF={#1}%
+ {boxsep=2pt, arc=2.5pt, outer arc=2.5pt,
+ boxrule=0.5pt, left=2pt}%
+ {boxsep=2.5pt, arc=0pt, outer arc=0pt,
+ boxrule=0pt, leftrule=1.5pt, left=0.5pt},
+ right=2pt, top=1pt, bottom=0.5pt,
+ breakable}"
+ "Preamble content injected when using engrave-faces-latex for source blocks.
+This is relevant when `org-latex-listings' is set to `engraved'.
+
+There is quite a lot of flexibility in what this preamble can be, as long as it:
+- Loads the fvextra package.
+- Loads the package xcolor (if it is not already loader elsewhere).
+- Defines a \"Code\" environment (note the capital C), which all
+ \"Verbatim\" environments (provided by fvextra) will be wrapped with.
+
+A macro-like placeholder is used to set fvextra's defaults according to
+`org-latex-engraved-options':
+
+ [FVEXTRA-SETUP]
+
+In the default value the color \"EFD\" is provided as this is the
+foreground colour provided by engrave-faces-latex. When there
+are example/fixed-width blocks only, the engraved generated
+preamble is not included, and so it is provided so we may use it
+anyway."
+ :group 'org-export-latex
+ :type 'string
+ :package-version '(Org . "9.6"))
+
+(defcustom org-latex-engraved-options
+ '(("commandchars" . "\\\\\\{\\}")
+ ("highlightcolor" . "white!95!black!80!blue")
+ ("breaklines" . "true")
+ ("breaksymbol" . "\\color{white!60!black}\\tiny\\ensuremath{\\hookrightarrow}"))
+ "Association list of options for the latex fvextra package when engraving code.
+
+These options are set using \\fvset{...} in the preamble of the
+LaTeX export. Each element of the alist should be a list or cons
+cell containing two strings: the name of the option, and the
+value. For example,
+
+ (setq org-latex-engraved-options
+ \\='((\"highlightcolor\" \"green\") (\"frame\" \"lines\")))
+ ; or
+ (setq org-latex-engraved-options
+ \\='((\"highlightcolor\" . \"green\") (\"frame\" . \"lines\")))
+
+will result in the following LaTeX in the preamble
+
+\\fvset{%
+ bgcolor=bg,
+ frame=lines}
+
+This will affect all fvextra environments. Note that the same
+options will be applied to all blocks. If you need
+block-specific options, you may use the following syntax:
+
+ #+ATTR_LATEX: :options key1=value1,key2=value2
+ #+BEGIN_SRC <LANG>
+ ...
+ #+END_SRC"
+ :group 'org-export-latex
+ :type '(alist :key-type (string :tag "option")
+ :value-type (string :tag "value")))
+
+(defun org-latex-generate-engraved-preamble (info syntax-colours-p)
+ "Generate the preamble to setup engraved code.
+The result is constructed from the :latex-engraved-preamble and
+:latex-engraved-optionsn export options, the default values of
+which are given by `org-latex-engraved-preamble' and
+`org-latex-engraved-options' respectively."
+ (let* ((engraved-options
+ (plist-get info :latex-engraved-options))
+ (engraved-preamble-template
+ (plist-get info :latex-engraved-preamble))
+ (engraved-preamble
+ (if (string-match "^[ \t]*\\[FVEXTRA-SETUP\\][ \t]*\n?"
+ engraved-preamble-template)
+ (replace-match
+ (concat
+ "\\fvset{%\n "
+ (org-latex--make-option-string engraved-options ",\n ")
+ "}\n")
+ t t
+ engraved-preamble-template)
+ engraved-preamble-template)))
+ (if syntax-colours-p
+ (concat
+ "\n% Setup for code blocks [1/2]\n\n"
+ engraved-preamble
+ "\n\n% Setup for code blocks [2/2]: syntax highlighting colors\n"
+ (if (require 'engrave-faces-latex nil t)
+ (engrave-faces-latex-gen-preamble)
+ (message "Cannot engrave source blocks. Consider installing `engrave-faces'.")
+ "% WARNING syntax highlighting unavailible as engrave-faces-latex was missing.\n")
+ "\n")
+ (concat
+ "\n% Setup for code blocks\n\n"
+ engraved-preamble
+ "\n"))))
;;;; Compilation
@@ -1756,6 +1908,17 @@ (defun org-latex-template (contents info)
(let ((template (plist-get info :latex-hyperref-template)))
(and (stringp template)
(format-spec template spec)))
+ ;; engrave-faces-latex preamble
+ (when (eq org-latex-listings 'engraved)
+ (let ((src-p (org-element-map (plist-get info :parse-tree)
+ '(src-block inline-src-block) #'identity
+ info t))
+ (fixedw-p
+ (org-element-map (plist-get info :parse-tree)
+ '(example-block fixed-width) #'identity
+ info t)))
+ (when (or src-p fixedw-p)
+ (org-latex-generate-engraved-preamble info src-p))))
;; Document start.
"\\begin{document}\n\n"
;; Title command.
@@ -2142,6 +2305,7 @@ (defun org-latex-inline-src-block (inline-src-block _contents info)
(pcase (plist-get info :latex-listings)
('nil (org-latex--text-markup code 'code info))
('minted (org-latex-inline-src-block--minted info code lang))
+ ('engraved (org-latex-inline-src-block--engraved info code lang))
(_ (org-latex-inline-src-block--listings info code lang)))))
(defun org-latex-inline-src-block--minted (info code lang)
@@ -2157,6 +2321,11 @@ (defun org-latex-inline-src-block--minted (info code lang)
mint-lang
code)))
+(defun org-latex-inline-src-block--engraved (_info code lang)
+ "Transcode an inline src block's content from Org to LaTeX, using engrave-faces.
+INFO, CODE, and LANG are provided by `org-latex-inline-src-block'."
+ (format "\\Verb{%s}" (org-latex-src--engrave-code code lang)))
+
(defun org-latex-inline-src-block--listings (info code lang)
"Transcode an inline src block's content from Org to LaTeX, using lstlistings.
INFO, CODE, and LANG are provided by `org-latex-inline-src-block'."
@@ -3017,6 +3186,9 @@ (defun org-latex-src-block (src-block _contents info)
num-start retain-labels attributes float custom-env))
((eq listings 'minted)
(org-latex-src-block--minted src-block info lang caption caption-above-p label
+ num-start retain-labels attributes float))
+ ((eq listings 'engraved)
+ (org-latex-src-block--engraved src-block info lang caption caption-above-p label
num-start retain-labels attributes float))
(t
(org-latex-src-block--listings src-block info lang caption caption-above-p label
@@ -3133,6 +3305,88 @@ (defun org-latex-src-block--minted
;; Return value.
(format float-env body)))
+(defun org-latex-src--engrave-code (content lang)
+ "Engrave CONTENT to LaTeX in a LANG-mode buffer, and give the result."
+ (if (require 'engrave-faces-latex nil t)
+ (let* ((lang-mode (and lang (org-src-get-lang-mode lang)))
+ (engraved-buffer
+ (with-temp-buffer
+ (insert content)
+ (when lang-mode
+ (if (functionp lang-mode)
+ (funcall lang-mode)
+ (message "Cannot engrave code as %s. %s is undefined."
+ lang lang-mode)))
+ (engrave-faces-latex-buffer)))
+ (engraved-code
+ (with-current-buffer engraved-buffer
+ (buffer-string))))
+ (kill-buffer engraved-buffer)
+ engraved-code)
+ (user-error "Cannot engrave code as `engrave-faces-latex' is unavailible.")))
+
+(defun org-latex-src-block--engraved
+ (src-block info lang caption caption-above-p _label
+ num-start retain-labels attributes float)
+ "Transcode a SRC-BLOCK element from Org to LaTeX, using engrave-faces-latex.
+LANG, CAPTION, CAPTION-ABOVE-P, LABEL, NUM-START, RETAIN-LABELS, ATTRIBUTES
+and FLOAT are extracted from SRC-BLOCK and INFO in `org-latex-src-block'."
+ (let* ((caption-str (org-latex--caption/label-string src-block info))
+ (placement (or (org-unbracket-string "[" "]" (plist-get attributes :placement))
+ (plist-get info :latex-default-figure-position)))
+ (float-env
+ (cond
+ ((string= "multicolumn" float)
+ (format "\\begin{listing*}[%s]\n%s%%s\n%s\\end{listing*}"
+ placement
+ (if caption-above-p caption-str "")
+ (if caption-above-p "" caption-str)))
+ (caption
+ (format "\\begin{listing}[%s]\n%s%%s\n%s\\end{listing}"
+ placement
+ (if caption-above-p caption-str "")
+ (if caption-above-p "" caption-str)))
+ ((string= "t" float)
+ (concat (format "\\begin{listing}[%s]\n"
+ placement)
+ "%s\n\\end{listing}"))
+ (t "%s")))
+ (options (plist-get info :latex-engraved-options))
+ (content
+ (let* ((code-info (org-export-unravel-code src-block))
+ (max-width
+ (apply 'max
+ (mapcar 'string-width
+ (org-split-string (car code-info)
+ "\n")))))
+ (org-export-format-code
+ (car code-info)
+ (lambda (loc _num ref)
+ (concat
+ loc
+ (when ref
+ ;; Ensure references are flushed to the right,
+ ;; separated with 6 spaces from the widest line
+ ;; of code.
+ (concat (make-string (+ (- max-width (length loc)) 6)
+ ?\s)
+ (format "(%s)" ref)))))
+ nil (and retain-labels (cdr code-info)))))
+ (body
+ (format
+ "\\begin{Code}\n\\begin{Verbatim}[%s]\n%s\\end{Verbatim}\n\\end{Code}"
+ ;; Options.
+ (concat
+ (org-latex--make-option-string
+ (append
+ (when (and num-start (not (assoc "linenos" options)))
+ `(("linenos")
+ ("firstnumber" ,(number-to-string (1+ num-start)))))
+ (let ((local-options (plist-get attributes :options)))
+ (and local-options (list local-options))))))
+ (org-latex-src--engrave-code content lang))))
+ (format float-env body)))
+
(defun org-latex-src-block--listings
(src-block info lang caption caption-above-p label
num-start retain-labels attributes float)
--
2.35.3
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #6: 0005-ox-latex-Don-t-use-length-to-get-string-width.patch --]
[-- Type: text/x-patch, Size: 1537 bytes --]
From 96cf9853329dacd69745a225a889855dd13e5c2c Mon Sep 17 00:00:00 2001
From: TEC <tec@tecosaur.com>
Date: Sat, 7 May 2022 13:59:13 +0800
Subject: [PATCH 5/7] ox-latex: Don't use `length' to get string width
* lisp/ox-latex.el (org-latex-src-block--listings,
org-latex-src-block--engraved, org-latex-src-block--minted): Use
`string-width' instead of `length' to gauge the displayed width of the
string in LaTeX. This may not be a perfect match, but it should be an
improvement.
---
lisp/ox-latex.el | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/lisp/ox-latex.el b/lisp/ox-latex.el
index 10cd6d76d..afd7ee48e 100644
--- a/lisp/ox-latex.el
+++ b/lisp/ox-latex.el
@@ -3286,7 +3286,7 @@ (defun org-latex-src-block--minted
(let* ((code-info (org-export-unravel-code src-block))
(max-width
(apply 'max
- (mapcar 'length
+ (mapcar 'string-width
(org-split-string (car code-info)
"\n")))))
(org-export-format-code
@@ -3438,7 +3438,7 @@ (defun org-latex-src-block--listings
(let* ((code-info (org-export-unravel-code src-block))
(max-width
(apply 'max
- (mapcar 'length
+ (mapcar 'string-width
(org-split-string (car code-info) "\n")))))
(org-export-format-code
(car code-info)
--
2.35.3
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #7: 0006-ox-latex-Refactor-source-block-transcode-fun-sigs.patch --]
[-- Type: text/x-patch, Size: 7297 bytes --]
From f191a03ef97f5f8e29b18b73238ab659709ae230 Mon Sep 17 00:00:00 2001
From: TEC <tec@tecosaur.com>
Date: Sat, 7 May 2022 14:02:44 +0800
Subject: [PATCH 6/7] ox-latex: Refactor source block transcode fun sigs
* lisp/ox-latex.el (org-latex-src-block--listings,
org-latex-src-block--engraved, org-latex-src-block--minted,
org-latex-src-block--custom): Refactor these --backend functions to use
cl-defun with keys instead of having an 11-argument signature.
(org-latex-src-block): Adjust for the change in signature of the
--backend functions, and refactor the `cond' statement to use `pcase'.
---
lisp/ox-latex.el | 82 +++++++++++++++++++++++-------------------------
1 file changed, 39 insertions(+), 43 deletions(-)
diff --git a/lisp/ox-latex.el b/lisp/ox-latex.el
index afd7ee48e..9150c1011 100644
--- a/lisp/ox-latex.el
+++ b/lisp/ox-latex.el
@@ -3166,37 +3166,37 @@ (defun org-latex-src-block (src-block _contents info)
contextual information."
(when (org-string-nw-p (org-element-property :value src-block))
(let* ((lang (org-element-property :language src-block))
- (caption (org-element-property :caption src-block))
- (caption-above-p (org-latex--caption-above-p src-block info))
- (label (org-element-property :name src-block))
- (custom-env (and lang
- (cadr (assq (intern lang)
- org-latex-custom-lang-environments))))
- (num-start (org-export-get-loc src-block info))
- (retain-labels (org-element-property :retain-labels src-block))
- (attributes (org-export-read-attribute :attr_latex src-block))
- (float (plist-get attributes :float))
- (listings (plist-get info :latex-listings)))
- (cond
- ((or (not lang) (not listings))
- (org-latex-src-block--verbatim src-block info lang caption caption-above-p label
- num-start retain-labels attributes float))
- (custom-env
- (org-latex-src-block--custom src-block info lang caption caption-above-p label
- num-start retain-labels attributes float custom-env))
- ((eq listings 'minted)
- (org-latex-src-block--minted src-block info lang caption caption-above-p label
- num-start retain-labels attributes float))
- ((eq listings 'engraved)
- (org-latex-src-block--engraved src-block info lang caption caption-above-p label
- num-start retain-labels attributes float))
- (t
- (org-latex-src-block--listings src-block info lang caption caption-above-p label
- num-start retain-labels attributes float))))))
-
-(defun org-latex-src-block--verbatim
- (src-block info _lang caption caption-above-p _label
- _num-start _retain-labels _attributes float)
+ (caption (org-element-property :caption src-block))
+ (caption-above-p (org-latex--caption-above-p src-block info))
+ (label (org-element-property :name src-block))
+ (custom-env (and lang
+ (cadr (assq (intern lang)
+ org-latex-custom-lang-environments))))
+ (num-start (org-export-get-loc src-block info))
+ (retain-labels (org-element-property :retain-labels src-block))
+ (attributes (org-export-read-attribute :attr_latex src-block))
+ (float (plist-get attributes :float))
+ (listings (plist-get info :latex-listings)))
+ (funcall
+ (pcase listings
+ ((or (pred not) (guard (not lang))) #'org-latex-src-block--verbatim)
+ ((guard custom-env) #'org-latex-src-block--custom)
+ ('minted #'org-latex-src-block--minted)
+ ('engraved #'org-latex-src-block--engraved)
+ (_ #'org-latex-src-block--listings))
+ :src-block src-block
+ :info info
+ :lang lang
+ :caption caption
+ :caption-above-p caption-above-p
+ :label label
+ :num-start num-start
+ :retain-labels retain-labels
+ :attributes attributes
+ :float float))))
+
+(cl-defun org-latex-src-block--verbatim
+ (&key src-block info caption caption-above-p float &allow-other-keys)
"Transcode a SRC-BLOCK element from Org to LaTeX, using verbatim.
LANG, CAPTION, CAPTION-ABOVE-P, LABEL, NUM-START, RETAIN-LABELS, ATTRIBUTES
and FLOAT are extracted from SRC-BLOCK and INFO in `org-latex-src-block'."
@@ -3215,9 +3215,8 @@ (defun org-latex-src-block--verbatim
(if caption-above-p "" (concat "\n" caption-str))))
(t verbatim))))
-(defun org-latex-src-block--custom
- (src-block info _lang caption caption-above-p _label
- _num-start _retain-labels attributes float custom-env)
+(cl-defun org-latex-src-block--custom
+ (&key src-block info caption caption-above-p attributes float custom-env &allow-other-keys)
"Transcode a SRC-BLOCK element from Org to LaTeX, using a custom environment.
LANG, CAPTION, CAPTION-ABOVE-P, LABEL, NUM-START, RETAIN-LABELS, ATTRIBUTES
and FLOAT are extracted from SRC-BLOCK and INFO in `org-latex-src-block'."
@@ -3237,9 +3236,8 @@ (defun org-latex-src-block--custom
(?l . ,(org-latex--label src-block info))
(?o . ,(or (plist-get attributes :options) "")))))))
-(defun org-latex-src-block--minted
- (src-block info lang caption caption-above-p _label
- num-start retain-labels attributes float)
+(cl-defun org-latex-src-block--minted
+ (&key src-block info lang caption caption-above-p num-start retain-labels attributes float &allow-other-keys)
"Transcode a SRC-BLOCK element from Org to LaTeX, using minted.
LANG, CAPTION, CAPTION-ABOVE-P, LABEL, NUM-START, RETAIN-LABELS, ATTRIBUTES
and FLOAT are extracted from SRC-BLOCK and INFO in `org-latex-src-block'."
@@ -3325,9 +3323,8 @@ (defun org-latex-src--engrave-code (content lang)
engraved-code)
(user-error "Cannot engrave code as `engrave-faces-latex' is unavailible.")))
-(defun org-latex-src-block--engraved
- (src-block info lang caption caption-above-p _label
- num-start retain-labels attributes float)
+(cl-defun org-latex-src-block--engraved
+ (&key src-block info lang caption caption-above-p num-start retain-labels attributes float &allow-other-keys)
"Transcode a SRC-BLOCK element from Org to LaTeX, using engrave-faces-latex.
LANG, CAPTION, CAPTION-ABOVE-P, LABEL, NUM-START, RETAIN-LABELS, ATTRIBUTES
and FLOAT are extracted from SRC-BLOCK and INFO in `org-latex-src-block'."
@@ -3387,9 +3384,8 @@ (defun org-latex-src-block--engraved
(org-latex-src--engrave-code content lang))))
(format float-env body)))
-(defun org-latex-src-block--listings
- (src-block info lang caption caption-above-p label
- num-start retain-labels attributes float)
+(cl-defun org-latex-src-block--listings
+ (&key src-block info lang caption caption-above-p label num-start retain-labels attributes float &allow-other-keys)
"Transcode a SRC-BLOCK element from Org to LaTeX, using listings.
LANG, CAPTION, CAPTION-ABOVE-P, LABEL, NUM-START, RETAIN-LABELS, ATTRIBUTES
and FLOAT are extracted from SRC-BLOCK and INFO in `org-latex-src-block'."
--
2.35.3
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #8: 0007-ox-latex-Replace-org-latex-listings.patch --]
[-- Type: text/x-patch, Size: 16128 bytes --]
From adb4b6df3b4549fd6afd6cfb6ae8945e89882cfc Mon Sep 17 00:00:00 2001
From: TEC <tec@tecosaur.com>
Date: Sat, 7 May 2022 14:46:28 +0800
Subject: [PATCH 7/7] ox-latex: Replace `org-latex-listings'
* lisp/ox-latex.el (org-latex-src-block, org-latex-keyword,
org-latex-inline-src-block, org-latex-template,
org-latex--caption/label-string, org-latex-engraved-preamble,
org-latex-listings): Replace `org-latex-listings' with
`org-latex-src-block-backend', which now can be set to listings/verbatim
and no longer advertises t/nil as valid values.
* lisp/ox-beamer.el (org-beamer-template): Update in the same manner as
`org-latex-template'.
* lisp/org-compat.el: Make `org-latex-listings' an obsolete alias for
`org-latex-src-block-backend'.
* testing/lisp/test-ox.el: Replace `org-latex-listings' reference with
`org-latex-src-block-backend'.
* doc/org-manual.org (Footnotes, LaTeX specific properties, Literal
Examples): Replace references to `org-latex-listings' with
`org-latex-src-block-backend'.
* etc/ORG-NEWS: Add a news entry noting this change.
The variable `org-latex-listings' originally indicated whether source
blocks should use the listings LaTeX package, or not. This usage has
evolved over the years, and now it sets one of four different
fontification backends. This renaming should make the variable name a
bit less misleading.
---
doc/org-manual.org | 6 +--
etc/ORG-NEWS | 9 ++++
lisp/org-compat.el | 2 +
lisp/ox-beamer.el | 2 +-
lisp/ox-latex.el | 111 ++++++++++++++++++++++------------------
testing/lisp/test-ox.el | 2 +-
6 files changed, 78 insertions(+), 54 deletions(-)
diff --git a/doc/org-manual.org b/doc/org-manual.org
index c0d38cd8c..60bded419 100644
--- a/doc/org-manual.org
+++ b/doc/org-manual.org
@@ -11159,7 +11159,7 @@ ** Literal Examples
#+end_example
#+cindex: formatting source code, markup rules
-#+vindex: org-latex-listings
+#+vindex: org-latex-src-block-backend
If the example is source code from a programming language, or any
other text that can be marked up by Font Lock in Emacs, you can ask
for the example to look like the fontified Emacs buffer[fn:114]. This
@@ -16304,12 +16304,12 @@ **** LaTeX specific properties
| ~:latex-link-with-unknown-path-format~ | ~org-latex-link-with-unknown-path-format~ |
| ~:latex-listings-langs~ | ~org-latex-listings-langs~ |
| ~:latex-listings-options~ | ~org-latex-listings-options~ |
-| ~:latex-listings~ | ~org-latex-listings~ |
| ~:latex-minted-langs~ | ~org-latex-minted-langs~ |
| ~:latex-minted-options~ | ~org-latex-minted-options~ |
| ~:latex-prefer-user-labels~ | ~org-latex-prefer-user-labels~ |
| ~:latex-subtitle-format~ | ~org-latex-subtitle-format~ |
| ~:latex-subtitle-separate~ | ~org-latex-subtitle-separate~ |
+| ~:latex-src-block-backend~ | ~org-latex-src-block-backend~ |
| ~:latex-table-scientific-notation~ | ~org-latex-table-scientific-notation~ |
| ~:latex-tables-booktabs~ | ~org-latex-tables-booktabs~ |
| ~:latex-tables-centered~ | ~org-latex-tables-centered~ |
@@ -22256,7 +22256,7 @@ * Footnotes
version 1.34 of the =htmlize.el= package, which you need to install).
Fontified code chunks in LaTeX can be achieved using either the
[[https://www.ctan.org/pkg/listings][listings]] package or the [[https://www.ctan.org/pkg/minted][minted]] package. Refer to
-~org-latex-listings~ for details.
+~org-latex-src-block-backend~ for details.
[fn:115] Source code in code blocks may also be evaluated either
interactively or on export. See [[*Working with Source Code]] for more
diff --git a/etc/ORG-NEWS b/etc/ORG-NEWS
index 1e8558c7b..c5f0bcb33 100644
--- a/etc/ORG-NEWS
+++ b/etc/ORG-NEWS
@@ -268,6 +268,15 @@ Chmod-style permissions are based on the new variable
~org-babel-tangle-default-file-mode~.
*** A new custom setting =org-agenda-clock-report-header= to add a header to org agenda clock report
+
+*** ~org-latex-listings~ has been replaced with ~org-latex-src-block-backend~
+
+~org-latex-listings~ has been renamed to better reflect the current
+purpose of the variable. The replacement variable
+~org-latex-src-block-backend~ acts in exactly the same way, however it
+accepts =listings= and =verbatim= in place of =t= and =nil= (which
+still work, but are no longer listed as valid options).
+
* Version 9.5
** Important announcements and breaking changes
diff --git a/lisp/org-compat.el b/lisp/org-compat.el
index f599e246e..c1a78e834 100644
--- a/lisp/org-compat.el
+++ b/lisp/org-compat.el
@@ -324,6 +324,8 @@ (define-obsolete-variable-alias 'org-latex-create-formula-image-program
'org-preview-latex-default-process "9.0")
(define-obsolete-variable-alias 'org-latex-preview-ltxpng-directory
'org-preview-latex-image-directory "9.0")
+(define-obsolete-variable-alias 'org-latex-listings
+ 'org-latex-src-block-backend "9.6")
(define-obsolete-function-alias 'org-table-p 'org-at-table-p "9.0")
(define-obsolete-function-alias 'org-on-heading-p 'org-at-heading-p "9.0")
(define-obsolete-function-alias 'org-at-regexp-p 'org-in-regexp "8.3")
diff --git a/lisp/ox-beamer.el b/lisp/ox-beamer.el
index 4d40f6a1d..3baa4e26e 100644
--- a/lisp/ox-beamer.el
+++ b/lisp/ox-beamer.el
@@ -858,7 +858,7 @@ (defun org-beamer-template (contents info)
(and (stringp template)
(format-spec template (org-latex--format-spec info))))
;; engrave-faces-latex preamble
- (when (eq org-latex-listings 'engraved)
+ (when (eq org-latex-src-block-backend 'engraved)
(let ((src-p (org-element-map (plist-get info :parse-tree)
'(src-block inline-src-block) #'identity
info t))
diff --git a/lisp/ox-latex.el b/lisp/ox-latex.el
index 9150c1011..ffa89188b 100644
--- a/lisp/ox-latex.el
+++ b/lisp/ox-latex.el
@@ -143,7 +143,7 @@ (org-export-define-backend 'latex
(:latex-inactive-timestamp-format nil nil org-latex-inactive-timestamp-format)
(:latex-inline-image-rules nil nil org-latex-inline-image-rules)
(:latex-link-with-unknown-path-format nil nil org-latex-link-with-unknown-path-format)
- (:latex-listings nil nil org-latex-listings)
+ (:latex-src-block-backend nil nil org-latex-src-block-backend)
(:latex-listings-langs nil nil org-latex-listings-langs)
(:latex-listings-options nil nil org-latex-listings-options)
(:latex-minted-langs nil nil org-latex-minted-langs)
@@ -937,22 +937,22 @@ (defcustom org-latex-format-inlinetask-function
;; Src blocks
-(defcustom org-latex-listings nil
- "Non-nil means export source code using the listings package.
+(defcustom org-latex-src-block-backend 'verbatim
+ "Backend used to generate source code listings.
-This package will fontify source code, possibly even with color.
-There are four implementations of this functionality you may
+This sets the behaviour for fontifying source code, possibly even with
+color. There are four implementations of this functionality you may
choose from (ordered from least to most capable):
-1. Verbatim (nil)
-2. Listings (t)
-3. Minted (minted)
-4. Engraved (engraved)
+1. Verbatim
+2. Listings
+3. Minted
+4. Engraved
The first two options provide basic syntax
highlighting (listings), or none at all (verbatim).
-When using listings, you also need to make use of the LaTeX
-\"listings\" package. The \"color\" package is also needed if you
+When using listings, you also need to make use of LaTeX package
+\"listings\"e. The \"color\" LaTeX package is also needed if you
would like color too. These can simply be added to
`org-latex-packages-alist', using customise or something like:
@@ -963,27 +963,12 @@ (defcustom org-latex-listings nil
There are two further options for more comprehensive
fontification. The first can be set with,
- (setq org-latex-listings \\='engraved)
+ (setq org-latex-src-block-backend \\='minted)
-which causes source code to be run through
-`engrave-faces-latex-buffer', which generates colorings using
-Emacs' font-lock information. This requires the engrave-faces
-package (availible from ELPA), and the fvextra LaTeX package be
-installed.
-
-The styling of the engraved result can customised with
-`org-latex-engraved-preamble' and `org-latex-engraved-options'.
-The default preamble also uses the tcolorbox LaTeX package in
-addition to fvextra.
-
-The second more comprehensive option can be set with,
-
- (setq org-latex-listings \\='minted)
-
-which causes source code to be exported using the minted package
-as opposed to listings. If you want to use minted, you need to
-add the minted package to `org-latex-packages-alist', for example
-using customize, or with
+which causes source code to be exported using the LaTeX package
+minted as opposed to listings. If you want to use minted, you
+need to add the minted package to `org-latex-packages-alist', for
+example using customize, or with
(require \\='ox-latex)
(add-to-list \\='org-latex-packages-alist \\='(\"newfloat\" \"minted\"))
@@ -996,14 +981,29 @@ (defcustom org-latex-listings nil
The minted choice has possible repercussions on the preview of
latex fragments (see `org-preview-latex-fragment'). If you run
into previewing problems, please consult
-URL `https://orgmode.org/worg/org-tutorials/org-latex-preview.html'."
+URL `https://orgmode.org/worg/org-tutorials/org-latex-preview.html'.
+
+The most comprehensive option can be set with,
+
+ (setq org-latex-src-block-backend \\='engraved)
+
+which causes source code to be run through
+`engrave-faces-latex-buffer', which generates colorings using
+Emacs' font-lock information. This requires the Emacs package
+engrave-faces (availible from ELPA), and the LaTeX package
+fvextra be installed.
+
+The styling of the engraved result can customised with
+`org-latex-engraved-preamble' and `org-latex-engraved-options'.
+The default preamble also uses the LaTeX package tcolorbox in
+addition to fvextra."
:group 'org-export-latex
:type '(choice
- (const :tag "Use listings" t)
+ (const :tag "Use listings" listings)
(const :tag "Use minted" minted)
(const :tag "Use engrave-faces-latex" engraved)
- (const :tag "Export verbatim" nil))
- :safe (lambda (s) (memq s '(t nil minted engraved))))
+ (const :tag "Export verbatim" verbatim))
+ :safe (lambda (s) (memq s '(listings minted engraved verbatim))))
(defcustom org-latex-listings-langs
'((emacs-lisp "Lisp") (lisp "Lisp") (clojure "Lisp")
@@ -1201,7 +1201,7 @@ (defcustom org-latex-engraved-preamble
right=2pt, top=1pt, bottom=0.5pt,
breakable}"
"Preamble content injected when using engrave-faces-latex for source blocks.
-This is relevant when `org-latex-listings' is set to `engraved'.
+This is relevant when `org-latex-src-block-backend' is set to `engraved'.
There is quite a lot of flexibility in what this preamble can be, as long as it:
- Loads the fvextra package.
@@ -1502,7 +1502,8 @@ (defun org-latex--caption/label-string (element info)
main)
(and (eq type 'src-block)
(not (plist-get attr :float))
- (null (plist-get info :latex-listings)))))
+ (memq (plist-get info :latex-src-block-backend)
+ '(verbatim nil)))))
(short (org-export-get-caption element t))
(caption-from-attr-latex (plist-get attr :caption)))
(cond
@@ -1522,7 +1523,8 @@ (defun org-latex--caption/label-string (element info)
(paragraph "figure")
(image "figure")
(special-block "figure")
- (src-block (if (plist-get info :latex-listings)
+ (src-block (if (not (memq (plist-get info :latex-src-block-backend)
+ '(verbatim nil)))
"listing"
"figure"))
(t (symbol-name type*)))
@@ -1909,7 +1911,7 @@ (defun org-latex-template (contents info)
(and (stringp template)
(format-spec template spec)))
;; engrave-faces-latex preamble
- (when (eq org-latex-listings 'engraved)
+ (when (eq org-latex-src-block-backend 'engraved)
(let ((src-p (org-element-map (plist-get info :parse-tree)
'(src-block inline-src-block) #'identity
info t))
@@ -2302,11 +2304,17 @@ (defun org-latex-inline-src-block (inline-src-block _contents info)
contextual information."
(let ((code (org-element-property :value inline-src-block))
(lang (org-element-property :language inline-src-block)))
- (pcase (plist-get info :latex-listings)
- ('nil (org-latex--text-markup code 'code info))
+ (pcase (plist-get info :latex-src-block-backend)
+ ('verbatim (org-latex--text-markup code 'code info))
('minted (org-latex-inline-src-block--minted info code lang))
('engraved (org-latex-inline-src-block--engraved info code lang))
- (_ (org-latex-inline-src-block--listings info code lang)))))
+ ('listings (org-latex-inline-src-block--listings info code lang))
+ (oldval
+ (message "Please update the LaTeX src-block-backend to %s"
+ (if oldval "listings" "verbatim"))
+ (if oldval
+ (org-latex-inline-src-block--listings info code lang)
+ (org-latex--text-markup code 'code info))))))
(defun org-latex-inline-src-block--minted (info code lang)
"Transcode an inline src block's content from Org to LaTeX, using minted.
@@ -2489,7 +2497,7 @@ (defun org-latex-keyword (keyword _contents info)
(concat depth (and depth "\n") "\\tableofcontents"))))
((string-match-p "\\<tables\\>" value) "\\listoftables")
((string-match-p "\\<listings\\>" value)
- (cl-case (plist-get info :latex-listings)
+ (cl-case (plist-get info :latex-src-block-backend)
((nil) "\\listoffigures")
(minted "\\listoflistings")
(otherwise "\\lstlistoflistings")))))))))
@@ -3175,15 +3183,20 @@ (defun org-latex-src-block (src-block _contents info)
(num-start (org-export-get-loc src-block info))
(retain-labels (org-element-property :retain-labels src-block))
(attributes (org-export-read-attribute :attr_latex src-block))
- (float (plist-get attributes :float))
- (listings (plist-get info :latex-listings)))
+ (float (plist-get attributes :float)))
(funcall
- (pcase listings
- ((or (pred not) (guard (not lang))) #'org-latex-src-block--verbatim)
- ((guard custom-env) #'org-latex-src-block--custom)
+ (pcase (plist-get info :latex-src-block-backend)
+ ((or 'verbatim (guard (not lang))) #'org-latex-src-block--verbatim)
('minted #'org-latex-src-block--minted)
('engraved #'org-latex-src-block--engraved)
- (_ #'org-latex-src-block--listings))
+ ('listings #'org-latex-src-block--listings)
+ ((guard custom-env) #'org-latex-src-block--custom)
+ (oldval
+ (message "Please update the LaTeX src-block-backend to %s"
+ (if oldval "listings" "verbatim"))
+ (if oldval
+ #'org-latex-src-block--listings
+ #'org-latex-src-block--verbatim)))
:src-block src-block
:info info
:lang lang
diff --git a/testing/lisp/test-ox.el b/testing/lisp/test-ox.el
index 25e02b258..28f950813 100644
--- a/testing/lisp/test-ox.el
+++ b/testing/lisp/test-ox.el
@@ -3978,7 +3978,7 @@ (ert-deftest test-org-export/latex-src-block-verbatim-caption ()
\\end{verbatim}
\\caption{Caption is below, 60\\%s}
\\end{figure*}"
- (let ((org-latex-listings 'minted) ; inactive due to missing lang
+ (let ((org-latex-src-block-backend 'minted) ; inactive due to missing lang
(org-latex-default-figure-position "tp"))
;; Namely "multicolumn" value to get just figure environment
;; looks like a bug.
--
2.35.3
^ permalink raw reply related [relevance 8%]
* Re: [PATCH] New LaTeX code export option: engraved
@ 2022-05-07 6:57 7% ` Timothy
2022-05-07 10:40 8% ` Timothy
0 siblings, 1 reply; 200+ results
From: Timothy @ 2022-05-07 6:57 UTC (permalink / raw)
To: Ihor Radchenko; +Cc: emacs-orgmode, Daniel Fleischer, Nicolas Goaziou
[-- Attachment #1: Type: text/plain, Size: 3409 bytes --]
Hi Ihor,
Find attached an updated patchset, and comments below :)
Ihor Radchenko <yantar92@gmail.com> writes:
> Maybe “The other two options”? Also, using first/second here is a bit
> confusing because: (1) they are actually 3/4 in the above list; (2)
> engraved is listed last.
Docstring changed.
>> +The second more comprehensive option can be used with,
>
> *can be set with
Changed.
> I feel slightly confused about using the word “package” here. Which one
> refers to LaTeX package and which one to Emacs? I would state “Emacs
> package” explicitly to highlight contrast with “LaTeX package”.
Clarifications added to the docstring.
>> +\\{\\\FancyVerbLine}
>
> I’d like to see a comment on what it does.
Added.
> Same request to provide a comment. Also, what it that % TODO doing
> there? It is confusing.
A comment has been added, and the TODO removed.
> Also, it is unclear what the [breakable,xparse] options to tcolorbox are
> doing there and what will happen if the user removes them.
“breakable” allows the box to be broken across pages, and “xparse” provides
`\DeclareTColorBox'.
> Further, I am wondering what is going to happen if the user happens to
> have tcolorbox without options loaded via org-latex-packages-alist.
They could see: ERROR: LaTeX Error: Option clash for package tcolorbox.
They would need to tweak such a tcolorbox entry to include the options used
here.
>> +There is quite a lot of flexibility in what this preamble can be, as long as it:
>> +- Loads the fvextra package.
>> +- Loads the package xcolor (if it is not already loader elsewhere).
>> +- Defines a \“Code\” environment (note the capital C), which can be
>> + later used to wrap \“Verbatim\” environments (provided by fvextra).
>
> The last point is not very clear. What kind of environment?
Anything that the user wants to do to modify the display of the generated
`Verbatim' environment.
>> +(defun org-latex-generate-engraved-preamble (info syntax-colours-p)
>> + “Generate the preamble to setup engraved code.
>> +The result is constructed from `org-latex-engraved-preamble’ and
>> +`org-latex-engraved-options’.”
>
> This is relying on
>
> (:latex-engraved-options nil nil org-latex-engraved-options)
> (:latex-engraved-preamble nil nil org-latex-engraved-preamble)
>
> If it changes any time in future (e.g. to allow per-file settings), the
> docstring may be overlooked.
Docstring tweaked.
> I’d use FIRST-MATCH argument for org-element-map. It will be slightly
> faster on large buffers.
Ah nice, I’ll make use of that.
>> - (downcase org-lang)))
>> + (downcase lang)))
>
> I am not sure if this belongs to this patch. Please double check.
Ooops, moved to the correct patch.
>> + (mapcar ’length
>> + (org-split-string (car code-info)
>> + “”)))))
>
> I am not sure how well it will work with e.g. Chinese characters in comments.
I’ve added a patch replacing `length' with `string-width'
> Maybe the functions could be rewritten using cl-defun with keys and
> &allow-other-keys and then called via apply on a let-bound arg plist?
Done.
All the best,
Timothy
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-ox-latex-Refactor-org-latex-src-block.patch --]
[-- Type: text/x-patch, Size: 15942 bytes --]
From d231437e2c9f96bf70520d9ddda810a95667fcdd Mon Sep 17 00:00:00 2001
From: TEC <tec@tecosaur.com>
Date: Sun, 21 Nov 2021 14:35:34 +0800
Subject: [PATCH 1/7] ox-latex: Refactor `org-latex-src-block'
* lisp/ox-latex.el (org-latex-src-block): Extract the per-format logic
from `org-latex-src-block' into new dedicated functions:
+ `org-latex-src-block--verbatim'
+ `org-latex-src-block--custom'
+ `org-latex-src-block--minted'
+ `org-latex-src-block--listings'
This makes `org-latex-src-block' much less monolithic, taking it from
175 lines to 30, and I find also makes it easier to understand.
---
lisp/ox-latex.el | 339 ++++++++++++++++++++++++++---------------------
1 file changed, 185 insertions(+), 154 deletions(-)
diff --git a/lisp/ox-latex.el b/lisp/ox-latex.el
index 841ad48bc..c2f728a1c 100644
--- a/lisp/ox-latex.el
+++ b/lisp/ox-latex.el
@@ -2997,164 +2997,195 @@ (defun org-latex-src-block (src-block _contents info)
(float (plist-get attributes :float))
(listings (plist-get info :latex-listings)))
(cond
- ;; Case 1. No source fontification.
((or (not lang) (not listings))
- (let ((caption-str (org-latex--caption/label-string src-block info))
- (verbatim (format "\\begin{verbatim}\n%s\\end{verbatim}"
- (org-export-format-code-default src-block info))))
- (cond ((string= "multicolumn" float)
- (format "\\begin{figure*}[%s]\n%s%s\n%s\\end{figure*}"
- (plist-get info :latex-default-figure-position)
- (if caption-above-p caption-str "")
- verbatim
- (if caption-above-p "" caption-str)))
- (caption (concat
- (if caption-above-p caption-str "")
- verbatim
- (if caption-above-p "" (concat "\n" caption-str))))
- (t verbatim))))
- ;; Case 2. Custom environment.
+ (org-latex-src-block--verbatim src-block info lang caption caption-above-p label
+ num-start retain-labels attributes float))
(custom-env
- (let ((caption-str (org-latex--caption/label-string src-block info))
- (formatted-src (org-export-format-code-default src-block info)))
- (if (string-match-p "\\`[a-zA-Z0-9]+\\'" custom-env)
- (format "\\begin{%s}\n%s\\end{%s}\n"
- custom-env
- (concat (and caption-above-p caption-str)
- formatted-src
- (and (not caption-above-p) caption-str))
- custom-env)
- (format-spec custom-env
- `((?s . ,formatted-src)
- (?c . ,caption)
- (?f . ,float)
- (?l . ,(org-latex--label src-block info))
- (?o . ,(or (plist-get attributes :options) "")))))))
- ;; Case 3. Use minted package.
+ (org-latex-src-block--custom src-block info lang caption caption-above-p label
+ num-start retain-labels attributes float custom-env))
((eq listings 'minted)
- (let* ((caption-str (org-latex--caption/label-string src-block info))
- (placement (or (org-unbracket-string "[" "]" (plist-get attributes :placement))
- (plist-get info :latex-default-figure-position)))
- (float-env
- (cond
- ((string= "multicolumn" float)
- (format "\\begin{listing*}[%s]\n%s%%s\n%s\\end{listing*}"
- placement
- (if caption-above-p caption-str "")
- (if caption-above-p "" caption-str)))
- (caption
- (format "\\begin{listing}[%s]\n%s%%s\n%s\\end{listing}"
- placement
- (if caption-above-p caption-str "")
- (if caption-above-p "" caption-str)))
- ((string= "t" float)
- (concat (format "\\begin{listing}[%s]\n"
- placement)
- "%s\n\\end{listing}"))
- (t "%s")))
- (options (plist-get info :latex-minted-options))
- (body
- (format
- "\\begin{minted}[%s]{%s}\n%s\\end{minted}"
- ;; Options.
- (concat
- (org-latex--make-option-string
- (if (or (not num-start) (assoc "linenos" options))
- options
- (append
- `(("linenos")
- ("firstnumber" ,(number-to-string (1+ num-start))))
- options)))
- (let ((local-options (plist-get attributes :options)))
- (and local-options (concat "," local-options))))
- ;; Language.
- (or (cadr (assq (intern lang)
- (plist-get info :latex-minted-langs)))
- (downcase lang))
- ;; Source code.
- (let* ((code-info (org-export-unravel-code src-block))
- (max-width
- (apply 'max
- (mapcar 'length
- (org-split-string (car code-info)
- "\n")))))
- (org-export-format-code
- (car code-info)
- (lambda (loc _num ref)
- (concat
- loc
- (when ref
- ;; Ensure references are flushed to the right,
- ;; separated with 6 spaces from the widest line
- ;; of code.
- (concat (make-string (+ (- max-width (length loc)) 6)
- ?\s)
- (format "(%s)" ref)))))
- nil (and retain-labels (cdr code-info)))))))
- ;; Return value.
- (format float-env body)))
- ;; Case 4. Use listings package.
+ (org-latex-src-block--minted src-block info lang caption caption-above-p label
+ num-start retain-labels attributes float))
(t
- (let ((lst-lang
- (or (cadr (assq (intern lang)
- (plist-get info :latex-listings-langs)))
- lang))
- (caption-str
- (when caption
- (let ((main (org-export-get-caption src-block))
- (secondary (org-export-get-caption src-block t)))
- (if (not secondary)
- (format "{%s}" (org-export-data main info))
- (format "{[%s]%s}"
- (org-export-data secondary info)
- (org-export-data main info))))))
- (lst-opt (plist-get info :latex-listings-options)))
- (concat
- ;; Options.
- (format
- "\\lstset{%s}\n"
- (concat
- (org-latex--make-option-string
- (append
- lst-opt
- (cond
- ((and (not float) (plist-member attributes :float)) nil)
- ((string= "multicolumn" float) '(("float" "*")))
- ((and float (not (assoc "float" lst-opt)))
- `(("float" ,(plist-get info :latex-default-figure-position)))))
- `(("language" ,lst-lang))
- (if label
- `(("label" ,(org-latex--label src-block info)))
- '(("label" " ")))
- (if caption-str `(("caption" ,caption-str)) '(("caption" " ")))
- `(("captionpos" ,(if caption-above-p "t" "b")))
- (cond ((assoc "numbers" lst-opt) nil)
- ((not num-start) '(("numbers" "none")))
- (t `(("firstnumber" ,(number-to-string (1+ num-start)))
- ("numbers" "left"))))))
- (let ((local-options (plist-get attributes :options)))
- (and local-options (concat "," local-options)))))
- ;; Source code.
- (format
- "\\begin{lstlisting}\n%s\\end{lstlisting}"
- (let* ((code-info (org-export-unravel-code src-block))
- (max-width
- (apply 'max
- (mapcar 'length
- (org-split-string (car code-info) "\n")))))
- (org-export-format-code
- (car code-info)
- (lambda (loc _num ref)
- (concat
- loc
- (when ref
- ;; Ensure references are flushed to the right,
- ;; separated with 6 spaces from the widest line of
- ;; code
- (concat (make-string (+ (- max-width (length loc)) 6) ?\s)
- (format "(%s)" ref)))))
- nil (and retain-labels (cdr code-info))))))))))))
-
+ (org-latex-src-block--listings src-block info lang caption caption-above-p label
+ num-start retain-labels attributes float))))))
+
+(defun org-latex-src-block--verbatim
+ (src-block info _lang caption caption-above-p _label
+ _num-start _retain-labels _attributes float)
+ "Transcode a SRC-BLOCK element from Org to LaTeX, using verbatim.
+LANG, CAPTION, CAPTION-ABOVE-P, LABEL, NUM-START, RETAIN-LABELS, ATTRIBUTES
+and FLOAT are extracted from SRC-BLOCK and INFO in `org-latex-src-block'."
+ (let ((caption-str (org-latex--caption/label-string src-block info))
+ (verbatim (format "\\begin{verbatim}\n%s\\end{verbatim}"
+ (org-export-format-code-default src-block info))))
+ (cond ((string= "multicolumn" float)
+ (format "\\begin{figure*}[%s]\n%s%s\n%s\\end{figure*}"
+ (plist-get info :latex-default-figure-position)
+ (if caption-above-p caption-str "")
+ verbatim
+ (if caption-above-p "" caption-str)))
+ (caption (concat
+ (if caption-above-p caption-str "")
+ verbatim
+ (if caption-above-p "" (concat "\n" caption-str))))
+ (t verbatim))))
+
+(defun org-latex-src-block--custom
+ (src-block info _lang caption caption-above-p _label
+ _num-start _retain-labels attributes float custom-env)
+ "Transcode a SRC-BLOCK element from Org to LaTeX, using a custom environment.
+LANG, CAPTION, CAPTION-ABOVE-P, LABEL, NUM-START, RETAIN-LABELS, ATTRIBUTES
+and FLOAT are extracted from SRC-BLOCK and INFO in `org-latex-src-block'."
+ (let ((caption-str (org-latex--caption/label-string src-block info))
+ (formatted-src (org-export-format-code-default src-block info)))
+ (if (string-match-p "\\`[a-zA-Z0-9]+\\'" custom-env)
+ (format "\\begin{%s}\n%s\\end{%s}\n"
+ custom-env
+ (concat (and caption-above-p caption-str)
+ formatted-src
+ (and (not caption-above-p) caption-str))
+ custom-env)
+ (format-spec custom-env
+ `((?s . ,formatted-src)
+ (?c . ,caption)
+ (?f . ,float)
+ (?l . ,(org-latex--label src-block info))
+ (?o . ,(or (plist-get attributes :options) "")))))))
+
+(defun org-latex-src-block--minted
+ (src-block info lang caption caption-above-p _label
+ num-start retain-labels attributes float)
+ "Transcode a SRC-BLOCK element from Org to LaTeX, using minted.
+LANG, CAPTION, CAPTION-ABOVE-P, LABEL, NUM-START, RETAIN-LABELS, ATTRIBUTES
+and FLOAT are extracted from SRC-BLOCK and INFO in `org-latex-src-block'."
+ (let* ((caption-str (org-latex--caption/label-string src-block info))
+ (placement (or (org-unbracket-string "[" "]" (plist-get attributes :placement))
+ (plist-get info :latex-default-figure-position)))
+ (float-env
+ (cond
+ ((string= "multicolumn" float)
+ (format "\\begin{listing*}[%s]\n%s%%s\n%s\\end{listing*}"
+ placement
+ (if caption-above-p caption-str "")
+ (if caption-above-p "" caption-str)))
+ (caption
+ (format "\\begin{listing}[%s]\n%s%%s\n%s\\end{listing}"
+ placement
+ (if caption-above-p caption-str "")
+ (if caption-above-p "" caption-str)))
+ ((string= "t" float)
+ (concat (format "\\begin{listing}[%s]\n"
+ placement)
+ "%s\n\\end{listing}"))
+ (t "%s")))
+ (options (plist-get info :latex-minted-options))
+ (body
+ (format
+ "\\begin{minted}[%s]{%s}\n%s\\end{minted}"
+ ;; Options.
+ (concat
+ (org-latex--make-option-string
+ (if (or (not num-start) (assoc "linenos" options))
+ options
+ (append
+ `(("linenos")
+ ("firstnumber" ,(number-to-string (1+ num-start))))
+ options)))
+ (let ((local-options (plist-get attributes :options)))
+ (and local-options (concat "," local-options))))
+ ;; Language.
+ (or (cadr (assq (intern lang)
+ (plist-get info :latex-minted-langs)))
+ (downcase lang))
+ ;; Source code.
+ (let* ((code-info (org-export-unravel-code src-block))
+ (max-width
+ (apply 'max
+ (mapcar 'length
+ (org-split-string (car code-info)
+ "\n")))))
+ (org-export-format-code
+ (car code-info)
+ (lambda (loc _num ref)
+ (concat
+ loc
+ (when ref
+ ;; Ensure references are flushed to the right,
+ ;; separated with 6 spaces from the widest line
+ ;; of code.
+ (concat (make-string (+ (- max-width (length loc)) 6)
+ ?\s)
+ (format "(%s)" ref)))))
+ nil (and retain-labels (cdr code-info)))))))
+ ;; Return value.
+ (format float-env body)))
+
+(defun org-latex-src-block--listings
+ (src-block info lang caption caption-above-p label
+ num-start retain-labels attributes float)
+ "Transcode a SRC-BLOCK element from Org to LaTeX, using listings.
+LANG, CAPTION, CAPTION-ABOVE-P, LABEL, NUM-START, RETAIN-LABELS, ATTRIBUTES
+and FLOAT are extracted from SRC-BLOCK and INFO in `org-latex-src-block'."
+ (let ((lst-lang
+ (or (cadr (assq (intern lang)
+ (plist-get info :latex-listings-langs)))
+ lang))
+ (caption-str
+ (when caption
+ (let ((main (org-export-get-caption src-block))
+ (secondary (org-export-get-caption src-block t)))
+ (if (not secondary)
+ (format "{%s}" (org-export-data main info))
+ (format "{[%s]%s}"
+ (org-export-data secondary info)
+ (org-export-data main info))))))
+ (lst-opt (plist-get info :latex-listings-options)))
+ (concat
+ ;; Options.
+ (format
+ "\\lstset{%s}\n"
+ (concat
+ (org-latex--make-option-string
+ (append
+ lst-opt
+ (cond
+ ((and (not float) (plist-member attributes :float)) nil)
+ ((string= "multicolumn" float) '(("float" "*")))
+ ((and float (not (assoc "float" lst-opt)))
+ `(("float" ,(plist-get info :latex-default-figure-position)))))
+ `(("language" ,lst-lang))
+ (if label
+ `(("label" ,(org-latex--label src-block info)))
+ '(("label" " ")))
+ (if caption-str `(("caption" ,caption-str)) '(("caption" " ")))
+ `(("captionpos" ,(if caption-above-p "t" "b")))
+ (cond ((assoc "numbers" lst-opt) nil)
+ ((not num-start) '(("numbers" "none")))
+ (t `(("firstnumber" ,(number-to-string (1+ num-start)))
+ ("numbers" "left"))))))
+ (let ((local-options (plist-get attributes :options)))
+ (and local-options (concat "," local-options)))))
+ ;; Source code.
+ (format
+ "\\begin{lstlisting}\n%s\\end{lstlisting}"
+ (let* ((code-info (org-export-unravel-code src-block))
+ (max-width
+ (apply 'max
+ (mapcar 'length
+ (org-split-string (car code-info) "\n")))))
+ (org-export-format-code
+ (car code-info)
+ (lambda (loc _num ref)
+ (concat
+ loc
+ (when ref
+ ;; Ensure references are flushed to the right,
+ ;; separated with 6 spaces from the widest line of
+ ;; code
+ (concat (make-string (+ (- max-width (length loc)) 6) ?\s)
+ (format "(%s)" ref)))))
+ nil (and retain-labels (cdr code-info))))))))
;;;; Statistics Cookie
--
2.35.3
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #3: 0002-ox-latex-Refactor-org-latex-inline-src-block.patch --]
[-- Type: text/x-patch, Size: 4016 bytes --]
From aa8406ce64507b870322495e8f9b54317930ed24 Mon Sep 17 00:00:00 2001
From: TEC <tec@tecosaur.com>
Date: Wed, 4 May 2022 18:53:10 +0800
Subject: [PATCH 2/7] ox-latex: Refactor `org-latex-inline-src-block'
* lisp/ox-latex.el (org-latex-inline-src-block,
org-latex-inline-src-block--minted,
org-latex-inline-src-block--listings): Extract the minted and listings
specific logic out of `org-latex-inline-src-block` into the new
functions `org-latex-inline-src-block--minted` and
`org-latex-inline-src-block--listings`.
---
lisp/ox-latex.el | 62 +++++++++++++++++++++++++-----------------------
1 file changed, 32 insertions(+), 30 deletions(-)
diff --git a/lisp/ox-latex.el b/lisp/ox-latex.el
index c2f728a1c..38f36a1f3 100644
--- a/lisp/ox-latex.el
+++ b/lisp/ox-latex.el
@@ -2127,36 +2127,38 @@ (defun org-latex-inline-src-block (inline-src-block _contents info)
"Transcode an INLINE-SRC-BLOCK element from Org to LaTeX.
CONTENTS holds the contents of the item. INFO is a plist holding
contextual information."
- (let* ((code (org-element-property :value inline-src-block))
- (separator (org-latex--find-verb-separator code)))
- (cl-case (plist-get info :latex-listings)
- ;; Do not use a special package: transcode it verbatim, as code.
- ((nil) (org-latex--text-markup code 'code info))
- ;; Use minted package.
- (minted
- (let* ((org-lang (org-element-property :language inline-src-block))
- (mint-lang (or (cadr (assq (intern org-lang)
- (plist-get info :latex-minted-langs)))
- (downcase org-lang)))
- (options (org-latex--make-option-string
- (plist-get info :latex-minted-options))))
- (format "\\mintinline%s{%s}{%s}"
- (if (string= options "") "" (format "[%s]" options))
- mint-lang
- code)))
- ;; Use listings package.
- (otherwise
- ;; Maybe translate language's name.
- (let* ((org-lang (org-element-property :language inline-src-block))
- (lst-lang (or (cadr (assq (intern org-lang)
- (plist-get info :latex-listings-langs)))
- org-lang))
- (options (org-latex--make-option-string
- (append (plist-get info :latex-listings-options)
- `(("language" ,lst-lang))))))
- (concat (format "\\lstinline[%s]" options)
- separator code separator))))))
-
+ (let ((code (org-element-property :value inline-src-block))
+ (lang (org-element-property :language inline-src-block)))
+ (pcase (plist-get info :latex-listings)
+ ('nil (org-latex--text-markup code 'code info))
+ ('minted (org-latex-inline-src-block--minted info code lang))
+ (_ (org-latex-inline-src-block--listings info code lang)))))
+
+(defun org-latex-inline-src-block--minted (info code lang)
+ "Transcode an inline src block's content from Org to LaTeX, using minted.
+INFO, CODE, and LANG are provided by `org-latex-inline-src-block'."
+ (let ((mint-lang (or (cadr (assq (intern lang)
+ (plist-get info :latex-minted-langs)))
+ (downcase lang)))
+ (options (org-latex--make-option-string
+ (plist-get info :latex-minted-options))))
+ (format "\\mintinline%s{%s}{%s}"
+ (if (string= options "") "" (format "[%s]" options))
+ mint-lang
+ code)))
+
+(defun org-latex-inline-src-block--listings (info code lang)
+ "Transcode an inline src block's content from Org to LaTeX, using lstlistings.
+INFO, CODE, and LANG are provided by `org-latex-inline-src-block'."
+ (let* ((lst-lang (or (cadr (assq (intern lang)
+ (plist-get info :latex-listings-langs)))
+ lang))
+ (separator (org-latex--find-verb-separator code))
+ (options (org-latex--make-option-string
+ (append (plist-get info :latex-listings-options)
+ `(("language" ,lst-lang))))))
+ (concat (format "\\lstinline[%s]" options)
+ separator code separator)))
;;;; Inlinetask
--
2.35.3
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #4: 0003-ox-latex-More-versitile-option-construction.patch --]
[-- Type: text/x-patch, Size: 4116 bytes --]
From 62d6703f0dd622916dff8aab960db6df4cb58cf7 Mon Sep 17 00:00:00 2001
From: TEC <tec@tecosaur.com>
Date: Wed, 4 May 2022 23:31:59 +0800
Subject: [PATCH 3/7] ox-latex: More versitile option construction
* lisp/ox-latex.el (org-latex--make-option-string): Support a custom
option seperator string.
(org-latex--make-option-string, org-latex-minted-options,
org-latex-listings-options): The first line of the docstrings for
`org-latex-minted-options` and `org-latex-listings-options` describe the
variables as "association lists", yet `org-latex--make-option-string`
does not handle association lists and an example of two-value lists is
provided. To make the behaviour match the docstring,
`org-latex--make-option-string` is modified to work with either a list
two-value lists or an association list, and the examples in
`org-latex-minted-options` and `org-latex-listings-options` updated
accordingly.
---
lisp/ox-latex.el | 38 ++++++++++++++++++++++++--------------
1 file changed, 24 insertions(+), 14 deletions(-)
diff --git a/lisp/ox-latex.el b/lisp/ox-latex.el
index 38f36a1f3..2d4b3bace 100644
--- a/lisp/ox-latex.el
+++ b/lisp/ox-latex.el
@@ -1006,12 +1006,16 @@ (defcustom org-latex-listings-options nil
These options are supplied as a comma-separated list to the
\\lstset command. Each element of the association list should be
-a list containing two strings: the name of the option, and the
-value. For example,
+a list or cons cell containing two strings: the name of the
+option, and the value. For example,
(setq org-latex-listings-options
\\='((\"basicstyle\" \"\\\\small\")
(\"keywordstyle\" \"\\\\color{black}\\\\bfseries\\\\underbar\")))
+ ; or
+ (setq org-latex-listings-options
+ \\='((\"basicstyle\" . \"\\\\small\")
+ (\"keywordstyle\" . \"\\\\color{black}\\\\bfseries\\\\underbar\")))
will typeset the code in a small size font with underlined, bold
black keywords.
@@ -1059,11 +1063,14 @@ (defcustom org-latex-minted-options nil
These options are supplied within square brackets in
\\begin{minted} environments. Each element of the alist should
-be a list containing two strings: the name of the option, and the
-value. For example,
+be a list or cons cell containing two strings: the name of the
+option, and the value. For example,
(setq org-latex-minted-options
\\='((\"bgcolor\" \"bg\") (\"frame\" \"lines\")))
+ ; or
+ (setq org-latex-minted-options
+ \\='((\"bgcolor\" . \"bg\") (\"frame\" . \"lines\")))
will result in source blocks being exported with
@@ -1506,21 +1513,24 @@ (defun org-latex--find-verb-separator (s)
when (not (string-match (regexp-quote (char-to-string c)) s))
return (char-to-string c))))
-(defun org-latex--make-option-string (options)
+(defun org-latex--make-option-string (options &optional seperator)
"Return a comma separated string of keywords and values.
OPTIONS is an alist where the key is the options keyword as
a string, and the value a list containing the keyword value, or
nil."
(mapconcat (lambda (pair)
- (pcase-let ((`(,keyword ,value) pair))
- (concat keyword
- (and (> (length value) 0)
- (concat "="
- (if (string-match-p (rx (any "[]")) value)
- (format "{%s}" value)
- value))))))
- options
- ","))
+ (let ((keyword (car pair))
+ (value (pcase (cdr pair)
+ ((pred stringp) (cdr pair))
+ ((pred consp) (cadr pair)))))
+ (concat keyword
+ (when value
+ (concat "="
+ (if (string-match-p (rx (any "[]")) value)
+ (format "{%s}" value)
+ value))))))
+ options
+ (or seperator ",")))
(defun org-latex--wrap-label (element output info)
"Wrap label associated to ELEMENT around OUTPUT, if appropriate.
--
2.35.3
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #5: 0004-ox-latex-Introduce-engraved-code-highlighting.patch --]
[-- Type: text/x-patch, Size: 17266 bytes --]
From 410fda41ae1efa67313ebbe2ada381c5d0f0a092 Mon Sep 17 00:00:00 2001
From: TEC <tec@tecosaur.com>
Date: Sun, 21 Nov 2021 20:04:12 +0800
Subject: [PATCH 4/7] ox-latex: Introduce "engraved" code highlighting
* lisp/ox-latex.el (org-latex-src-block, org-latex-src-block--engraved,
org-latex-inline-src-block, org-latex-inline-src-block--engraved,
org-latex-template, org-latex-listings): Make use of the engraved-faces
package (available on ELPA) to provide an alternative LaTeX code
highlighting backend which functions similarly to htmlize.el for HTML
exports.
(org-latex-engraved-preamble, org-latex-engraved-options): Introduce
variables to construct the preamble for engraved code blocks.
* lisp/ox-beamer.el (org-beamer-template): Modify to add engrave-faces
preamble when applicable.
---
lisp/ox-beamer.el | 11 ++
lisp/ox-latex.el | 276 ++++++++++++++++++++++++++++++++++++++++++++--
2 files changed, 278 insertions(+), 9 deletions(-)
diff --git a/lisp/ox-beamer.el b/lisp/ox-beamer.el
index 6be73c91e..4d40f6a1d 100644
--- a/lisp/ox-beamer.el
+++ b/lisp/ox-beamer.el
@@ -857,6 +857,17 @@ (defun org-beamer-template (contents info)
(let ((template (plist-get info :latex-hyperref-template)))
(and (stringp template)
(format-spec template (org-latex--format-spec info))))
+ ;; engrave-faces-latex preamble
+ (when (eq org-latex-listings 'engraved)
+ (let ((src-p (org-element-map (plist-get info :parse-tree)
+ '(src-block inline-src-block) #'identity
+ info t))
+ (fixedw-p
+ (org-element-map (plist-get info :parse-tree)
+ '(example-block fixed-width) #'identity
+ info t)))
+ (when (or src-p fixedw-p)
+ (org-latex-generate-engraved-preamble info src-p))))
;; Document start.
"\\begin{document}\n\n"
;; Title command.
diff --git a/lisp/ox-latex.el b/lisp/ox-latex.el
index 2d4b3bace..b9c6d4c3e 100644
--- a/lisp/ox-latex.el
+++ b/lisp/ox-latex.el
@@ -37,6 +37,8 @@ (defvar org-latex-default-packages-alist)
(defvar org-latex-packages-alist)
(defvar orgtbl-exp-regexp)
+(declare-function engrave-faces-latex-gen-preamble "ext:engrave-faces-latex")
+(declare-function engrave-faces-latex-buffer "ext:engrave-faces-latex")
\f
;;; Define Back-End
@@ -125,6 +127,8 @@ (org-export-define-backend 'latex
(:latex-default-quote-environment nil nil org-latex-default-quote-environment)
(:latex-default-table-mode nil nil org-latex-default-table-mode)
(:latex-diary-timestamp-format nil nil org-latex-diary-timestamp-format)
+ (:latex-engraved-options nil nil org-latex-engraved-options)
+ (:latex-engraved-preamble nil nil org-latex-engraved-preamble)
(:latex-footnote-defined-format nil nil org-latex-footnote-defined-format)
(:latex-footnote-separator nil nil org-latex-footnote-separator)
(:latex-format-drawer-function nil nil org-latex-format-drawer-function)
@@ -937,22 +941,48 @@ (defcustom org-latex-listings nil
"Non-nil means export source code using the listings package.
This package will fontify source code, possibly even with color.
-If you want to use this, you also need to make LaTeX use the
-listings package, and if you want to have color, the color
-package. Just add these to `org-latex-packages-alist', for
-example using customize, or with something like:
+There are four implementations of this functionality you may
+choose from (ordered from least to most capable):
+1. Verbatim (nil)
+2. Listings (t)
+3. Minted (minted)
+4. Engraved (engraved)
+
+The first two options provide basic syntax
+highlighting (listings), or none at all (verbatim).
+
+When using listings, you also need to make use of the LaTeX
+\"listings\" package. The \"color\" package is also needed if you
+would like color too. These can simply be added to
+`org-latex-packages-alist', using customise or something like:
(require \\='ox-latex)
(add-to-list \\='org-latex-packages-alist \\='(\"\" \"listings\"))
(add-to-list \\='org-latex-packages-alist \\='(\"\" \"color\"))
-Alternatively,
+There are two further options for more comprehensive
+fontification. The first can be set with,
+
+ (setq org-latex-listings \\='engraved)
+
+which causes source code to be run through
+`engrave-faces-latex-buffer', which generates colorings using
+Emacs' font-lock information. This requires the engrave-faces
+package (availible from ELPA), and the fvextra LaTeX package be
+installed.
+
+The styling of the engraved result can customised with
+`org-latex-engraved-preamble' and `org-latex-engraved-options'.
+The default preamble also uses the tcolorbox LaTeX package in
+addition to fvextra.
+
+The second more comprehensive option can be set with,
(setq org-latex-listings \\='minted)
-causes source code to be exported using the minted package as
-opposed to listings. If you want to use minted, you need to add
-the minted package to `org-latex-packages-alist', for example
+which causes source code to be exported using the minted package
+as opposed to listings. If you want to use minted, you need to
+add the minted package to `org-latex-packages-alist', for example
using customize, or with
(require \\='ox-latex)
@@ -971,8 +1001,9 @@ (defcustom org-latex-listings nil
:type '(choice
(const :tag "Use listings" t)
(const :tag "Use minted" minted)
+ (const :tag "Use engrave-faces-latex" engraved)
(const :tag "Export verbatim" nil))
- :safe (lambda (s) (memq s '(t nil minted))))
+ :safe (lambda (s) (memq s '(t nil minted engraved))))
(defcustom org-latex-listings-langs
'((emacs-lisp "Lisp") (lisp "Lisp") (clojure "Lisp")
@@ -1142,6 +1173,127 @@ (defcustom org-latex-custom-lang-environments nil
:version "26.1"
:package-version '(Org . "9.0"))
+(defcustom org-latex-engraved-preamble
+ "\\usepackage{fvextra}
+
+[FVEXTRA-SETUP]
+
+% Make line numbers smaller and grey.
+\\renewcommand\\theFancyVerbLine{\\footnotesize\\color{black!40!white}\\arabic{FancyVerbLine}}
+
+\\usepackage{xcolor}
+
+\\providecolor{codebackground}{HTML}{f7f7f7}
+\\providecolor{codeborder}{HTML}{f0f0f0}
+\\providecolor{EFD}{HTML}{28292e}
+
+% Define a Code environment to prettily wrap the fontified code.
+\\usepackage[breakable,xparse]{tcolorbox}
+\\DeclareTColorBox[]{Code}{o}%
+{colback=codebackground, colframe=codeborder,
+ fontupper=\\footnotesize\\setlength{\\fboxsep}{0pt},
+ colupper=EFD,
+ IfNoValueTF={#1}%
+ {boxsep=2pt, arc=2.5pt, outer arc=2.5pt,
+ boxrule=0.5pt, left=2pt}%
+ {boxsep=2.5pt, arc=0pt, outer arc=0pt,
+ boxrule=0pt, leftrule=1.5pt, left=0.5pt},
+ right=2pt, top=1pt, bottom=0.5pt,
+ breakable}"
+ "Preamble content injected when using engrave-faces-latex for source blocks.
+This is relevant when `org-latex-listings' is set to `engraved'.
+
+There is quite a lot of flexibility in what this preamble can be, as long as it:
+- Loads the fvextra package.
+- Loads the package xcolor (if it is not already loader elsewhere).
+- Defines a \"Code\" environment (note the capital C), which all
+ \"Verbatim\" environments (provided by fvextra) will be wrapped with.
+
+A macro-like placeholder is used to set fvextra's defaults according to
+`org-latex-engraved-options':
+
+ [FVEXTRA-SETUP]
+
+In the default value the color \"EFD\" is provided as this is the
+foreground colour provided by engrave-faces-latex. When there
+are example/fixed-width blocks only, the engraved generated
+preamble is not included, and so it is provided so we may use it
+anyway."
+ :group 'org-export-latex
+ :type 'string
+ :package-version '(Org . "9.6"))
+
+(defcustom org-latex-engraved-options
+ '(("commandchars" . "\\\\\\{\\}")
+ ("highlightcolor" . "white!95!black!80!blue")
+ ("breaklines" . "true")
+ ("breaksymbol" . "\\color{white!60!black}\\tiny\\ensuremath{\\hookrightarrow}"))
+ "Association list of options for the latex fvextra package when engraving code.
+
+These options are set using \\fvset{...} in the preamble of the
+LaTeX export. Each element of the alist should be a list or cons
+cell containing two strings: the name of the option, and the
+value. For example,
+
+ (setq org-latex-engraved-options
+ \\='((\"highlightcolor\" \"green\") (\"frame\" \"lines\")))
+ ; or
+ (setq org-latex-engraved-options
+ \\='((\"highlightcolor\" . \"green\") (\"frame\" . \"lines\")))
+
+will result in the following LaTeX in the preamble
+
+\\fvset{%
+ bgcolor=bg,
+ frame=lines}
+
+This will affect all fvextra environments. Note that the same
+options will be applied to all blocks. If you need
+block-specific options, you may use the following syntax:
+
+ #+ATTR_LATEX: :options key1=value1,key2=value2
+ #+BEGIN_SRC <LANG>
+ ...
+ #+END_SRC"
+ :group 'org-export-latex
+ :type '(alist :key-type (string :tag "option")
+ :value-type (string :tag "value")))
+
+(defun org-latex-generate-engraved-preamble (info syntax-colours-p)
+ "Generate the preamble to setup engraved code.
+The result is constructed from the :latex-engraved-preamble and
+:latex-engraved-optionsn export options, the default values of
+which are given by `org-latex-engraved-preamble' and
+`org-latex-engraved-options' respectively."
+ (let* ((engraved-options
+ (plist-get info :latex-engraved-options))
+ (engraved-preamble-template
+ (plist-get info :latex-engraved-preamble))
+ (engraved-preamble
+ (if (string-match "^[ \t]*\\[FVEXTRA-SETUP\\][ \t]*\n?"
+ engraved-preamble-template)
+ (replace-match
+ (concat
+ "\\fvset{%\n "
+ (org-latex--make-option-string engraved-options ",\n ")
+ "}\n")
+ t t
+ engraved-preamble-template)
+ engraved-preamble-template)))
+ (if syntax-colours-p
+ (concat
+ "\n% Setup for code blocks [1/2]\n\n"
+ engraved-preamble
+ "\n\n% Setup for code blocks [2/2]: syntax highlighting colors\n"
+ (if (require 'engrave-faces-latex nil t)
+ (engrave-faces-latex-gen-preamble)
+ (message "Cannot engrave source blocks. Consider installing `engrave-faces'.")
+ "% WARNING syntax highlighting unavailible as engrave-faces-latex was missing.\n")
+ "\n")
+ (concat
+ "\n% Setup for code blocks\n\n"
+ engraved-preamble
+ "\n"))))
;;;; Compilation
@@ -1756,6 +1908,17 @@ (defun org-latex-template (contents info)
(let ((template (plist-get info :latex-hyperref-template)))
(and (stringp template)
(format-spec template spec)))
+ ;; engrave-faces-latex preamble
+ (when (eq org-latex-listings 'engraved)
+ (let ((src-p (org-element-map (plist-get info :parse-tree)
+ '(src-block inline-src-block) #'identity
+ info t))
+ (fixedw-p
+ (org-element-map (plist-get info :parse-tree)
+ '(example-block fixed-width) #'identity
+ info t)))
+ (when (or src-p fixedw-p)
+ (org-latex-generate-engraved-preamble info src-p))))
;; Document start.
"\\begin{document}\n\n"
;; Title command.
@@ -2142,6 +2305,7 @@ (defun org-latex-inline-src-block (inline-src-block _contents info)
(pcase (plist-get info :latex-listings)
('nil (org-latex--text-markup code 'code info))
('minted (org-latex-inline-src-block--minted info code lang))
+ ('engraved (org-latex-inline-src-block--engraved info code lang))
(_ (org-latex-inline-src-block--listings info code lang)))))
(defun org-latex-inline-src-block--minted (info code lang)
@@ -2157,6 +2321,24 @@ (defun org-latex-inline-src-block--minted (info code lang)
mint-lang
code)))
+(defun org-latex-inline-src-block--engraved (_info code lang)
+ "Transcode an inline src block's content from Org to LaTeX, using engrave-faces.
+INFO, CODE, and LANG are provided by `org-latex-inline-src-block'."
+ (if (require 'engrave-faces-latex nil t)
+ (let (engraved-buffer engraved-code)
+ (setq engraved-buffer
+ (with-temp-buffer
+ (insert code)
+ (funcall (org-src-get-lang-mode lang))
+ (engrave-faces-latex-buffer)))
+ (setq engraved-code
+ (with-current-buffer engraved-buffer
+ (buffer-string)))
+ (kill-buffer engraved-buffer)
+ (format "\\Verb{%s}"
+ engraved-code))
+ (user-error "Cannot engrave inline src block, `engrave-faces-latex' is unavailible.")))
+
(defun org-latex-inline-src-block--listings (info code lang)
"Transcode an inline src block's content from Org to LaTeX, using lstlistings.
INFO, CODE, and LANG are provided by `org-latex-inline-src-block'."
@@ -3017,6 +3199,9 @@ (defun org-latex-src-block (src-block _contents info)
num-start retain-labels attributes float custom-env))
((eq listings 'minted)
(org-latex-src-block--minted src-block info lang caption caption-above-p label
+ num-start retain-labels attributes float))
+ ((eq listings 'engraved)
+ (org-latex-src-block--engraved src-block info lang caption caption-above-p label
num-start retain-labels attributes float))
(t
(org-latex-src-block--listings src-block info lang caption caption-above-p label
@@ -3133,6 +3318,79 @@ (defun org-latex-src-block--minted
;; Return value.
(format float-env body)))
+(defun org-latex-src-block--engraved
+ (src-block info lang caption caption-above-p _label
+ num-start retain-labels attributes float)
+ "Transcode a SRC-BLOCK element from Org to LaTeX, using engrave-faces-latex.
+LANG, CAPTION, CAPTION-ABOVE-P, LABEL, NUM-START, RETAIN-LABELS, ATTRIBUTES
+and FLOAT are extracted from SRC-BLOCK and INFO in `org-latex-src-block'."
+ (if (require 'engrave-faces-latex nil t)
+ (let* ((caption-str (org-latex--caption/label-string src-block info))
+ (placement (or (org-unbracket-string "[" "]" (plist-get attributes :placement))
+ (plist-get info :latex-default-figure-position)))
+ (float-env
+ (cond
+ ((string= "multicolumn" float)
+ (format "\\begin{listing*}[%s]\n%s%%s\n%s\\end{listing*}"
+ placement
+ (if caption-above-p caption-str "")
+ (if caption-above-p "" caption-str)))
+ (caption
+ (format "\\begin{listing}[%s]\n%s%%s\n%s\\end{listing}"
+ placement
+ (if caption-above-p caption-str "")
+ (if caption-above-p "" caption-str)))
+ ((string= "t" float)
+ (concat (format "\\begin{listing}[%s]\n"
+ placement)
+ "%s\n\\end{listing}"))
+ (t "%s")))
+ (options (plist-get info :latex-engraved-options))
+ (content-buffer
+ (with-temp-buffer
+ (insert
+ (let* ((code-info (org-export-unravel-code src-block))
+ (max-width
+ (apply 'max
+ (mapcar 'length
+ (org-split-string (car code-info)
+ "\n")))))
+ (org-export-format-code
+ (car code-info)
+ (lambda (loc _num ref)
+ (concat
+ loc
+ (when ref
+ ;; Ensure references are flushed to the right,
+ ;; separated with 6 spaces from the widest line
+ ;; of code.
+ (concat (make-string (+ (- max-width (length loc)) 6)
+ ?\s)
+ (format "(%s)" ref)))))
+ nil (and retain-labels (cdr code-info)))))
+ (funcall (org-src-get-lang-mode lang))
+ (engrave-faces-latex-buffer)))
+ (content
+ (with-current-buffer content-buffer
+ (buffer-string)))
+ (body
+ (format
+ "\\begin{Code}\n\\begin{Verbatim}[%s]\n%s\\end{Verbatim}\n\\end{Code}"
+ ;; Options.
+ (concat
+ (org-latex--make-option-string
+ (append
+ (when (and num-start (not (assoc "linenos" options)))
+ `(("linenos")
+ ("firstnumber" ,(number-to-string (1+ num-start)))))
+ (let ((local-options (plist-get attributes :options)))
+ (and local-options (list local-options))))))
+ content)))
+ (kill-buffer content-buffer)
+ ;; Return value.
+ (format float-env body))
+ (user-error "Cannot engrave src block, `engrave-faces-latex' is unavailible.")))
+
(defun org-latex-src-block--listings
(src-block info lang caption caption-above-p label
num-start retain-labels attributes float)
--
2.35.3
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #6: 0005-ox-latex-Don-t-use-length-to-get-string-width.patch --]
[-- Type: text/x-patch, Size: 2005 bytes --]
From 531a8bdd52bc6c9b7ba0da847809c76f14221bb1 Mon Sep 17 00:00:00 2001
From: TEC <tec@tecosaur.com>
Date: Sat, 7 May 2022 13:59:13 +0800
Subject: [PATCH 5/7] ox-latex: Don't use `length' to get string width
* lisp/ox-latex.el (org-latex-src-block--listings,
org-latex-src-block--engraved, org-latex-src-block--minted): Use
`string-width' instead of `length' to gauge the displayed width of the
string in LaTeX. This may not be a perfect match, but it should be an
improvement.
---
lisp/ox-latex.el | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/lisp/ox-latex.el b/lisp/ox-latex.el
index b9c6d4c3e..6a794c41c 100644
--- a/lisp/ox-latex.el
+++ b/lisp/ox-latex.el
@@ -3299,7 +3299,7 @@ (defun org-latex-src-block--minted
(let* ((code-info (org-export-unravel-code src-block))
(max-width
(apply 'max
- (mapcar 'length
+ (mapcar 'string-width
(org-split-string (car code-info)
"\n")))))
(org-export-format-code
@@ -3352,7 +3352,7 @@ (defun org-latex-src-block--engraved
(let* ((code-info (org-export-unravel-code src-block))
(max-width
(apply 'max
- (mapcar 'length
+ (mapcar 'string-width
(org-split-string (car code-info)
"\n")))))
(org-export-format-code
@@ -3442,7 +3442,7 @@ (defun org-latex-src-block--listings
(let* ((code-info (org-export-unravel-code src-block))
(max-width
(apply 'max
- (mapcar 'length
+ (mapcar 'string-width
(org-split-string (car code-info) "\n")))))
(org-export-format-code
(car code-info)
--
2.35.3
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #7: 0006-ox-latex-Refactor-source-block-transcode-fun-sigs.patch --]
[-- Type: text/x-patch, Size: 7091 bytes --]
From 1961039336917e6f4e3698aadccc03444dfc2592 Mon Sep 17 00:00:00 2001
From: TEC <tec@tecosaur.com>
Date: Sat, 7 May 2022 14:02:44 +0800
Subject: [PATCH 6/7] ox-latex: Refactor source block transcode fun sigs
* lisp/ox-latex.el (org-latex-src-block--listings,
org-latex-src-block--engraved, org-latex-src-block--minted,
org-latex-src-block--custom): Refactor these --backend functions to use
cl-defun with keys instead of having an 11-argument signature.
(org-latex-src-block): Adjust for the change in signature of the
--backend functions, and refactor the `cond' statement to use `pcase'.
---
lisp/ox-latex.el | 78 +++++++++++++++++++++++-------------------------
1 file changed, 37 insertions(+), 41 deletions(-)
diff --git a/lisp/ox-latex.el b/lisp/ox-latex.el
index 6a794c41c..685899c7d 100644
--- a/lisp/ox-latex.el
+++ b/lisp/ox-latex.el
@@ -3179,37 +3179,37 @@ (defun org-latex-src-block (src-block _contents info)
contextual information."
(when (org-string-nw-p (org-element-property :value src-block))
(let* ((lang (org-element-property :language src-block))
- (caption (org-element-property :caption src-block))
- (caption-above-p (org-latex--caption-above-p src-block info))
- (label (org-element-property :name src-block))
- (custom-env (and lang
- (cadr (assq (intern lang)
- org-latex-custom-lang-environments))))
- (num-start (org-export-get-loc src-block info))
- (retain-labels (org-element-property :retain-labels src-block))
- (attributes (org-export-read-attribute :attr_latex src-block))
- (float (plist-get attributes :float))
- (listings (plist-get info :latex-listings)))
- (cond
- ((or (not lang) (not listings))
- (org-latex-src-block--verbatim src-block info lang caption caption-above-p label
- num-start retain-labels attributes float))
- (custom-env
- (org-latex-src-block--custom src-block info lang caption caption-above-p label
- num-start retain-labels attributes float custom-env))
- ((eq listings 'minted)
- (org-latex-src-block--minted src-block info lang caption caption-above-p label
- num-start retain-labels attributes float))
- ((eq listings 'engraved)
- (org-latex-src-block--engraved src-block info lang caption caption-above-p label
- num-start retain-labels attributes float))
- (t
- (org-latex-src-block--listings src-block info lang caption caption-above-p label
- num-start retain-labels attributes float))))))
-
-(defun org-latex-src-block--verbatim
- (src-block info _lang caption caption-above-p _label
- _num-start _retain-labels _attributes float)
+ (caption (org-element-property :caption src-block))
+ (caption-above-p (org-latex--caption-above-p src-block info))
+ (label (org-element-property :name src-block))
+ (custom-env (and lang
+ (cadr (assq (intern lang)
+ org-latex-custom-lang-environments))))
+ (num-start (org-export-get-loc src-block info))
+ (retain-labels (org-element-property :retain-labels src-block))
+ (attributes (org-export-read-attribute :attr_latex src-block))
+ (float (plist-get attributes :float))
+ (listings (plist-get info :latex-listings)))
+ (funcall
+ (pcase listings
+ ((or (pred not) (guard (not lang))) #'org-latex-src-block--verbatim
+ ((guard custom-env) #'org-latex-src-block--custom)
+ ('minted #'org-latex-src-block--minted)
+ ('engraved #'org-latex-src-block--engraved)
+ (_ #'org-latex-src-block--listings)))
+ :src-block src-block
+ :info info
+ :lang lang
+ :caption caption
+ :caption-above-p caption-above-p
+ :label label
+ :num-start num-start
+ :retain-labels retain-labels
+ :attributes attributes
+ :float float))))
+
+(cl-defun org-latex-src-block--verbatim
+ (&key src-block info caption caption-above-p float &allow-other-keys)
"Transcode a SRC-BLOCK element from Org to LaTeX, using verbatim.
LANG, CAPTION, CAPTION-ABOVE-P, LABEL, NUM-START, RETAIN-LABELS, ATTRIBUTES
and FLOAT are extracted from SRC-BLOCK and INFO in `org-latex-src-block'."
@@ -3228,9 +3228,8 @@ (defun org-latex-src-block--verbatim
(if caption-above-p "" (concat "\n" caption-str))))
(t verbatim))))
-(defun org-latex-src-block--custom
- (src-block info _lang caption caption-above-p _label
- _num-start _retain-labels attributes float custom-env)
+(cl-defun org-latex-src-block--custom
+ (&key src-block info caption caption-above-p attributes float custom-env &allow-other-keys)
"Transcode a SRC-BLOCK element from Org to LaTeX, using a custom environment.
LANG, CAPTION, CAPTION-ABOVE-P, LABEL, NUM-START, RETAIN-LABELS, ATTRIBUTES
and FLOAT are extracted from SRC-BLOCK and INFO in `org-latex-src-block'."
@@ -3251,8 +3250,7 @@ (defun org-latex-src-block--custom
(?o . ,(or (plist-get attributes :options) "")))))))
(defun org-latex-src-block--minted
- (src-block info lang caption caption-above-p _label
- num-start retain-labels attributes float)
+ (&key src-block info lang caption caption-above-p num-start retain-labels attributes float &allow-other-keys)
"Transcode a SRC-BLOCK element from Org to LaTeX, using minted.
LANG, CAPTION, CAPTION-ABOVE-P, LABEL, NUM-START, RETAIN-LABELS, ATTRIBUTES
and FLOAT are extracted from SRC-BLOCK and INFO in `org-latex-src-block'."
@@ -3319,8 +3317,7 @@ (defun org-latex-src-block--minted
(format float-env body)))
(defun org-latex-src-block--engraved
- (src-block info lang caption caption-above-p _label
- num-start retain-labels attributes float)
+ (&key src-block info lang caption caption-above-p num-start retain-labels attributes float &allow-other-keys)
"Transcode a SRC-BLOCK element from Org to LaTeX, using engrave-faces-latex.
LANG, CAPTION, CAPTION-ABOVE-P, LABEL, NUM-START, RETAIN-LABELS, ATTRIBUTES
and FLOAT are extracted from SRC-BLOCK and INFO in `org-latex-src-block'."
@@ -3391,9 +3388,8 @@ (defun org-latex-src-block--engraved
(format float-env body))
(user-error "Cannot engrave src block, `engrave-faces-latex' is unavailible.")))
-(defun org-latex-src-block--listings
- (src-block info lang caption caption-above-p label
- num-start retain-labels attributes float)
+(cl-defun org-latex-src-block--listings
+ (&key src-block info lang caption caption-above-p label num-start retain-labels attributes float &allow-other-keys)
"Transcode a SRC-BLOCK element from Org to LaTeX, using listings.
LANG, CAPTION, CAPTION-ABOVE-P, LABEL, NUM-START, RETAIN-LABELS, ATTRIBUTES
and FLOAT are extracted from SRC-BLOCK and INFO in `org-latex-src-block'."
--
2.35.3
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #8: 0007-ox-latex-Replace-org-latex-listings.patch --]
[-- Type: text/x-patch, Size: 16140 bytes --]
From 4d24b74e5490a30c75c7a23721c836a8ce4756b6 Mon Sep 17 00:00:00 2001
From: TEC <tec@tecosaur.com>
Date: Sat, 7 May 2022 14:46:28 +0800
Subject: [PATCH 7/7] ox-latex: Replace `org-latex-listings'
* lisp/ox-latex.el (org-latex-src-block, org-latex-keyword,
org-latex-inline-src-block, org-latex-template,
org-latex--caption/label-string, org-latex-engraved-preamble,
org-latex-listings): Replace `org-latex-listings' with
`org-latex-src-block-backend', which now can be set to listings/verbatim
and no longer advertises t/nil as valid values.
* lisp/ox-beamer.el (org-beamer-template): Update in the same manner as
`org-latex-template'.
* lisp/org-compat.el: Make `org-latex-listings' an obsolete alias for
`org-latex-src-block-backend'.
* testing/lisp/test-ox.el: Replace `org-latex-listings' reference with
`org-latex-src-block-backend'.
* doc/org-manual.org (Footnotes, LaTeX specific properties, Literal
Examples): Replace references to `org-latex-listings' with
`org-latex-src-block-backend'.
* etc/ORG-NEWS: Add a news entry noting this change.
The variable `org-latex-listings' originally indicated whether source
blocks should use the listings LaTeX package, or not. This usage has
evolved over the years, and now it sets one of four different
fontification backends. This renaming should make the variable name a
bit less misleading.
---
doc/org-manual.org | 6 +--
etc/ORG-NEWS | 9 ++++
lisp/org-compat.el | 2 +
lisp/ox-beamer.el | 2 +-
lisp/ox-latex.el | 111 ++++++++++++++++++++++------------------
testing/lisp/test-ox.el | 2 +-
6 files changed, 78 insertions(+), 54 deletions(-)
diff --git a/doc/org-manual.org b/doc/org-manual.org
index c0d38cd8c..60bded419 100644
--- a/doc/org-manual.org
+++ b/doc/org-manual.org
@@ -11159,7 +11159,7 @@ ** Literal Examples
#+end_example
#+cindex: formatting source code, markup rules
-#+vindex: org-latex-listings
+#+vindex: org-latex-src-block-backend
If the example is source code from a programming language, or any
other text that can be marked up by Font Lock in Emacs, you can ask
for the example to look like the fontified Emacs buffer[fn:114]. This
@@ -16304,12 +16304,12 @@ **** LaTeX specific properties
| ~:latex-link-with-unknown-path-format~ | ~org-latex-link-with-unknown-path-format~ |
| ~:latex-listings-langs~ | ~org-latex-listings-langs~ |
| ~:latex-listings-options~ | ~org-latex-listings-options~ |
-| ~:latex-listings~ | ~org-latex-listings~ |
| ~:latex-minted-langs~ | ~org-latex-minted-langs~ |
| ~:latex-minted-options~ | ~org-latex-minted-options~ |
| ~:latex-prefer-user-labels~ | ~org-latex-prefer-user-labels~ |
| ~:latex-subtitle-format~ | ~org-latex-subtitle-format~ |
| ~:latex-subtitle-separate~ | ~org-latex-subtitle-separate~ |
+| ~:latex-src-block-backend~ | ~org-latex-src-block-backend~ |
| ~:latex-table-scientific-notation~ | ~org-latex-table-scientific-notation~ |
| ~:latex-tables-booktabs~ | ~org-latex-tables-booktabs~ |
| ~:latex-tables-centered~ | ~org-latex-tables-centered~ |
@@ -22256,7 +22256,7 @@ * Footnotes
version 1.34 of the =htmlize.el= package, which you need to install).
Fontified code chunks in LaTeX can be achieved using either the
[[https://www.ctan.org/pkg/listings][listings]] package or the [[https://www.ctan.org/pkg/minted][minted]] package. Refer to
-~org-latex-listings~ for details.
+~org-latex-src-block-backend~ for details.
[fn:115] Source code in code blocks may also be evaluated either
interactively or on export. See [[*Working with Source Code]] for more
diff --git a/etc/ORG-NEWS b/etc/ORG-NEWS
index 1e8558c7b..c5f0bcb33 100644
--- a/etc/ORG-NEWS
+++ b/etc/ORG-NEWS
@@ -268,6 +268,15 @@ Chmod-style permissions are based on the new variable
~org-babel-tangle-default-file-mode~.
*** A new custom setting =org-agenda-clock-report-header= to add a header to org agenda clock report
+
+*** ~org-latex-listings~ has been replaced with ~org-latex-src-block-backend~
+
+~org-latex-listings~ has been renamed to better reflect the current
+purpose of the variable. The replacement variable
+~org-latex-src-block-backend~ acts in exactly the same way, however it
+accepts =listings= and =verbatim= in place of =t= and =nil= (which
+still work, but are no longer listed as valid options).
+
* Version 9.5
** Important announcements and breaking changes
diff --git a/lisp/org-compat.el b/lisp/org-compat.el
index f599e246e..c1a78e834 100644
--- a/lisp/org-compat.el
+++ b/lisp/org-compat.el
@@ -324,6 +324,8 @@ (define-obsolete-variable-alias 'org-latex-create-formula-image-program
'org-preview-latex-default-process "9.0")
(define-obsolete-variable-alias 'org-latex-preview-ltxpng-directory
'org-preview-latex-image-directory "9.0")
+(define-obsolete-variable-alias 'org-latex-listings
+ 'org-latex-src-block-backend "9.6")
(define-obsolete-function-alias 'org-table-p 'org-at-table-p "9.0")
(define-obsolete-function-alias 'org-on-heading-p 'org-at-heading-p "9.0")
(define-obsolete-function-alias 'org-at-regexp-p 'org-in-regexp "8.3")
diff --git a/lisp/ox-beamer.el b/lisp/ox-beamer.el
index 4d40f6a1d..3baa4e26e 100644
--- a/lisp/ox-beamer.el
+++ b/lisp/ox-beamer.el
@@ -858,7 +858,7 @@ (defun org-beamer-template (contents info)
(and (stringp template)
(format-spec template (org-latex--format-spec info))))
;; engrave-faces-latex preamble
- (when (eq org-latex-listings 'engraved)
+ (when (eq org-latex-src-block-backend 'engraved)
(let ((src-p (org-element-map (plist-get info :parse-tree)
'(src-block inline-src-block) #'identity
info t))
diff --git a/lisp/ox-latex.el b/lisp/ox-latex.el
index 685899c7d..8f4206164 100644
--- a/lisp/ox-latex.el
+++ b/lisp/ox-latex.el
@@ -143,7 +143,7 @@ (org-export-define-backend 'latex
(:latex-inactive-timestamp-format nil nil org-latex-inactive-timestamp-format)
(:latex-inline-image-rules nil nil org-latex-inline-image-rules)
(:latex-link-with-unknown-path-format nil nil org-latex-link-with-unknown-path-format)
- (:latex-listings nil nil org-latex-listings)
+ (:latex-src-block-backend nil nil org-latex-src-block-backend)
(:latex-listings-langs nil nil org-latex-listings-langs)
(:latex-listings-options nil nil org-latex-listings-options)
(:latex-minted-langs nil nil org-latex-minted-langs)
@@ -937,22 +937,22 @@ (defcustom org-latex-format-inlinetask-function
;; Src blocks
-(defcustom org-latex-listings nil
- "Non-nil means export source code using the listings package.
+(defcustom org-latex-src-block-backend 'verbatim
+ "Backend used to generate source code listings.
-This package will fontify source code, possibly even with color.
-There are four implementations of this functionality you may
+This sets the behaviour for fontifying source code, possibly even with
+color. There are four implementations of this functionality you may
choose from (ordered from least to most capable):
-1. Verbatim (nil)
-2. Listings (t)
-3. Minted (minted)
-4. Engraved (engraved)
+1. Verbatim
+2. Listings
+3. Minted
+4. Engraved
The first two options provide basic syntax
highlighting (listings), or none at all (verbatim).
-When using listings, you also need to make use of the LaTeX
-\"listings\" package. The \"color\" package is also needed if you
+When using listings, you also need to make use of LaTeX package
+\"listings\"e. The \"color\" LaTeX package is also needed if you
would like color too. These can simply be added to
`org-latex-packages-alist', using customise or something like:
@@ -963,27 +963,12 @@ (defcustom org-latex-listings nil
There are two further options for more comprehensive
fontification. The first can be set with,
- (setq org-latex-listings \\='engraved)
+ (setq org-latex-src-block-backend \\='minted)
-which causes source code to be run through
-`engrave-faces-latex-buffer', which generates colorings using
-Emacs' font-lock information. This requires the engrave-faces
-package (availible from ELPA), and the fvextra LaTeX package be
-installed.
-
-The styling of the engraved result can customised with
-`org-latex-engraved-preamble' and `org-latex-engraved-options'.
-The default preamble also uses the tcolorbox LaTeX package in
-addition to fvextra.
-
-The second more comprehensive option can be set with,
-
- (setq org-latex-listings \\='minted)
-
-which causes source code to be exported using the minted package
-as opposed to listings. If you want to use minted, you need to
-add the minted package to `org-latex-packages-alist', for example
-using customize, or with
+which causes source code to be exported using the LaTeX package
+minted as opposed to listings. If you want to use minted, you
+need to add the minted package to `org-latex-packages-alist', for
+example using customize, or with
(require \\='ox-latex)
(add-to-list \\='org-latex-packages-alist \\='(\"newfloat\" \"minted\"))
@@ -996,14 +981,29 @@ (defcustom org-latex-listings nil
The minted choice has possible repercussions on the preview of
latex fragments (see `org-preview-latex-fragment'). If you run
into previewing problems, please consult
-URL `https://orgmode.org/worg/org-tutorials/org-latex-preview.html'."
+URL `https://orgmode.org/worg/org-tutorials/org-latex-preview.html'.
+
+The most comprehensive option can be set with,
+
+ (setq org-latex-src-block-backend \\='engraved)
+
+which causes source code to be run through
+`engrave-faces-latex-buffer', which generates colorings using
+Emacs' font-lock information. This requires the Emacs package
+engrave-faces (availible from ELPA), and the LaTeX package
+fvextra be installed.
+
+The styling of the engraved result can customised with
+`org-latex-engraved-preamble' and `org-latex-engraved-options'.
+The default preamble also uses the LaTeX package tcolorbox in
+addition to fvextra."
:group 'org-export-latex
:type '(choice
- (const :tag "Use listings" t)
+ (const :tag "Use listings" listings)
(const :tag "Use minted" minted)
(const :tag "Use engrave-faces-latex" engraved)
- (const :tag "Export verbatim" nil))
- :safe (lambda (s) (memq s '(t nil minted engraved))))
+ (const :tag "Export verbatim" verbatim))
+ :safe (lambda (s) (memq s '(listings minted engraved verbatim))))
(defcustom org-latex-listings-langs
'((emacs-lisp "Lisp") (lisp "Lisp") (clojure "Lisp")
@@ -1201,7 +1201,7 @@ (defcustom org-latex-engraved-preamble
right=2pt, top=1pt, bottom=0.5pt,
breakable}"
"Preamble content injected when using engrave-faces-latex for source blocks.
-This is relevant when `org-latex-listings' is set to `engraved'.
+This is relevant when `org-latex-src-block-backend' is set to `engraved'.
There is quite a lot of flexibility in what this preamble can be, as long as it:
- Loads the fvextra package.
@@ -1502,7 +1502,8 @@ (defun org-latex--caption/label-string (element info)
main)
(and (eq type 'src-block)
(not (plist-get attr :float))
- (null (plist-get info :latex-listings)))))
+ (memq (plist-get info :latex-src-block-backend)
+ '(verbatim nil)))))
(short (org-export-get-caption element t))
(caption-from-attr-latex (plist-get attr :caption)))
(cond
@@ -1522,7 +1523,8 @@ (defun org-latex--caption/label-string (element info)
(paragraph "figure")
(image "figure")
(special-block "figure")
- (src-block (if (plist-get info :latex-listings)
+ (src-block (if (not (memq (plist-get info :latex-src-block-backend)
+ '(verbatim nil)))
"listing"
"figure"))
(t (symbol-name type*)))
@@ -1909,7 +1911,7 @@ (defun org-latex-template (contents info)
(and (stringp template)
(format-spec template spec)))
;; engrave-faces-latex preamble
- (when (eq org-latex-listings 'engraved)
+ (when (eq org-latex-src-block-backend 'engraved)
(let ((src-p (org-element-map (plist-get info :parse-tree)
'(src-block inline-src-block) #'identity
info t))
@@ -2302,11 +2304,17 @@ (defun org-latex-inline-src-block (inline-src-block _contents info)
contextual information."
(let ((code (org-element-property :value inline-src-block))
(lang (org-element-property :language inline-src-block)))
- (pcase (plist-get info :latex-listings)
- ('nil (org-latex--text-markup code 'code info))
+ (pcase (plist-get info :latex-src-block-backend)
+ ('verbatim (org-latex--text-markup code 'code info))
('minted (org-latex-inline-src-block--minted info code lang))
('engraved (org-latex-inline-src-block--engraved info code lang))
- (_ (org-latex-inline-src-block--listings info code lang)))))
+ ('listings (org-latex-inline-src-block--listings info code lang))
+ (oldval
+ (message "Please update the LaTeX src-block-backend to %s"
+ (if oldval "listings" "verbatim"))
+ (if oldval
+ (org-latex-inline-src-block--listings info code lang)
+ (org-latex--text-markup code 'code info))))))
(defun org-latex-inline-src-block--minted (info code lang)
"Transcode an inline src block's content from Org to LaTeX, using minted.
@@ -2502,7 +2510,7 @@ (defun org-latex-keyword (keyword _contents info)
(concat depth (and depth "\n") "\\tableofcontents"))))
((string-match-p "\\<tables\\>" value) "\\listoftables")
((string-match-p "\\<listings\\>" value)
- (cl-case (plist-get info :latex-listings)
+ (cl-case (plist-get info :latex-src-block-backend)
((nil) "\\listoffigures")
(minted "\\listoflistings")
(otherwise "\\lstlistoflistings")))))))))
@@ -3188,15 +3196,20 @@ (defun org-latex-src-block (src-block _contents info)
(num-start (org-export-get-loc src-block info))
(retain-labels (org-element-property :retain-labels src-block))
(attributes (org-export-read-attribute :attr_latex src-block))
- (float (plist-get attributes :float))
- (listings (plist-get info :latex-listings)))
+ (float (plist-get attributes :float)))
(funcall
- (pcase listings
- ((or (pred not) (guard (not lang))) #'org-latex-src-block--verbatim
- ((guard custom-env) #'org-latex-src-block--custom)
+ (pcase (plist-get info :latex-src-block-backend)
+ ((or 'verbatim (guard (not lang))) #'org-latex-src-block--verbatim
('minted #'org-latex-src-block--minted)
('engraved #'org-latex-src-block--engraved)
- (_ #'org-latex-src-block--listings)))
+ ('listings #'org-latex-src-block--listings)
+ ((guard custom-env) #'org-latex-src-block--custom)
+ (oldval
+ (message "Please update the LaTeX src-block-backend to %s"
+ (if oldval "listings" "verbatim"))
+ (if oldval
+ #'org-latex-src-block--listings
+ #'org-latex-src-block--verbatim))))
:src-block src-block
:info info
:lang lang
diff --git a/testing/lisp/test-ox.el b/testing/lisp/test-ox.el
index 25e02b258..28f950813 100644
--- a/testing/lisp/test-ox.el
+++ b/testing/lisp/test-ox.el
@@ -3978,7 +3978,7 @@ (ert-deftest test-org-export/latex-src-block-verbatim-caption ()
\\end{verbatim}
\\caption{Caption is below, 60\\%s}
\\end{figure*}"
- (let ((org-latex-listings 'minted) ; inactive due to missing lang
+ (let ((org-latex-src-block-backend 'minted) ; inactive due to missing lang
(org-latex-default-figure-position "tp"))
;; Namely "multicolumn" value to get just figure environment
;; looks like a bug.
--
2.35.3
^ permalink raw reply related [relevance 7%]
* Re: [PATCH] New LaTeX code export option: engraved
@ 2022-05-06 11:23 86% ` Timothy
0 siblings, 0 replies; 200+ results
From: Timothy @ 2022-05-06 11:23 UTC (permalink / raw)
To: Ihor Radchenko; +Cc: Daniel Fleischer, emacs-orgmode, Nicolas Goaziou
[-- Attachment #1: Type: text/plain, Size: 1407 bytes --]
Hi Ihor,
>> Sure. If it’s any help, here’s a comparison example I whipped up:
>> <https://0x0.st/oAdn.png>
>
> Timothy, could you please not use 0x0 to share not-so-large images? 0x0
> deletes uploaded files within ~1year time and this link will no longer
> be valid if someone tries to read this discussion years later.
I forget if org-msg handles image links well (I recall some issue in the past).
Let’s do a little test:
<file:/tmp/ox-latex-src-fontification-comparison.png>
> Also, this illustration makes me wonder if engrave-faces can provide a
> color scheme that is mimicking minted.
One could certainly create `engrave-faces-preset-styles' presets which mimic
certain minted colour schemes.
> Generally, easy customisation of highlight schemes could be useful.
I agree. Is this not already the case though? Manually modifying
`engrave-faces-preset-styles' or calling `engrave-faces-generate-preset' seems
pretty easy to me, the only thing missing is the ability to generate a preset
from a theme not loaded, which I suspect won’t be easy to do.
> On per-src-block basis or even on per-language basis if document contains
> course blocks with different programming languages.
I can’t say I really see the point in this myself. It would certainly be
non-trivial to add, but could be added latter if there’s demand for it.
All the best,
Timothy
[-- Attachment #2: ox-latex-src-fontification-comparison.png --]
[-- Type: image/png, Size: 476505 bytes --]
^ permalink raw reply [relevance 86%]
* Re: [PATCH] New LaTeX code export option: engraved
2022-05-05 15:17 12% ` Timothy
@ 2022-05-05 16:13 25% ` Timothy
0 siblings, 1 reply; 200+ results
From: Timothy @ 2022-05-05 16:13 UTC (permalink / raw)
To: Ihor Radchenko; +Cc: emacs-orgmode, Daniel Fleischer, Nicolas Goaziou
[-- Attachment #1: Type: text/plain, Size: 166 bytes --]
> [5. text/x-patch; 0004-ox-latex-Introduce-engraved-code-highlighting.patch]…
Ooops, I had some ucommited changes. The correct version is attached.
Timothy
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-ox-latex-Introduce-engraved-code-highlighting.patch --]
[-- Type: text/x-patch, Size: 17470 bytes --]
From b66c291b1f0d1419742449bcde42bf0c4d620c23 Mon Sep 17 00:00:00 2001
From: TEC <tec@tecosaur.com>
Date: Sun, 21 Nov 2021 20:04:12 +0800
Subject: [PATCH] ox-latex: Introduce "engraved" code highlighting
* lisp/ox-latex.el (org-latex-src-block, org-latex-src-block--engraved,
org-latex-inline-src-block, org-latex-inline-src-block--engraved,
org-latex-template, org-latex-listings): Make use of the engraved-faces
package (available on ELPA) to provide an alternative LaTeX code
highlighting backend which functions similarly to htmlize.el for HTML
exports.
(org-latex-engraved-preamble, org-latex-engraved-options): Introduce
variables to construct the preamble for engraved code blocks.
* lisp/ox-beamer.el (org-beamer-template): Modify to add engrave-faces
preamble when applicable.
---
lisp/ox-beamer.el | 9 ++
lisp/ox-latex.el | 273 ++++++++++++++++++++++++++++++++++++++++++++--
2 files changed, 272 insertions(+), 10 deletions(-)
diff --git a/lisp/ox-beamer.el b/lisp/ox-beamer.el
index 6be73c91e..73bd95539 100644
--- a/lisp/ox-beamer.el
+++ b/lisp/ox-beamer.el
@@ -857,6 +857,15 @@ (defun org-beamer-template (contents info)
(let ((template (plist-get info :latex-hyperref-template)))
(and (stringp template)
(format-spec template (org-latex--format-spec info))))
+ ;; engrave-faces-latex preamble
+ (when (eq org-latex-listings 'engraved)
+ (let ((src-p (org-element-map (plist-get info :parse-tree)
+ '(src-block inline-src-block) #'identity))
+ (fixedw-p
+ (org-element-map (plist-get info :parse-tree)
+ '(example-block fixed-width) #'identity)))
+ (when (or src-p fixedw-p)
+ (org-latex-generate-engraved-preamble info src-p))))
;; Document start.
"\\begin{document}\n\n"
;; Title command.
diff --git a/lisp/ox-latex.el b/lisp/ox-latex.el
index 4181db175..83bb6f078 100644
--- a/lisp/ox-latex.el
+++ b/lisp/ox-latex.el
@@ -37,6 +37,8 @@ (defvar org-latex-default-packages-alist)
(defvar org-latex-packages-alist)
(defvar orgtbl-exp-regexp)
+(declare-function engrave-faces-latex-gen-preamble "ext:engrave-faces-latex")
+(declare-function engrave-faces-latex-buffer "ext:engrave-faces-latex")
\f
;;; Define Back-End
@@ -125,6 +127,8 @@ (org-export-define-backend 'latex
(:latex-default-quote-environment nil nil org-latex-default-quote-environment)
(:latex-default-table-mode nil nil org-latex-default-table-mode)
(:latex-diary-timestamp-format nil nil org-latex-diary-timestamp-format)
+ (:latex-engraved-options nil nil org-latex-engraved-options)
+ (:latex-engraved-preamble nil nil org-latex-engraved-preamble)
(:latex-footnote-defined-format nil nil org-latex-footnote-defined-format)
(:latex-footnote-separator nil nil org-latex-footnote-separator)
(:latex-format-drawer-function nil nil org-latex-format-drawer-function)
@@ -937,22 +941,48 @@ (defcustom org-latex-listings nil
"Non-nil means export source code using the listings package.
This package will fontify source code, possibly even with color.
-If you want to use this, you also need to make LaTeX use the
-listings package, and if you want to have color, the color
-package. Just add these to `org-latex-packages-alist', for
-example using customize, or with something like:
+There are four implementations of this functionality you may
+choose from (ordered from least to most capable):
+1. Verbatim (nil)
+2. Listings (t)
+3. Minted (minted)
+4. Engraved (engraved)
+
+The first two options provide basic syntax
+highlighting (listings), or none at all (verbatim).
+
+When using listings, you also need to make use of the LaTeX
+\"listings\" package. The \"color\" package is also needed if you
+would like color too. These can simply be added to
+`org-latex-packages-alist', using customise or something like:
(require \\='ox-latex)
(add-to-list \\='org-latex-packages-alist \\='(\"\" \"listings\"))
(add-to-list \\='org-latex-packages-alist \\='(\"\" \"color\"))
-Alternatively,
+There are two options for more comprehensive fontification. The
+first can be set with,
+
+ (setq org-latex-listings \\='engraved)
+
+which causes source code to be run through
+`engrave-faces-latex-buffer', which generates colorings using
+Emacs' font-lock information. This requires the engrave-faces
+package (availible from ELPA), and the fvextra LaTeX package be
+installed.
+
+The styling of the engraved result can customised with
+`org-latex-engraved-preamble' and `org-latex-engraved-options'.
+The default preamble also uses the tcolorbox LaTeX package in
+addition to fvextra.
+
+The second more comprehensive option can be used with,
(setq org-latex-listings \\='minted)
-causes source code to be exported using the minted package as
-opposed to listings. If you want to use minted, you need to add
-the minted package to `org-latex-packages-alist', for example
+which causes source code to be exported using the minted package
+as opposed to listings. If you want to use minted, you need to
+add the minted package to `org-latex-packages-alist', for example
using customize, or with
(require \\='ox-latex)
@@ -971,8 +1001,9 @@ (defcustom org-latex-listings nil
:type '(choice
(const :tag "Use listings" t)
(const :tag "Use minted" minted)
+ (const :tag "Use engrave-faces-latex" engraved)
(const :tag "Export verbatim" nil))
- :safe (lambda (s) (memq s '(t nil minted))))
+ :safe (lambda (s) (memq s '(t nil minted engraved))))
(defcustom org-latex-listings-langs
'((emacs-lisp "Lisp") (lisp "Lisp") (clojure "Lisp")
@@ -1142,6 +1173,124 @@ (defcustom org-latex-custom-lang-environments nil
:version "26.1"
:package-version '(Org . "9.0"))
+(defcustom org-latex-engraved-preamble
+ "\\usepackage{fvextra}
+
+[FVEXTRA-SETUP]
+
+\\renewcommand\\theFancyVerbLine{\\footnotesize\\color{black!40!white}\\arabic{FancyVerbLine}}
+
+\\usepackage{xcolor}
+
+\\providecolor{codebackground}{HTML}{f7f7f7}
+\\providecolor{codeborder}{HTML}{f0f0f0}
+\\providecolor{EFD}{HTML}{28292e}
+
+% TODO have code boxes keep line vertical alignment
+\\usepackage[breakable,xparse]{tcolorbox}
+\\DeclareTColorBox[]{Code}{o}%
+{colback=codebackground, colframe=codeborder,
+ fontupper=\\footnotesize\\setlength{\\fboxsep}{0pt},
+ colupper=EFD,
+ IfNoValueTF={#1}%
+ {boxsep=2pt, arc=2.5pt, outer arc=2.5pt,
+ boxrule=0.5pt, left=2pt}%
+ {boxsep=2.5pt, arc=0pt, outer arc=0pt,
+ boxrule=0pt, leftrule=1.5pt, left=0.5pt},
+ right=2pt, top=1pt, bottom=0.5pt,
+ breakable}"
+ "Preamble content injected when using engrave-faces-latex for source blocks.
+This is relevant when `org-latex-listings' is set to `engraved'.
+
+There is quite a lot of flexibility in what this preamble can be, as long as it:
+- Loads the fvextra package.
+- Loads the package xcolor (if it is not already loader elsewhere).
+- Defines a \"Code\" environment (note the capital C), which can be
+ later used to wrap \"Verbatim\" environments (provided by fvextra).
+
+A macro-like placeholder is used to set fvextra's defaults according to
+`org-latex-engraved-options':
+
+ [FVEXTRA-SETUP]
+
+In the default value the color \"EFD\" is provided as this is the
+foreground colour provided by engrave-faces-latex. When there
+are example/fixed-width blocks only, the engraved generated
+preamble is not included, and so it is provided so we may use it
+anyway."
+ :group 'org-export-latex
+ :type 'string
+ :package-version '(Org . "9.6"))
+
+(defcustom org-latex-engraved-options
+ '(("commandchars" . "\\\\\\{\\}")
+ ("highlightcolor" . "white!95!black!80!blue")
+ ("breaklines" . "true")
+ ("breaksymbol" . "\\color{white!60!black}\\tiny\\ensuremath{\\hookrightarrow}"))
+ "Association list of options for the latex fvextra package when engraving code.
+
+These options are set using \\fvset{...} in the preamble of the
+LaTeX export. Each element of the alist should be a list or cons
+cell containing two strings: the name of the option, and the
+value. For example,
+
+ (setq org-latex-engraved-options
+ \\='((\"highlightcolor\" \"green\") (\"frame\" \"lines\")))
+ ; or
+ (setq org-latex-engraved-options
+ \\='((\"highlightcolor\" . \"green\") (\"frame\" . \"lines\")))
+
+will result in the following LaTeX in the preamble
+
+\\fvset{%
+ bgcolor=bg,
+ frame=lines}
+
+This will affect all fvextra environments. Note that the same
+options will be applied to all blocks. If you need
+block-specific options, you may use the following syntax:
+
+ #+ATTR_LATEX: :options key1=value1,key2=value2
+ #+BEGIN_SRC <LANG>
+ ...
+ #+END_SRC"
+ :group 'org-export-latex
+ :type '(alist :key-type (string :tag "option")
+ :value-type (string :tag "value")))
+
+(defun org-latex-generate-engraved-preamble (info syntax-colours-p)
+ "Generate the preamble to setup engraved code.
+The result is constructed from `org-latex-engraved-preamble' and
+`org-latex-engraved-options'."
+ (let* ((engraved-options
+ (plist-get info :latex-engraved-options))
+ (engraved-preamble-template
+ (plist-get info :latex-engraved-preamble))
+ (engraved-preamble
+ (if (string-match "^[ \t]*\\[FVEXTRA-SETUP\\][ \t]*\n?"
+ engraved-preamble-template)
+ (replace-match
+ (concat
+ "\\fvset{%\n "
+ (org-latex--make-option-string engraved-options ",\n ")
+ "}\n")
+ t t
+ engraved-preamble-template)
+ engraved-preamble-template)))
+ (if syntax-colours-p
+ (concat
+ "\n% Setup for code blocks [1/2]\n\n"
+ engraved-preamble
+ "\n\n% Setup for code blocks [2/2]: syntax highlighting colors\n"
+ (if (require 'engrave-faces-latex nil t)
+ (engrave-faces-latex-gen-preamble)
+ (message "Cannot engrave source blocks. Consider installing `engrave-faces'.")
+ "% WARNING syntax highlighting unavailible as engrave-faces-latex was missing.\n")
+ "\n")
+ (concat
+ "\n% Setup for code blocks\n\n"
+ engraved-preamble
+ "\n"))))
;;;; Compilation
@@ -1756,6 +1905,15 @@ (defun org-latex-template (contents info)
(let ((template (plist-get info :latex-hyperref-template)))
(and (stringp template)
(format-spec template spec)))
+ ;; engrave-faces-latex preamble
+ (when (eq org-latex-listings 'engraved)
+ (let ((src-p (org-element-map (plist-get info :parse-tree)
+ '(src-block inline-src-block) #'identity))
+ (fixedw-p
+ (org-element-map (plist-get info :parse-tree)
+ '(example-block fixed-width) #'identity)))
+ (when (or src-p fixedw-p)
+ (org-latex-generate-engraved-preamble info src-p))))
;; Document start.
"\\begin{document}\n\n"
;; Title command.
@@ -2142,6 +2300,7 @@ (defun org-latex-inline-src-block (inline-src-block _contents info)
(pcase (plist-get info :latex-listings)
('nil (org-latex--text-markup code 'code info))
('minted (org-latex-inline-src-block--minted info code lang))
+ ('engraved (org-latex-inline-src-block--engraved info code lang))
(_ (org-latex-inline-src-block--listings info code lang)))))
(defun org-latex-inline-src-block--minted (info code lang)
@@ -2149,7 +2308,7 @@ (defun org-latex-inline-src-block--minted (info code lang)
INFO, CODE, and LANG are provided by `org-latex-inline-src-block'."
(let ((mint-lang (or (cadr (assq (intern lang)
(plist-get info :latex-minted-langs)))
- (downcase org-lang)))
+ (downcase lang)))
(options (org-latex--make-option-string
(plist-get info :latex-minted-options))))
(format "\\mintinline%s{%s}{%s}"
@@ -2157,6 +2316,24 @@ (defun org-latex-inline-src-block--minted (info code lang)
mint-lang
code)))
+(defun org-latex-inline-src-block--engraved (_info code lang)
+ "Transcode an inline src block's content from Org to LaTeX, using engrave-faces.
+INFO, CODE, and LANG are provided by `org-latex-inline-src-block'."
+ (if (require 'engrave-faces-latex nil t)
+ (let (engraved-buffer engraved-code)
+ (setq engraved-buffer
+ (with-temp-buffer
+ (insert code)
+ (funcall (org-src-get-lang-mode lang))
+ (engrave-faces-latex-buffer)))
+ (setq engraved-code
+ (with-current-buffer engraved-buffer
+ (buffer-string)))
+ (kill-buffer engraved-buffer)
+ (format "\\Verb{%s}"
+ engraved-code))
+ (user-error "Cannot engrave inline src block, `engrave-faces-latex' is unavailible.")))
+
(defun org-latex-inline-src-block--listings (info code lang)
"Transcode an inline src block's content from Org to LaTeX, using lstlistings.
INFO, CODE, and LANG are provided by `org-latex-inline-src-block'."
@@ -3017,6 +3194,9 @@ (defun org-latex-src-block (src-block _contents info)
num-start retain-labels attributes float custom-env))
((eq listings 'minted)
(org-latex-src-block--minted src-block info lang caption caption-above-p label
+ num-start retain-labels attributes float))
+ ((eq listings 'engraved)
+ (org-latex-src-block--engraved src-block info lang caption caption-above-p label
num-start retain-labels attributes float))
(t
(org-latex-src-block--listings src-block info lang caption caption-above-p label
@@ -3133,6 +3313,79 @@ (defun org-latex-src-block--minted
;; Return value.
(format float-env body)))
+(defun org-latex-src-block--engraved
+ (src-block info lang caption caption-above-p _label
+ num-start retain-labels attributes float)
+ "Transcode a SRC-BLOCK element from Org to LaTeX, using engrave-faces-latex.
+LANG, CAPTION, CAPTION-ABOVE-P, LABEL, NUM-START, RETAIN-LABELS, ATTRIBUTES
+and FLOAT are extracted from SRC-BLOCK and INFO in `org-latex-src-block'."
+ (if (require 'engrave-faces-latex nil t)
+ (let* ((caption-str (org-latex--caption/label-string src-block info))
+ (placement (or (org-unbracket-string "[" "]" (plist-get attributes :placement))
+ (plist-get info :latex-default-figure-position)))
+ (float-env
+ (cond
+ ((string= "multicolumn" float)
+ (format "\\begin{listing*}[%s]\n%s%%s\n%s\\end{listing*}"
+ placement
+ (if caption-above-p caption-str "")
+ (if caption-above-p "" caption-str)))
+ (caption
+ (format "\\begin{listing}[%s]\n%s%%s\n%s\\end{listing}"
+ placement
+ (if caption-above-p caption-str "")
+ (if caption-above-p "" caption-str)))
+ ((string= "t" float)
+ (concat (format "\\begin{listing}[%s]\n"
+ placement)
+ "%s\n\\end{listing}"))
+ (t "%s")))
+ (options (plist-get info :latex-engraved-options))
+ (content-buffer
+ (with-temp-buffer
+ (insert
+ (let* ((code-info (org-export-unravel-code src-block))
+ (max-width
+ (apply 'max
+ (mapcar 'length
+ (org-split-string (car code-info)
+ "\n")))))
+ (org-export-format-code
+ (car code-info)
+ (lambda (loc _num ref)
+ (concat
+ loc
+ (when ref
+ ;; Ensure references are flushed to the right,
+ ;; separated with 6 spaces from the widest line
+ ;; of code.
+ (concat (make-string (+ (- max-width (length loc)) 6)
+ ?\s)
+ (format "(%s)" ref)))))
+ nil (and retain-labels (cdr code-info)))))
+ (funcall (org-src-get-lang-mode lang))
+ (engrave-faces-latex-buffer)))
+ (content
+ (with-current-buffer content-buffer
+ (buffer-string)))
+ (body
+ (format
+ "\\begin{Code}\n\\begin{Verbatim}[%s]\n%s\\end{Verbatim}\n\\end{Code}"
+ ;; Options.
+ (concat
+ (org-latex--make-option-string
+ (append
+ (when (and num-start (not (assoc "linenos" options)))
+ `(("linenos")
+ ("firstnumber" ,(number-to-string (1+ num-start)))))
+ (let ((local-options (plist-get attributes :options)))
+ (and local-options (list local-options))))))
+ content)))
+ (kill-buffer content-buffer)
+ ;; Return value.
+ (format float-env body))
+ (user-error "Cannot engrave src block, `engrave-faces-latex' is unavailible.")))
+
(defun org-latex-src-block--listings
(src-block info lang caption caption-above-p label
num-start retain-labels attributes float)
--
2.35.3
^ permalink raw reply related [relevance 25%]
* Re: [PATCH] New LaTeX code export option: engraved
@ 2022-05-05 16:09 93% ` Timothy
0 siblings, 1 reply; 200+ results
From: Timothy @ 2022-05-05 16:09 UTC (permalink / raw)
To: Daniel Fleischer; +Cc: emacs-orgmode, Nicolas Goaziou
[-- Attachment #1: Type: text/plain, Size: 336 bytes --]
Hi Daniel,
> Hi Timothy, thank you very much for your work!
Thanks for the kind words 🙂
> Let me learn a bit about the different code highlighting options in
> order to understand what you offer.
Sure. If it’s any help, here’s a comparison example I whipped up:
<https://0x0.st/oAdn.png>
All the best,
Timothy
^ permalink raw reply [relevance 93%]
* Re: [PATCH] New LaTeX code export option: engraved
@ 2022-05-05 15:17 12% ` Timothy
2022-05-05 16:13 25% ` Timothy
0 siblings, 1 reply; 200+ results
From: Timothy @ 2022-05-05 15:17 UTC (permalink / raw)
To: Ihor Radchenko; +Cc: emacs-orgmode, Daniel Fleischer, Nicolas Goaziou
[-- Attachment #1: Type: text/plain, Size: 2879 bytes --]
Hi Ihor,
> Thanks!
> Implementing fontification using Emacs capabilities is certainly a step
> in the right direction. LaTeX support for fontification has always been
> tricky.
I’m glad to hear you’re of a similar mind to me with this.
> - I tried to test your patch, and it only works partially. There is some
> stray text caused by LaTeX errors:
>
> [2. application/vnd.lotus-organizer; test.org]…
> [3. application/pdf; test.pdf]…
Ah. I thought that hyperref loaded xcolor, but it seems my assumption was
incorrect. I’ve added `\usepackage{xcolor}' to the default
`org-latex-engraved-preamble', but maybe I should ask people to modify
`org-latex-packages-alist'. I’m not sure.
> - You did not add a NEWS entry and did not update the manual in your patch.
I’m waiting till the functional content of these packages is settled/accepted,
and then I’ll write NEWS and manual entries.
> - There are many compiler warnings emitted when compiling Org with your patch
Oops, I keep on forgetting to check byte compilation. These should all be fixed now.
> The docstrings are missing in the above.
Docstrings have been added.
> I am not sure why, but the word fancy feels slightly annoying here.
Docsting rewritten.
> Since engraved is not entirely relying on LaTeX options, a lot of
> customisation is not mentioned in this docstring. AFAIU, color
> customisation is only possible by changing defcustoms from engrave-faces
> package.
>
> Another related note is what is going to happen in beamer export with
> dark background. The default face mapping in engrave-faces is using some
> kind of light theme, which may lose all the contrast on not-light
> background.
Modifying the style of engraved-faces-latex’s output is indeed done by
customising a engraved-faces variable. I don’t think we should attempt to do
anything further with this within Org.
To elaborate a bit, the generated LaTeX uses the styling information given in
`engrave-faces-preset-styles'. Changing this to use the current Emacs theme is as
simple as `(setq engrave-faces-preset-styles (engrave-faces-generate-preset))'.
> It feels that codebackground, codeborder, and EFD should be customizable
> by org-latex-engraved-options.
Hmm. I don’t think so. They are entirely self-contained within the preamble
variable. Should there be a nice existing `org-latex-user-colors' variable or
such, it would make a lot of sense to shove this there, but since no such
variable exists I’m not sure we can really do much better than just asking users
to modify `org-latex-engraved-preamble'.
> Docstring?
Added.
>> + (message “Cannot engrave inline src block, `engrave-faces-latex’ is unavailible.”)
>
> Why message instead of error?
User errors are now thrown.
Thanks for the feedback!
Timothy
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-ox-latex-Refactor-org-latex-src-block.patch --]
[-- Type: text/x-patch, Size: 15942 bytes --]
From d231437e2c9f96bf70520d9ddda810a95667fcdd Mon Sep 17 00:00:00 2001
From: TEC <tec@tecosaur.com>
Date: Sun, 21 Nov 2021 14:35:34 +0800
Subject: [PATCH 1/4] ox-latex: Refactor `org-latex-src-block'
* lisp/ox-latex.el (org-latex-src-block): Extract the per-format logic
from `org-latex-src-block' into new dedicated functions:
+ `org-latex-src-block--verbatim'
+ `org-latex-src-block--custom'
+ `org-latex-src-block--minted'
+ `org-latex-src-block--listings'
This makes `org-latex-src-block' much less monolithic, taking it from
175 lines to 30, and I find also makes it easier to understand.
---
lisp/ox-latex.el | 339 ++++++++++++++++++++++++++---------------------
1 file changed, 185 insertions(+), 154 deletions(-)
diff --git a/lisp/ox-latex.el b/lisp/ox-latex.el
index 841ad48bc..c2f728a1c 100644
--- a/lisp/ox-latex.el
+++ b/lisp/ox-latex.el
@@ -2997,164 +2997,195 @@ (defun org-latex-src-block (src-block _contents info)
(float (plist-get attributes :float))
(listings (plist-get info :latex-listings)))
(cond
- ;; Case 1. No source fontification.
((or (not lang) (not listings))
- (let ((caption-str (org-latex--caption/label-string src-block info))
- (verbatim (format "\\begin{verbatim}\n%s\\end{verbatim}"
- (org-export-format-code-default src-block info))))
- (cond ((string= "multicolumn" float)
- (format "\\begin{figure*}[%s]\n%s%s\n%s\\end{figure*}"
- (plist-get info :latex-default-figure-position)
- (if caption-above-p caption-str "")
- verbatim
- (if caption-above-p "" caption-str)))
- (caption (concat
- (if caption-above-p caption-str "")
- verbatim
- (if caption-above-p "" (concat "\n" caption-str))))
- (t verbatim))))
- ;; Case 2. Custom environment.
+ (org-latex-src-block--verbatim src-block info lang caption caption-above-p label
+ num-start retain-labels attributes float))
(custom-env
- (let ((caption-str (org-latex--caption/label-string src-block info))
- (formatted-src (org-export-format-code-default src-block info)))
- (if (string-match-p "\\`[a-zA-Z0-9]+\\'" custom-env)
- (format "\\begin{%s}\n%s\\end{%s}\n"
- custom-env
- (concat (and caption-above-p caption-str)
- formatted-src
- (and (not caption-above-p) caption-str))
- custom-env)
- (format-spec custom-env
- `((?s . ,formatted-src)
- (?c . ,caption)
- (?f . ,float)
- (?l . ,(org-latex--label src-block info))
- (?o . ,(or (plist-get attributes :options) "")))))))
- ;; Case 3. Use minted package.
+ (org-latex-src-block--custom src-block info lang caption caption-above-p label
+ num-start retain-labels attributes float custom-env))
((eq listings 'minted)
- (let* ((caption-str (org-latex--caption/label-string src-block info))
- (placement (or (org-unbracket-string "[" "]" (plist-get attributes :placement))
- (plist-get info :latex-default-figure-position)))
- (float-env
- (cond
- ((string= "multicolumn" float)
- (format "\\begin{listing*}[%s]\n%s%%s\n%s\\end{listing*}"
- placement
- (if caption-above-p caption-str "")
- (if caption-above-p "" caption-str)))
- (caption
- (format "\\begin{listing}[%s]\n%s%%s\n%s\\end{listing}"
- placement
- (if caption-above-p caption-str "")
- (if caption-above-p "" caption-str)))
- ((string= "t" float)
- (concat (format "\\begin{listing}[%s]\n"
- placement)
- "%s\n\\end{listing}"))
- (t "%s")))
- (options (plist-get info :latex-minted-options))
- (body
- (format
- "\\begin{minted}[%s]{%s}\n%s\\end{minted}"
- ;; Options.
- (concat
- (org-latex--make-option-string
- (if (or (not num-start) (assoc "linenos" options))
- options
- (append
- `(("linenos")
- ("firstnumber" ,(number-to-string (1+ num-start))))
- options)))
- (let ((local-options (plist-get attributes :options)))
- (and local-options (concat "," local-options))))
- ;; Language.
- (or (cadr (assq (intern lang)
- (plist-get info :latex-minted-langs)))
- (downcase lang))
- ;; Source code.
- (let* ((code-info (org-export-unravel-code src-block))
- (max-width
- (apply 'max
- (mapcar 'length
- (org-split-string (car code-info)
- "\n")))))
- (org-export-format-code
- (car code-info)
- (lambda (loc _num ref)
- (concat
- loc
- (when ref
- ;; Ensure references are flushed to the right,
- ;; separated with 6 spaces from the widest line
- ;; of code.
- (concat (make-string (+ (- max-width (length loc)) 6)
- ?\s)
- (format "(%s)" ref)))))
- nil (and retain-labels (cdr code-info)))))))
- ;; Return value.
- (format float-env body)))
- ;; Case 4. Use listings package.
+ (org-latex-src-block--minted src-block info lang caption caption-above-p label
+ num-start retain-labels attributes float))
(t
- (let ((lst-lang
- (or (cadr (assq (intern lang)
- (plist-get info :latex-listings-langs)))
- lang))
- (caption-str
- (when caption
- (let ((main (org-export-get-caption src-block))
- (secondary (org-export-get-caption src-block t)))
- (if (not secondary)
- (format "{%s}" (org-export-data main info))
- (format "{[%s]%s}"
- (org-export-data secondary info)
- (org-export-data main info))))))
- (lst-opt (plist-get info :latex-listings-options)))
- (concat
- ;; Options.
- (format
- "\\lstset{%s}\n"
- (concat
- (org-latex--make-option-string
- (append
- lst-opt
- (cond
- ((and (not float) (plist-member attributes :float)) nil)
- ((string= "multicolumn" float) '(("float" "*")))
- ((and float (not (assoc "float" lst-opt)))
- `(("float" ,(plist-get info :latex-default-figure-position)))))
- `(("language" ,lst-lang))
- (if label
- `(("label" ,(org-latex--label src-block info)))
- '(("label" " ")))
- (if caption-str `(("caption" ,caption-str)) '(("caption" " ")))
- `(("captionpos" ,(if caption-above-p "t" "b")))
- (cond ((assoc "numbers" lst-opt) nil)
- ((not num-start) '(("numbers" "none")))
- (t `(("firstnumber" ,(number-to-string (1+ num-start)))
- ("numbers" "left"))))))
- (let ((local-options (plist-get attributes :options)))
- (and local-options (concat "," local-options)))))
- ;; Source code.
- (format
- "\\begin{lstlisting}\n%s\\end{lstlisting}"
- (let* ((code-info (org-export-unravel-code src-block))
- (max-width
- (apply 'max
- (mapcar 'length
- (org-split-string (car code-info) "\n")))))
- (org-export-format-code
- (car code-info)
- (lambda (loc _num ref)
- (concat
- loc
- (when ref
- ;; Ensure references are flushed to the right,
- ;; separated with 6 spaces from the widest line of
- ;; code
- (concat (make-string (+ (- max-width (length loc)) 6) ?\s)
- (format "(%s)" ref)))))
- nil (and retain-labels (cdr code-info))))))))))))
-
+ (org-latex-src-block--listings src-block info lang caption caption-above-p label
+ num-start retain-labels attributes float))))))
+
+(defun org-latex-src-block--verbatim
+ (src-block info _lang caption caption-above-p _label
+ _num-start _retain-labels _attributes float)
+ "Transcode a SRC-BLOCK element from Org to LaTeX, using verbatim.
+LANG, CAPTION, CAPTION-ABOVE-P, LABEL, NUM-START, RETAIN-LABELS, ATTRIBUTES
+and FLOAT are extracted from SRC-BLOCK and INFO in `org-latex-src-block'."
+ (let ((caption-str (org-latex--caption/label-string src-block info))
+ (verbatim (format "\\begin{verbatim}\n%s\\end{verbatim}"
+ (org-export-format-code-default src-block info))))
+ (cond ((string= "multicolumn" float)
+ (format "\\begin{figure*}[%s]\n%s%s\n%s\\end{figure*}"
+ (plist-get info :latex-default-figure-position)
+ (if caption-above-p caption-str "")
+ verbatim
+ (if caption-above-p "" caption-str)))
+ (caption (concat
+ (if caption-above-p caption-str "")
+ verbatim
+ (if caption-above-p "" (concat "\n" caption-str))))
+ (t verbatim))))
+
+(defun org-latex-src-block--custom
+ (src-block info _lang caption caption-above-p _label
+ _num-start _retain-labels attributes float custom-env)
+ "Transcode a SRC-BLOCK element from Org to LaTeX, using a custom environment.
+LANG, CAPTION, CAPTION-ABOVE-P, LABEL, NUM-START, RETAIN-LABELS, ATTRIBUTES
+and FLOAT are extracted from SRC-BLOCK and INFO in `org-latex-src-block'."
+ (let ((caption-str (org-latex--caption/label-string src-block info))
+ (formatted-src (org-export-format-code-default src-block info)))
+ (if (string-match-p "\\`[a-zA-Z0-9]+\\'" custom-env)
+ (format "\\begin{%s}\n%s\\end{%s}\n"
+ custom-env
+ (concat (and caption-above-p caption-str)
+ formatted-src
+ (and (not caption-above-p) caption-str))
+ custom-env)
+ (format-spec custom-env
+ `((?s . ,formatted-src)
+ (?c . ,caption)
+ (?f . ,float)
+ (?l . ,(org-latex--label src-block info))
+ (?o . ,(or (plist-get attributes :options) "")))))))
+
+(defun org-latex-src-block--minted
+ (src-block info lang caption caption-above-p _label
+ num-start retain-labels attributes float)
+ "Transcode a SRC-BLOCK element from Org to LaTeX, using minted.
+LANG, CAPTION, CAPTION-ABOVE-P, LABEL, NUM-START, RETAIN-LABELS, ATTRIBUTES
+and FLOAT are extracted from SRC-BLOCK and INFO in `org-latex-src-block'."
+ (let* ((caption-str (org-latex--caption/label-string src-block info))
+ (placement (or (org-unbracket-string "[" "]" (plist-get attributes :placement))
+ (plist-get info :latex-default-figure-position)))
+ (float-env
+ (cond
+ ((string= "multicolumn" float)
+ (format "\\begin{listing*}[%s]\n%s%%s\n%s\\end{listing*}"
+ placement
+ (if caption-above-p caption-str "")
+ (if caption-above-p "" caption-str)))
+ (caption
+ (format "\\begin{listing}[%s]\n%s%%s\n%s\\end{listing}"
+ placement
+ (if caption-above-p caption-str "")
+ (if caption-above-p "" caption-str)))
+ ((string= "t" float)
+ (concat (format "\\begin{listing}[%s]\n"
+ placement)
+ "%s\n\\end{listing}"))
+ (t "%s")))
+ (options (plist-get info :latex-minted-options))
+ (body
+ (format
+ "\\begin{minted}[%s]{%s}\n%s\\end{minted}"
+ ;; Options.
+ (concat
+ (org-latex--make-option-string
+ (if (or (not num-start) (assoc "linenos" options))
+ options
+ (append
+ `(("linenos")
+ ("firstnumber" ,(number-to-string (1+ num-start))))
+ options)))
+ (let ((local-options (plist-get attributes :options)))
+ (and local-options (concat "," local-options))))
+ ;; Language.
+ (or (cadr (assq (intern lang)
+ (plist-get info :latex-minted-langs)))
+ (downcase lang))
+ ;; Source code.
+ (let* ((code-info (org-export-unravel-code src-block))
+ (max-width
+ (apply 'max
+ (mapcar 'length
+ (org-split-string (car code-info)
+ "\n")))))
+ (org-export-format-code
+ (car code-info)
+ (lambda (loc _num ref)
+ (concat
+ loc
+ (when ref
+ ;; Ensure references are flushed to the right,
+ ;; separated with 6 spaces from the widest line
+ ;; of code.
+ (concat (make-string (+ (- max-width (length loc)) 6)
+ ?\s)
+ (format "(%s)" ref)))))
+ nil (and retain-labels (cdr code-info)))))))
+ ;; Return value.
+ (format float-env body)))
+
+(defun org-latex-src-block--listings
+ (src-block info lang caption caption-above-p label
+ num-start retain-labels attributes float)
+ "Transcode a SRC-BLOCK element from Org to LaTeX, using listings.
+LANG, CAPTION, CAPTION-ABOVE-P, LABEL, NUM-START, RETAIN-LABELS, ATTRIBUTES
+and FLOAT are extracted from SRC-BLOCK and INFO in `org-latex-src-block'."
+ (let ((lst-lang
+ (or (cadr (assq (intern lang)
+ (plist-get info :latex-listings-langs)))
+ lang))
+ (caption-str
+ (when caption
+ (let ((main (org-export-get-caption src-block))
+ (secondary (org-export-get-caption src-block t)))
+ (if (not secondary)
+ (format "{%s}" (org-export-data main info))
+ (format "{[%s]%s}"
+ (org-export-data secondary info)
+ (org-export-data main info))))))
+ (lst-opt (plist-get info :latex-listings-options)))
+ (concat
+ ;; Options.
+ (format
+ "\\lstset{%s}\n"
+ (concat
+ (org-latex--make-option-string
+ (append
+ lst-opt
+ (cond
+ ((and (not float) (plist-member attributes :float)) nil)
+ ((string= "multicolumn" float) '(("float" "*")))
+ ((and float (not (assoc "float" lst-opt)))
+ `(("float" ,(plist-get info :latex-default-figure-position)))))
+ `(("language" ,lst-lang))
+ (if label
+ `(("label" ,(org-latex--label src-block info)))
+ '(("label" " ")))
+ (if caption-str `(("caption" ,caption-str)) '(("caption" " ")))
+ `(("captionpos" ,(if caption-above-p "t" "b")))
+ (cond ((assoc "numbers" lst-opt) nil)
+ ((not num-start) '(("numbers" "none")))
+ (t `(("firstnumber" ,(number-to-string (1+ num-start)))
+ ("numbers" "left"))))))
+ (let ((local-options (plist-get attributes :options)))
+ (and local-options (concat "," local-options)))))
+ ;; Source code.
+ (format
+ "\\begin{lstlisting}\n%s\\end{lstlisting}"
+ (let* ((code-info (org-export-unravel-code src-block))
+ (max-width
+ (apply 'max
+ (mapcar 'length
+ (org-split-string (car code-info) "\n")))))
+ (org-export-format-code
+ (car code-info)
+ (lambda (loc _num ref)
+ (concat
+ loc
+ (when ref
+ ;; Ensure references are flushed to the right,
+ ;; separated with 6 spaces from the widest line of
+ ;; code
+ (concat (make-string (+ (- max-width (length loc)) 6) ?\s)
+ (format "(%s)" ref)))))
+ nil (and retain-labels (cdr code-info))))))))
;;;; Statistics Cookie
--
2.35.3
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #3: 0002-ox-latex-Refactor-org-latex-inline-src-block.patch --]
[-- Type: text/x-patch, Size: 4020 bytes --]
From ea5d116b06326be46e3053e6ded26d5b8b0638d9 Mon Sep 17 00:00:00 2001
From: TEC <tec@tecosaur.com>
Date: Wed, 4 May 2022 18:53:10 +0800
Subject: [PATCH 2/4] ox-latex: Refactor `org-latex-inline-src-block'
* lisp/ox-latex.el (org-latex-inline-src-block,
org-latex-inline-src-block--minted,
org-latex-inline-src-block--listings): Extract the minted and listings
specific logic out of `org-latex-inline-src-block` into the new
functions `org-latex-inline-src-block--minted` and
`org-latex-inline-src-block--listings`.
---
lisp/ox-latex.el | 62 +++++++++++++++++++++++++-----------------------
1 file changed, 32 insertions(+), 30 deletions(-)
diff --git a/lisp/ox-latex.el b/lisp/ox-latex.el
index c2f728a1c..2b732cf16 100644
--- a/lisp/ox-latex.el
+++ b/lisp/ox-latex.el
@@ -2127,36 +2127,38 @@ (defun org-latex-inline-src-block (inline-src-block _contents info)
"Transcode an INLINE-SRC-BLOCK element from Org to LaTeX.
CONTENTS holds the contents of the item. INFO is a plist holding
contextual information."
- (let* ((code (org-element-property :value inline-src-block))
- (separator (org-latex--find-verb-separator code)))
- (cl-case (plist-get info :latex-listings)
- ;; Do not use a special package: transcode it verbatim, as code.
- ((nil) (org-latex--text-markup code 'code info))
- ;; Use minted package.
- (minted
- (let* ((org-lang (org-element-property :language inline-src-block))
- (mint-lang (or (cadr (assq (intern org-lang)
- (plist-get info :latex-minted-langs)))
- (downcase org-lang)))
- (options (org-latex--make-option-string
- (plist-get info :latex-minted-options))))
- (format "\\mintinline%s{%s}{%s}"
- (if (string= options "") "" (format "[%s]" options))
- mint-lang
- code)))
- ;; Use listings package.
- (otherwise
- ;; Maybe translate language's name.
- (let* ((org-lang (org-element-property :language inline-src-block))
- (lst-lang (or (cadr (assq (intern org-lang)
- (plist-get info :latex-listings-langs)))
- org-lang))
- (options (org-latex--make-option-string
- (append (plist-get info :latex-listings-options)
- `(("language" ,lst-lang))))))
- (concat (format "\\lstinline[%s]" options)
- separator code separator))))))
-
+ (let ((code (org-element-property :value inline-src-block))
+ (lang (org-element-property :language inline-src-block)))
+ (pcase (plist-get info :latex-listings)
+ ('nil (org-latex--text-markup code 'code info))
+ ('minted (org-latex-inline-src-block--minted info code lang))
+ (_ (org-latex-inline-src-block--listings info code lang)))))
+
+(defun org-latex-inline-src-block--minted (info code lang)
+ "Transcode an inline src block's content from Org to LaTeX, using minted.
+INFO, CODE, and LANG are provided by `org-latex-inline-src-block'."
+ (let ((mint-lang (or (cadr (assq (intern lang)
+ (plist-get info :latex-minted-langs)))
+ (downcase org-lang)))
+ (options (org-latex--make-option-string
+ (plist-get info :latex-minted-options))))
+ (format "\\mintinline%s{%s}{%s}"
+ (if (string= options "") "" (format "[%s]" options))
+ mint-lang
+ code)))
+
+(defun org-latex-inline-src-block--listings (info code lang)
+ "Transcode an inline src block's content from Org to LaTeX, using lstlistings.
+INFO, CODE, and LANG are provided by `org-latex-inline-src-block'."
+ (let* ((lst-lang (or (cadr (assq (intern lang)
+ (plist-get info :latex-listings-langs)))
+ lang))
+ (separator (org-latex--find-verb-separator code))
+ (options (org-latex--make-option-string
+ (append (plist-get info :latex-listings-options)
+ `(("language" ,lst-lang))))))
+ (concat (format "\\lstinline[%s]" options)
+ separator code separator)))
;;;; Inlinetask
--
2.35.3
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #4: 0003-ox-latex-More-versitile-option-construction.patch --]
[-- Type: text/x-patch, Size: 4116 bytes --]
From aa0a9dafab7a7246e2855a2257d4c156eb48752c Mon Sep 17 00:00:00 2001
From: TEC <tec@tecosaur.com>
Date: Wed, 4 May 2022 23:31:59 +0800
Subject: [PATCH 3/4] ox-latex: More versitile option construction
* lisp/ox-latex.el (org-latex--make-option-string): Support a custom
option seperator string.
(org-latex--make-option-string, org-latex-minted-options,
org-latex-listings-options): The first line of the docstrings for
`org-latex-minted-options` and `org-latex-listings-options` describe the
variables as "association lists", yet `org-latex--make-option-string`
does not handle association lists and an example of two-value lists is
provided. To make the behaviour match the docstring,
`org-latex--make-option-string` is modified to work with either a list
two-value lists or an association list, and the examples in
`org-latex-minted-options` and `org-latex-listings-options` updated
accordingly.
---
lisp/ox-latex.el | 38 ++++++++++++++++++++++++--------------
1 file changed, 24 insertions(+), 14 deletions(-)
diff --git a/lisp/ox-latex.el b/lisp/ox-latex.el
index 2b732cf16..4181db175 100644
--- a/lisp/ox-latex.el
+++ b/lisp/ox-latex.el
@@ -1006,12 +1006,16 @@ (defcustom org-latex-listings-options nil
These options are supplied as a comma-separated list to the
\\lstset command. Each element of the association list should be
-a list containing two strings: the name of the option, and the
-value. For example,
+a list or cons cell containing two strings: the name of the
+option, and the value. For example,
(setq org-latex-listings-options
\\='((\"basicstyle\" \"\\\\small\")
(\"keywordstyle\" \"\\\\color{black}\\\\bfseries\\\\underbar\")))
+ ; or
+ (setq org-latex-listings-options
+ \\='((\"basicstyle\" . \"\\\\small\")
+ (\"keywordstyle\" . \"\\\\color{black}\\\\bfseries\\\\underbar\")))
will typeset the code in a small size font with underlined, bold
black keywords.
@@ -1059,11 +1063,14 @@ (defcustom org-latex-minted-options nil
These options are supplied within square brackets in
\\begin{minted} environments. Each element of the alist should
-be a list containing two strings: the name of the option, and the
-value. For example,
+be a list or cons cell containing two strings: the name of the
+option, and the value. For example,
(setq org-latex-minted-options
\\='((\"bgcolor\" \"bg\") (\"frame\" \"lines\")))
+ ; or
+ (setq org-latex-minted-options
+ \\='((\"bgcolor\" . \"bg\") (\"frame\" . \"lines\")))
will result in source blocks being exported with
@@ -1506,21 +1513,24 @@ (defun org-latex--find-verb-separator (s)
when (not (string-match (regexp-quote (char-to-string c)) s))
return (char-to-string c))))
-(defun org-latex--make-option-string (options)
+(defun org-latex--make-option-string (options &optional seperator)
"Return a comma separated string of keywords and values.
OPTIONS is an alist where the key is the options keyword as
a string, and the value a list containing the keyword value, or
nil."
(mapconcat (lambda (pair)
- (pcase-let ((`(,keyword ,value) pair))
- (concat keyword
- (and (> (length value) 0)
- (concat "="
- (if (string-match-p (rx (any "[]")) value)
- (format "{%s}" value)
- value))))))
- options
- ","))
+ (let ((keyword (car pair))
+ (value (pcase (cdr pair)
+ ((pred stringp) (cdr pair))
+ ((pred consp) (cadr pair)))))
+ (concat keyword
+ (when value
+ (concat "="
+ (if (string-match-p (rx (any "[]")) value)
+ (format "{%s}" value)
+ value))))))
+ options
+ (or seperator ",")))
(defun org-latex--wrap-label (element output info)
"Wrap label associated to ELEMENT around OUTPUT, if appropriate.
--
2.35.3
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #5: 0004-ox-latex-Introduce-engraved-code-highlighting.patch --]
[-- Type: text/x-patch, Size: 17464 bytes --]
From 90849f3986cc709c1d01ec9f204a7eb8b940cd27 Mon Sep 17 00:00:00 2001
From: TEC <tec@tecosaur.com>
Date: Sun, 21 Nov 2021 20:04:12 +0800
Subject: [PATCH 4/4] ox-latex: Introduce "engraved" code highlighting
* lisp/ox-latex.el (org-latex-src-block, org-latex-src-block--engraved,
org-latex-inline-src-block, org-latex-inline-src-block--engraved,
org-latex-template, org-latex-listings): Make use of the engraved-faces
package (available on ELPA) to provide an alternative LaTeX code
highlighting backend which functions similarly to htmlize.el for HTML
exports.
(org-latex-engraved-preamble, org-latex-engraved-options): Introduce
variables to construct the preamble for engraved code blocks.
* lisp/ox-beamer.el (org-beamer-template): Modify to add engrave-faces
preamble when applicable.
---
lisp/ox-beamer.el | 9 ++
lisp/ox-latex.el | 273 ++++++++++++++++++++++++++++++++++++++++++++--
2 files changed, 272 insertions(+), 10 deletions(-)
diff --git a/lisp/ox-beamer.el b/lisp/ox-beamer.el
index 6be73c91e..73bd95539 100644
--- a/lisp/ox-beamer.el
+++ b/lisp/ox-beamer.el
@@ -857,6 +857,15 @@ (defun org-beamer-template (contents info)
(let ((template (plist-get info :latex-hyperref-template)))
(and (stringp template)
(format-spec template (org-latex--format-spec info))))
+ ;; engrave-faces-latex preamble
+ (when (eq org-latex-listings 'engraved)
+ (let ((src-p (org-element-map (plist-get info :parse-tree)
+ '(src-block inline-src-block) #'identity))
+ (fixedw-p
+ (org-element-map (plist-get info :parse-tree)
+ '(example-block fixed-width) #'identity)))
+ (when (or src-p fixedw-p)
+ (org-latex-generate-engraved-preamble info src-p))))
;; Document start.
"\\begin{document}\n\n"
;; Title command.
diff --git a/lisp/ox-latex.el b/lisp/ox-latex.el
index 4181db175..831509a26 100644
--- a/lisp/ox-latex.el
+++ b/lisp/ox-latex.el
@@ -37,6 +37,8 @@ (defvar org-latex-default-packages-alist)
(defvar org-latex-packages-alist)
(defvar orgtbl-exp-regexp)
+(declare-function engrave-faces-latex-gen-preamble "ext:engrave-faces-latex")
+(declare-function engrave-faces-latex-buffer "ext:engrave-faces-latex")
\f
;;; Define Back-End
@@ -125,6 +127,8 @@ (org-export-define-backend 'latex
(:latex-default-quote-environment nil nil org-latex-default-quote-environment)
(:latex-default-table-mode nil nil org-latex-default-table-mode)
(:latex-diary-timestamp-format nil nil org-latex-diary-timestamp-format)
+ (:latex-engraved-options nil nil org-latex-engraved-options)
+ (:latex-engraved-preamble nil nil org-latex-engraved-preamble)
(:latex-footnote-defined-format nil nil org-latex-footnote-defined-format)
(:latex-footnote-separator nil nil org-latex-footnote-separator)
(:latex-format-drawer-function nil nil org-latex-format-drawer-function)
@@ -937,22 +941,48 @@ (defcustom org-latex-listings nil
"Non-nil means export source code using the listings package.
This package will fontify source code, possibly even with color.
-If you want to use this, you also need to make LaTeX use the
-listings package, and if you want to have color, the color
-package. Just add these to `org-latex-packages-alist', for
-example using customize, or with something like:
+There are four implementations of this functionality you may
+choose from (ordered from least to most capable):
+1. Verbatim (nil)
+2. Listings (t)
+3. Minted (minted)
+4. Engraved (engraved)
+
+The first two options provide basic syntax
+highlighting (listings), or none at all (verbatim).
+
+When using listings, you also need to make use of the LaTeX
+\"listings\" package. The \"color\" package is also needed if you
+would like color too. These can simply be added to
+`org-latex-packages-alist', using customise or something like:
(require \\='ox-latex)
(add-to-list \\='org-latex-packages-alist \\='(\"\" \"listings\"))
(add-to-list \\='org-latex-packages-alist \\='(\"\" \"color\"))
-Alternatively,
+There are two options for more comprehensive fontification. The
+first can be set with,
+
+ (setq org-latex-listings \\='engraved)
+
+which causes source code to be run through
+`engrave-faces-latex-buffer', which generates colorings using
+Emacs' font-lock information. This requires the engrave-faces
+package (availible from ELPA), and the fvextra LaTeX package be
+installed.
+
+The styling of the engraved result can customised with
+`org-latex-engraved-preamble' and `org-latex-engraved-options'.
+The default preamble also uses the tcolorbox LaTeX package in
+addition to fvextra.
+
+The second more comprehensive option can be used with,
(setq org-latex-listings \\='minted)
-causes source code to be exported using the minted package as
-opposed to listings. If you want to use minted, you need to add
-the minted package to `org-latex-packages-alist', for example
+which causes source code to be exported using the minted package
+as opposed to listings. If you want to use minted, you need to
+add the minted package to `org-latex-packages-alist', for example
using customize, or with
(require \\='ox-latex)
@@ -971,8 +1001,9 @@ (defcustom org-latex-listings nil
:type '(choice
(const :tag "Use listings" t)
(const :tag "Use minted" minted)
+ (const :tag "Use engrave-faces-latex" engraved)
(const :tag "Export verbatim" nil))
- :safe (lambda (s) (memq s '(t nil minted))))
+ :safe (lambda (s) (memq s '(t nil minted engraved))))
(defcustom org-latex-listings-langs
'((emacs-lisp "Lisp") (lisp "Lisp") (clojure "Lisp")
@@ -1142,6 +1173,124 @@ (defcustom org-latex-custom-lang-environments nil
:version "26.1"
:package-version '(Org . "9.0"))
+(defcustom org-latex-engraved-preamble
+ "\\usepackage{fvextra}
+
+[FVEXTRA-SETUP]
+
+\\renewcommand\\theFancyVerbLine{\\footnotesize\\color{black!40!white}\\arabic{FancyVerbLine}}
+
+\\usepackage{xcolor}
+
+\\providecolor{codebackground}{HTML}{f7f7f7}
+\\providecolor{codeborder}{HTML}{f0f0f0}
+\\providecolor{EFD}{HTML}{28292e}
+
+% TODO have code boxes keep line vertical alignment
+\\usepackage[breakable,xparse]{tcolorbox}
+\\DeclareTColorBox[]{Code}{o}%
+{colback=codebackground, colframe=codeborder,
+ fontupper=\\footnotesize\\setlength{\\fboxsep}{0pt},
+ colupper=EFD,
+ IfNoValueTF={#1}%
+ {boxsep=2pt, arc=2.5pt, outer arc=2.5pt,
+ boxrule=0.5pt, left=2pt}%
+ {boxsep=2.5pt, arc=0pt, outer arc=0pt,
+ boxrule=0pt, leftrule=1.5pt, left=0.5pt},
+ right=2pt, top=1pt, bottom=0.5pt,
+ breakable}"
+ "Preamble content injected when using engrave-faces-latex for source blocks.
+This is relevant when `org-latex-listings' is set to `engraved'.
+
+There is quite a lot of flexibility in what this preamble can be, as long as it:
+- Loads the fvextra package.
+- Loads the package xcolor (if it is not already loader elsewhere).
+- Defines a \"Code\" environment (note the capital C), which can be
+ later used to wrap \"Verbatim\" environments (provided by fvextra).
+
+A macro-like placeholder is used to set fvextra's defaults according to
+`org-latex-engraved-options':
+
+ [FVEXTRA-SETUP]
+
+In the default value the color \"EFD\" is provided as this is the
+foreground colour provided by engrave-faces-latex. When there
+are example/fixed-width blocks only, the engraved generated
+preamble is not included, and so it is provided so we may use it
+anyway."
+ :group 'org-export-latex
+ :type 'string
+ :package-version '(Org . "9.6"))
+
+(defcustom org-latex-engraved-options
+ '(("commandchars" . "\\\\\\{\\}")
+ ("highlightcolor" . "white!95!black!80!blue")
+ ("breaklines" . "true")
+ ("breaksymbol" . "\\color{white!60!black}\\tiny\\ensuremath{\\hookrightarrow}"))
+ "Association list of options for the latex fvextra package when engraving code.
+
+These options are set using \\fvset{...} in the preamble of the
+LaTeX export. Each element of the alist should be a list or cons
+cell containing two strings: the name of the option, and the
+value. For example,
+
+ (setq org-latex-engraved-options
+ \\='((\"highlightcolor\" \"green\") (\"frame\" \"lines\")))
+ ; or
+ (setq org-latex-engraved-options
+ \\='((\"highlightcolor\" . \"green\") (\"frame\" . \"lines\")))
+
+will result in the following LaTeX in the preamble
+
+\\fvset{%
+ bgcolor=bg,
+ frame=lines}
+
+This will affect all fvextra environments. Note that the same
+options will be applied to all blocks. If you need
+block-specific options, you may use the following syntax:
+
+ #+ATTR_LATEX: :options key1=value1,key2=value2
+ #+BEGIN_SRC <LANG>
+ ...
+ #+END_SRC"
+ :group 'org-export-latex
+ :type '(alist :key-type (string :tag "option")
+ :value-type (string :tag "value")))
+
+(defun org-latex-generate-engraved-preamble (info syntax-colours-p)
+ "Generate the preamble to setup engraved code.
+The result is constructed from `org-latex-engraved-preamble' and
+`org-latex-engraved-options'."
+ (let* ((engraved-options
+ (plist-get info :latex-engraved-options))
+ (engraved-preamble-template
+ (plist-get info :latex-engraved-preamble))
+ (engraved-preamble
+ (if (string-match "^[ \t]*\\[FVEXTRA-SETUP\\][ \t]*\n?"
+ engraved-preamble)
+ (replace-match
+ (concat
+ "\\fvset{%\n "
+ (org-latex--make-option-string engraved-options ",\n ")
+ "}\n")
+ t t
+ engraved-preamble-template)
+ engraved-preamble-template)))
+ (if syntax-colours-p
+ (concat
+ "\n% Setup for code blocks [1/2]\n\n"
+ engraved-preamble
+ "\n\n% Setup for code blocks [2/2]: syntax highlighting colors\n"
+ (if (require 'engrave-faces-latex nil t)
+ (engrave-faces-latex-gen-preamble)
+ (message "Cannot engrave source blocks. Consider installing `engrave-faces'.")
+ "% WARNING syntax highlighting unavailible as engrave-faces-latex was missing.\n")
+ "\n")
+ (concat
+ "\n% Setup for code blocks\n\n"
+ engraved-preamble
+ "\n"))))
;;;; Compilation
@@ -1756,6 +1905,15 @@ (defun org-latex-template (contents info)
(let ((template (plist-get info :latex-hyperref-template)))
(and (stringp template)
(format-spec template spec)))
+ ;; engrave-faces-latex preamble
+ (when (eq org-latex-listings 'engraved)
+ (let ((src-p (org-element-map (plist-get info :parse-tree)
+ '(src-block inline-src-block) #'identity))
+ (fixedw-p
+ (org-element-map (plist-get info :parse-tree)
+ '(example-block fixed-width) #'identity)))
+ (when (or src-p fixedw-p)
+ (org-latex-generate-engraved-preamble info src-p))))
;; Document start.
"\\begin{document}\n\n"
;; Title command.
@@ -2142,6 +2300,7 @@ (defun org-latex-inline-src-block (inline-src-block _contents info)
(pcase (plist-get info :latex-listings)
('nil (org-latex--text-markup code 'code info))
('minted (org-latex-inline-src-block--minted info code lang))
+ ('engraved (org-latex-inline-src-block--engraved info code lang))
(_ (org-latex-inline-src-block--listings info code lang)))))
(defun org-latex-inline-src-block--minted (info code lang)
@@ -2149,7 +2308,7 @@ (defun org-latex-inline-src-block--minted (info code lang)
INFO, CODE, and LANG are provided by `org-latex-inline-src-block'."
(let ((mint-lang (or (cadr (assq (intern lang)
(plist-get info :latex-minted-langs)))
- (downcase org-lang)))
+ (downcase lang)))
(options (org-latex--make-option-string
(plist-get info :latex-minted-options))))
(format "\\mintinline%s{%s}{%s}"
@@ -2157,6 +2316,24 @@ (defun org-latex-inline-src-block--minted (info code lang)
mint-lang
code)))
+(defun org-latex-inline-src-block--engraved (info code lang)
+ "Transcode an inline src block's content from Org to LaTeX, using engrave-faces.
+INFO, CODE, and LANG are provided by `org-latex-inline-src-block'."
+ (if (require 'engrave-faces-latex nil t)
+ (let (engraved-buffer engraved-code)
+ (setq engraved-buffer
+ (with-temp-buffer
+ (insert code)
+ (funcall (org-src-get-lang-mode lang))
+ (engrave-faces-latex-buffer)))
+ (setq engraved-code
+ (with-current-buffer engraved-buffer
+ (buffer-string)))
+ (kill-buffer engraved-buffer)
+ (format "\\Verb{%s}"
+ engraved-code))
+ (user-error "Cannot engrave inline src block, `engrave-faces-latex' is unavailible.")))
+
(defun org-latex-inline-src-block--listings (info code lang)
"Transcode an inline src block's content from Org to LaTeX, using lstlistings.
INFO, CODE, and LANG are provided by `org-latex-inline-src-block'."
@@ -3017,6 +3194,9 @@ (defun org-latex-src-block (src-block _contents info)
num-start retain-labels attributes float custom-env))
((eq listings 'minted)
(org-latex-src-block--minted src-block info lang caption caption-above-p label
+ num-start retain-labels attributes float))
+ ((eq listings 'engraved)
+ (org-latex-src-block--engraved src-block info lang caption caption-above-p label
num-start retain-labels attributes float))
(t
(org-latex-src-block--listings src-block info lang caption caption-above-p label
@@ -3133,6 +3313,79 @@ (defun org-latex-src-block--minted
;; Return value.
(format float-env body)))
+(defun org-latex-src-block--engraved
+ (src-block info lang caption caption-above-p _label
+ num-start retain-labels attributes float)
+ "Transcode a SRC-BLOCK element from Org to LaTeX, using engrave-faces-latex.
+LANG, CAPTION, CAPTION-ABOVE-P, LABEL, NUM-START, RETAIN-LABELS, ATTRIBUTES
+and FLOAT are extracted from SRC-BLOCK and INFO in `org-latex-src-block'."
+ (if (require 'engrave-faces-latex nil t)
+ (let* ((caption-str (org-latex--caption/label-string src-block info))
+ (placement (or (org-unbracket-string "[" "]" (plist-get attributes :placement))
+ (plist-get info :latex-default-figure-position)))
+ (float-env
+ (cond
+ ((string= "multicolumn" float)
+ (format "\\begin{listing*}[%s]\n%s%%s\n%s\\end{listing*}"
+ placement
+ (if caption-above-p caption-str "")
+ (if caption-above-p "" caption-str)))
+ (caption
+ (format "\\begin{listing}[%s]\n%s%%s\n%s\\end{listing}"
+ placement
+ (if caption-above-p caption-str "")
+ (if caption-above-p "" caption-str)))
+ ((string= "t" float)
+ (concat (format "\\begin{listing}[%s]\n"
+ placement)
+ "%s\n\\end{listing}"))
+ (t "%s")))
+ (options (plist-get info :latex-engraved-options))
+ (content-buffer
+ (with-temp-buffer
+ (insert
+ (let* ((code-info (org-export-unravel-code src-block))
+ (max-width
+ (apply 'max
+ (mapcar 'length
+ (org-split-string (car code-info)
+ "\n")))))
+ (org-export-format-code
+ (car code-info)
+ (lambda (loc _num ref)
+ (concat
+ loc
+ (when ref
+ ;; Ensure references are flushed to the right,
+ ;; separated with 6 spaces from the widest line
+ ;; of code.
+ (concat (make-string (+ (- max-width (length loc)) 6)
+ ?\s)
+ (format "(%s)" ref)))))
+ nil (and retain-labels (cdr code-info)))))
+ (funcall (org-src-get-lang-mode lang))
+ (engrave-faces-latex-buffer)))
+ (content
+ (with-current-buffer content-buffer
+ (buffer-string)))
+ (body
+ (format
+ "\\begin{Code}\n\\begin{Verbatim}[%s]\n%s\\end{Verbatim}\n\\end{Code}"
+ ;; Options.
+ (concat
+ (org-latex--make-option-string
+ (append
+ (when (and num-start (not (assoc "linenos" options)))
+ `(("linenos")
+ ("firstnumber" ,(number-to-string (1+ num-start)))))
+ (let ((local-options (plist-get attributes :options)))
+ (and local-options (list local-options))))))
+ content)))
+ (kill-buffer content-buffer)
+ ;; Return value.
+ (format float-env body))
+ (user-error "Cannot engrave src block, `engrave-faces-latex' is unavailible.")))
+
(defun org-latex-src-block--listings
(src-block info lang caption caption-above-p label
num-start retain-labels attributes float)
--
2.35.3
^ permalink raw reply related [relevance 12%]
* [PATCH] New LaTeX code export option: engraved
@ 2022-05-04 15:59 12% Timothy
` (2 more replies)
0 siblings, 3 replies; 200+ results
From: Timothy @ 2022-05-04 15:59 UTC (permalink / raw)
To: emacs-orgmode, Daniel Fleischer, Nicolas Goaziou
[-- Attachment #1.1: Type: text/plain, Size: 3432 bytes --]
Hi All,
I’ve been fairly busy as of late (hence my recent silence on this ML), however I
have a patchset that’s been in the works for a while that I’ve finally polished
up.
Short version: It adds a new (superior) option for exporting code blocks with
syntax highlighting to LaTeX.
The long version follows.
Currently there are four options for exporting code to LaTeX (ordered by
complexity/quality).
1. Verbatim, which simply includes the code unstyled
2. Custom, which puts the code in an enviroment of your choice
3. Listings, which uses the LaTeX package by this name. This is quick, but
exceedingly basic.
4. Minted, which uses the LaTeX package by this name. This is slow, but produces
better results than Listings
This patchset accomplishes two things:
1. It refactors the overly large `org-latex-src-block' function, and makes a few
other improvements to pre-existing code
2. It adds a new option for exporting code, named (you guessed it!) “engraved”
What is this new option, and why do we want it?
About a year ago I started work on a package that generalises the functionality
of `htmlize.el', termed `engrave-faces'
(<https://elpa.gnu.org/packages/engrave-faces.html>). It provides the ability to
extract font-lock information and export it to a number of formats: html, ansi,
and (crucially) LaTeX! Since the LaTeX export is built on the `fvextra' (LaTeX)
package (like pygments), the vast majority of the Minted options you’re used to
just carry over.
This allows for a result that is, I think, straight up better than all the
pre-existing options. For starters, you can now apply syntax highlighting to any
language you have a major mode for.
There are a number of optimisations unattempted, but it already significantly
outperforms Minted. Here are some timings from my `config.org':
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
LaTeX code backend Compile time Overhead Overhead ratio
────────────────────────────────────────────────────────────
verbatim 12 s 0 0.0
lstlistings 15 s 3 s 0.2
Engrave 34 s 22 s 1.8
Pygments (Minted) 184 s 172 s 14.3
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Compared to Minted, we also no longer have to install `pygments' or pass the
`--shelll-escape' flag to LaTeX to generate passable code blocks.
Having an all-emacs system also allows for some nifty things, like having entire
documents/presentations based on your Emacs theme (see
<https://github.com/tecosaur/ox-chameleon>). Demo images: <https://0x0.st/oAl1.png>,
<https://0x0.st/oAle.png>.
Here are some more screenshots to see what the result can look like in practice:
• <https://0x0.st/oAl2.png>
• <https://0x0.st/oAl_.png>
• <https://0x0.st/oAlL.png>
So, please take a look at the patches, give this a whirl, and let me know what
you think! 😀
All the best,
Timothy
[-- Attachment #1.2: Type: text/html, Size: 14197 bytes --]
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-ox-latex-Refactor-org-latex-src-block.patch --]
[-- Type: text/x-patch, Size: 15943 bytes --]
From 87872cc8f2fb1da1a03dc4aadfbd4af6541d8c13 Mon Sep 17 00:00:00 2001
From: TEC <tec@tecosaur.com>
Date: Sun, 21 Nov 2021 14:35:34 +0800
Subject: [PATCH 1/4] ox-latex: Refactor `org-latex-src-block'
* lisp/ox-latex.el (org-latex-src-block): Extract the per-format logic
from `org-latex-src-block' into new dedicated functions:
+ `org-latex-src-block--verbatim'
+ `org-latex-src-block--custom'
+ `org-latex-src-block--minted'
+ `org-latex-src-block--listings'
This makes `org-latex-src-block' much less monolithic, taking it from
175 lines to 30, and I find also makes it easier to understand.
---
lisp/ox-latex.el | 339 ++++++++++++++++++++++++++---------------------
1 file changed, 185 insertions(+), 154 deletions(-)
diff --git a/lisp/ox-latex.el b/lisp/ox-latex.el
index 841ad48bc..63855d2f6 100644
--- a/lisp/ox-latex.el
+++ b/lisp/ox-latex.el
@@ -2997,164 +2997,195 @@ (defun org-latex-src-block (src-block _contents info)
(float (plist-get attributes :float))
(listings (plist-get info :latex-listings)))
(cond
- ;; Case 1. No source fontification.
((or (not lang) (not listings))
- (let ((caption-str (org-latex--caption/label-string src-block info))
- (verbatim (format "\\begin{verbatim}\n%s\\end{verbatim}"
- (org-export-format-code-default src-block info))))
- (cond ((string= "multicolumn" float)
- (format "\\begin{figure*}[%s]\n%s%s\n%s\\end{figure*}"
- (plist-get info :latex-default-figure-position)
- (if caption-above-p caption-str "")
- verbatim
- (if caption-above-p "" caption-str)))
- (caption (concat
- (if caption-above-p caption-str "")
- verbatim
- (if caption-above-p "" (concat "\n" caption-str))))
- (t verbatim))))
- ;; Case 2. Custom environment.
+ (org-latex-src-block--verbatim src-block info lang caption caption-above-p label
+ num-start retain-labels attributes float))
(custom-env
- (let ((caption-str (org-latex--caption/label-string src-block info))
- (formatted-src (org-export-format-code-default src-block info)))
- (if (string-match-p "\\`[a-zA-Z0-9]+\\'" custom-env)
- (format "\\begin{%s}\n%s\\end{%s}\n"
- custom-env
- (concat (and caption-above-p caption-str)
- formatted-src
- (and (not caption-above-p) caption-str))
- custom-env)
- (format-spec custom-env
- `((?s . ,formatted-src)
- (?c . ,caption)
- (?f . ,float)
- (?l . ,(org-latex--label src-block info))
- (?o . ,(or (plist-get attributes :options) "")))))))
- ;; Case 3. Use minted package.
+ (org-latex-src-block--custom src-block info lang caption caption-above-p label
+ num-start retain-labels attributes float custom-env))
((eq listings 'minted)
- (let* ((caption-str (org-latex--caption/label-string src-block info))
- (placement (or (org-unbracket-string "[" "]" (plist-get attributes :placement))
- (plist-get info :latex-default-figure-position)))
- (float-env
- (cond
- ((string= "multicolumn" float)
- (format "\\begin{listing*}[%s]\n%s%%s\n%s\\end{listing*}"
- placement
- (if caption-above-p caption-str "")
- (if caption-above-p "" caption-str)))
- (caption
- (format "\\begin{listing}[%s]\n%s%%s\n%s\\end{listing}"
- placement
- (if caption-above-p caption-str "")
- (if caption-above-p "" caption-str)))
- ((string= "t" float)
- (concat (format "\\begin{listing}[%s]\n"
- placement)
- "%s\n\\end{listing}"))
- (t "%s")))
- (options (plist-get info :latex-minted-options))
- (body
- (format
- "\\begin{minted}[%s]{%s}\n%s\\end{minted}"
- ;; Options.
- (concat
- (org-latex--make-option-string
- (if (or (not num-start) (assoc "linenos" options))
- options
- (append
- `(("linenos")
- ("firstnumber" ,(number-to-string (1+ num-start))))
- options)))
- (let ((local-options (plist-get attributes :options)))
- (and local-options (concat "," local-options))))
- ;; Language.
- (or (cadr (assq (intern lang)
- (plist-get info :latex-minted-langs)))
- (downcase lang))
- ;; Source code.
- (let* ((code-info (org-export-unravel-code src-block))
- (max-width
- (apply 'max
- (mapcar 'length
- (org-split-string (car code-info)
- "\n")))))
- (org-export-format-code
- (car code-info)
- (lambda (loc _num ref)
- (concat
- loc
- (when ref
- ;; Ensure references are flushed to the right,
- ;; separated with 6 spaces from the widest line
- ;; of code.
- (concat (make-string (+ (- max-width (length loc)) 6)
- ?\s)
- (format "(%s)" ref)))))
- nil (and retain-labels (cdr code-info)))))))
- ;; Return value.
- (format float-env body)))
- ;; Case 4. Use listings package.
+ (org-latex-src-block--minted src-block info lang caption caption-above-p label
+ num-start retain-labels attributes float))
(t
- (let ((lst-lang
- (or (cadr (assq (intern lang)
- (plist-get info :latex-listings-langs)))
- lang))
- (caption-str
- (when caption
- (let ((main (org-export-get-caption src-block))
- (secondary (org-export-get-caption src-block t)))
- (if (not secondary)
- (format "{%s}" (org-export-data main info))
- (format "{[%s]%s}"
- (org-export-data secondary info)
- (org-export-data main info))))))
- (lst-opt (plist-get info :latex-listings-options)))
- (concat
- ;; Options.
- (format
- "\\lstset{%s}\n"
- (concat
- (org-latex--make-option-string
- (append
- lst-opt
- (cond
- ((and (not float) (plist-member attributes :float)) nil)
- ((string= "multicolumn" float) '(("float" "*")))
- ((and float (not (assoc "float" lst-opt)))
- `(("float" ,(plist-get info :latex-default-figure-position)))))
- `(("language" ,lst-lang))
- (if label
- `(("label" ,(org-latex--label src-block info)))
- '(("label" " ")))
- (if caption-str `(("caption" ,caption-str)) '(("caption" " ")))
- `(("captionpos" ,(if caption-above-p "t" "b")))
- (cond ((assoc "numbers" lst-opt) nil)
- ((not num-start) '(("numbers" "none")))
- (t `(("firstnumber" ,(number-to-string (1+ num-start)))
- ("numbers" "left"))))))
- (let ((local-options (plist-get attributes :options)))
- (and local-options (concat "," local-options)))))
- ;; Source code.
- (format
- "\\begin{lstlisting}\n%s\\end{lstlisting}"
- (let* ((code-info (org-export-unravel-code src-block))
- (max-width
- (apply 'max
- (mapcar 'length
- (org-split-string (car code-info) "\n")))))
- (org-export-format-code
- (car code-info)
- (lambda (loc _num ref)
- (concat
- loc
- (when ref
- ;; Ensure references are flushed to the right,
- ;; separated with 6 spaces from the widest line of
- ;; code
- (concat (make-string (+ (- max-width (length loc)) 6) ?\s)
- (format "(%s)" ref)))))
- nil (and retain-labels (cdr code-info))))))))))))
-
+ (org-latex-src-block--listings src-block info lang caption caption-above-p label
+ num-start retain-labels attributes float))))))
+
+(defun org-latex-src-block--verbatim
+ (src-block info _lang caption caption-above-p _label
+ _num-start _retain-labels _attributes float)
+ "Transcode a SRC-BLOCK element from Org to LaTeX, using verbatim.
+LANG, CAPTION, CAPTION-ABOVE-P, LABEL, NUM-START, RETAIN-LABELS, ATTRIBUTES
+and FLOAT are extracted from SRC-BLOCK and INFO in `org-latex-src-block'."
+ (let ((caption-str (org-latex--caption/label-string src-block info))
+ (verbatim (format "\\begin{verbatim}\n%s\\end{verbatim}"
+ (org-export-format-code-default src-block info))))
+ (cond ((string= "multicolumn" float)
+ (format "\\begin{figure*}[%s]\n%s%s\n%s\\end{figure*}"
+ (plist-get info :latex-default-figure-position)
+ (if caption-above-p caption-str "")
+ verbatim
+ (if caption-above-p "" caption-str)))
+ (caption (concat
+ (if caption-above-p caption-str "")
+ verbatim
+ (if caption-above-p "" (concat "\n" caption-str))))
+ (t verbatim))))
+
+(defun org-latex-src-block--custom
+ (src-block info _lang caption caption-above-p _label
+ _num-start _retain-labels attributes float custom-env)
+ "Transcode a SRC-BLOCK element from Org to LaTeX, using a custom environment.
+LANG, CAPTION, CAPTION-ABOVE-P, LABEL, NUM-START, RETAIN-LABELS, ATTRIBUTES
+and FLOAT are extracted from SRC-BLOCK and INFO in `org-latex-src-block'."
+ (let ((caption-str (org-latex--caption/label-string src-block info))
+ (formatted-src (org-export-format-code-default src-block info)))
+ (if (string-match-p "\\`[a-zA-Z0-9]+\\'" custom-env)
+ (format "\\begin{%s}\n%s\\end{%s}\n"
+ custom-env
+ (concat (and caption-above-p caption-str)
+ formatted-src
+ (and (not caption-above-p) caption-str))
+ custom-env)
+ (format-spec custom-env
+ `((?s . ,formatted-src)
+ (?c . ,caption)
+ (?f . ,float)
+ (?l . ,(org-latex--label src-block info))
+ (?o . ,(or (plist-get attributes :options) "")))))))
+
+(defun org-latex-src-block--minted
+ (src-block info _lang caption caption-above-p _label
+ num-start retain-labels attributes float)
+ "Transcode a SRC-BLOCK element from Org to LaTeX, using minted.
+LANG, CAPTION, CAPTION-ABOVE-P, LABEL, NUM-START, RETAIN-LABELS, ATTRIBUTES
+and FLOAT are extracted from SRC-BLOCK and INFO in `org-latex-src-block'."
+ (let* ((caption-str (org-latex--caption/label-string src-block info))
+ (placement (or (org-unbracket-string "[" "]" (plist-get attributes :placement))
+ (plist-get info :latex-default-figure-position)))
+ (float-env
+ (cond
+ ((string= "multicolumn" float)
+ (format "\\begin{listing*}[%s]\n%s%%s\n%s\\end{listing*}"
+ placement
+ (if caption-above-p caption-str "")
+ (if caption-above-p "" caption-str)))
+ (caption
+ (format "\\begin{listing}[%s]\n%s%%s\n%s\\end{listing}"
+ placement
+ (if caption-above-p caption-str "")
+ (if caption-above-p "" caption-str)))
+ ((string= "t" float)
+ (concat (format "\\begin{listing}[%s]\n"
+ placement)
+ "%s\n\\end{listing}"))
+ (t "%s")))
+ (options (plist-get info :latex-minted-options))
+ (body
+ (format
+ "\\begin{minted}[%s]{%s}\n%s\\end{minted}"
+ ;; Options.
+ (concat
+ (org-latex--make-option-string
+ (if (or (not num-start) (assoc "linenos" options))
+ options
+ (append
+ `(("linenos")
+ ("firstnumber" ,(number-to-string (1+ num-start))))
+ options)))
+ (let ((local-options (plist-get attributes :options)))
+ (and local-options (concat "," local-options))))
+ ;; Language.
+ (or (cadr (assq (intern lang)
+ (plist-get info :latex-minted-langs)))
+ (downcase lang))
+ ;; Source code.
+ (let* ((code-info (org-export-unravel-code src-block))
+ (max-width
+ (apply 'max
+ (mapcar 'length
+ (org-split-string (car code-info)
+ "\n")))))
+ (org-export-format-code
+ (car code-info)
+ (lambda (loc _num ref)
+ (concat
+ loc
+ (when ref
+ ;; Ensure references are flushed to the right,
+ ;; separated with 6 spaces from the widest line
+ ;; of code.
+ (concat (make-string (+ (- max-width (length loc)) 6)
+ ?\s)
+ (format "(%s)" ref)))))
+ nil (and retain-labels (cdr code-info)))))))
+ ;; Return value.
+ (format float-env body)))
+
+(defun org-latex-src-block--listings
+ (src-block info lang caption caption-above-p label
+ num-start retain-labels attributes float)
+ "Transcode a SRC-BLOCK element from Org to LaTeX, using listings.
+LANG, CAPTION, CAPTION-ABOVE-P, LABEL, NUM-START, RETAIN-LABELS, ATTRIBUTES
+and FLOAT are extracted from SRC-BLOCK and INFO in `org-latex-src-block'."
+ (let ((lst-lang
+ (or (cadr (assq (intern lang)
+ (plist-get info :latex-listings-langs)))
+ lang))
+ (caption-str
+ (when caption
+ (let ((main (org-export-get-caption src-block))
+ (secondary (org-export-get-caption src-block t)))
+ (if (not secondary)
+ (format "{%s}" (org-export-data main info))
+ (format "{[%s]%s}"
+ (org-export-data secondary info)
+ (org-export-data main info))))))
+ (lst-opt (plist-get info :latex-listings-options)))
+ (concat
+ ;; Options.
+ (format
+ "\\lstset{%s}\n"
+ (concat
+ (org-latex--make-option-string
+ (append
+ lst-opt
+ (cond
+ ((and (not float) (plist-member attributes :float)) nil)
+ ((string= "multicolumn" float) '(("float" "*")))
+ ((and float (not (assoc "float" lst-opt)))
+ `(("float" ,(plist-get info :latex-default-figure-position)))))
+ `(("language" ,lst-lang))
+ (if label
+ `(("label" ,(org-latex--label src-block info)))
+ '(("label" " ")))
+ (if caption-str `(("caption" ,caption-str)) '(("caption" " ")))
+ `(("captionpos" ,(if caption-above-p "t" "b")))
+ (cond ((assoc "numbers" lst-opt) nil)
+ ((not num-start) '(("numbers" "none")))
+ (t `(("firstnumber" ,(number-to-string (1+ num-start)))
+ ("numbers" "left"))))))
+ (let ((local-options (plist-get attributes :options)))
+ (and local-options (concat "," local-options)))))
+ ;; Source code.
+ (format
+ "\\begin{lstlisting}\n%s\\end{lstlisting}"
+ (let* ((code-info (org-export-unravel-code src-block))
+ (max-width
+ (apply 'max
+ (mapcar 'length
+ (org-split-string (car code-info) "\n")))))
+ (org-export-format-code
+ (car code-info)
+ (lambda (loc _num ref)
+ (concat
+ loc
+ (when ref
+ ;; Ensure references are flushed to the right,
+ ;; separated with 6 spaces from the widest line of
+ ;; code
+ (concat (make-string (+ (- max-width (length loc)) 6) ?\s)
+ (format "(%s)" ref)))))
+ nil (and retain-labels (cdr code-info))))))))
;;;; Statistics Cookie
--
2.35.3
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #3: 0002-ox-latex-Refactor-org-latex-inline-src-block.patch --]
[-- Type: text/x-patch, Size: 3727 bytes --]
From a4d833418c3e2f0a8f365b92c01c091f75b6482d Mon Sep 17 00:00:00 2001
From: TEC <tec@tecosaur.com>
Date: Wed, 4 May 2022 18:53:10 +0800
Subject: [PATCH 2/4] ox-latex: Refactor `org-latex-inline-src-block'
* lisp/ox-latex.el (org-latex-inline-src-block,
org-latex-inline-src-block--minted,
org-latex-inline-src-block--listings): Extract the minted and listings
specific logic out of `org-latex-inline-src-block` into the new
functions `org-latex-inline-src-block--minted` and
`org-latex-inline-src-block--listings`.
---
lisp/ox-latex.el | 58 +++++++++++++++++++++++-------------------------
1 file changed, 28 insertions(+), 30 deletions(-)
diff --git a/lisp/ox-latex.el b/lisp/ox-latex.el
index 63855d2f6..ed66a51c0 100644
--- a/lisp/ox-latex.el
+++ b/lisp/ox-latex.el
@@ -2127,36 +2127,34 @@ (defun org-latex-inline-src-block (inline-src-block _contents info)
"Transcode an INLINE-SRC-BLOCK element from Org to LaTeX.
CONTENTS holds the contents of the item. INFO is a plist holding
contextual information."
- (let* ((code (org-element-property :value inline-src-block))
- (separator (org-latex--find-verb-separator code)))
- (cl-case (plist-get info :latex-listings)
- ;; Do not use a special package: transcode it verbatim, as code.
- ((nil) (org-latex--text-markup code 'code info))
- ;; Use minted package.
- (minted
- (let* ((org-lang (org-element-property :language inline-src-block))
- (mint-lang (or (cadr (assq (intern org-lang)
- (plist-get info :latex-minted-langs)))
- (downcase org-lang)))
- (options (org-latex--make-option-string
- (plist-get info :latex-minted-options))))
- (format "\\mintinline%s{%s}{%s}"
- (if (string= options "") "" (format "[%s]" options))
- mint-lang
- code)))
- ;; Use listings package.
- (otherwise
- ;; Maybe translate language's name.
- (let* ((org-lang (org-element-property :language inline-src-block))
- (lst-lang (or (cadr (assq (intern org-lang)
- (plist-get info :latex-listings-langs)))
- org-lang))
- (options (org-latex--make-option-string
- (append (plist-get info :latex-listings-options)
- `(("language" ,lst-lang))))))
- (concat (format "\\lstinline[%s]" options)
- separator code separator))))))
-
+ (let ((code (org-element-property :value inline-src-block))
+ (lang (org-element-property :language inline-src-block)))
+ (pcase (plist-get info :latex-listings)
+ ('nil (org-latex--text-markup code 'code info))
+ ('minted (org-latex-inline-src-block--minted info code lang))
+ (_ (org-latex-inline-src-block--listings info code lang)))))
+
+(defun org-latex-inline-src-block--minted (info code lang)
+ (let ((mint-lang (or (cadr (assq (intern lang)
+ (plist-get info :latex-minted-langs)))
+ (downcase org-lang)))
+ (options (org-latex--make-option-string
+ (plist-get info :latex-minted-options))))
+ (format "\\mintinline%s{%s}{%s}"
+ (if (string= options "") "" (format "[%s]" options))
+ mint-lang
+ code)))
+
+(defun org-latex-inline-src-block--listings (info code lang)
+ (let* ((lst-lang (or (cadr (assq (intern lang)
+ (plist-get info :latex-listings-langs)))
+ org-lang))
+ (separator (org-latex--find-verb-separator code))
+ (options (org-latex--make-option-string
+ (append (plist-get info :latex-listings-options)
+ `(("language" ,lst-lang))))))
+ (concat (format "\\lstinline[%s]" options)
+ separator code separator)))
;;;; Inlinetask
--
2.35.3
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #4: 0003-ox-latex-More-versitile-option-construction.patch --]
[-- Type: text/x-patch, Size: 4116 bytes --]
From b322e67cc8b88826be26ee8ae155467aa764e743 Mon Sep 17 00:00:00 2001
From: TEC <tec@tecosaur.com>
Date: Wed, 4 May 2022 23:31:59 +0800
Subject: [PATCH 3/4] ox-latex: More versitile option construction
* lisp/ox-latex.el (org-latex--make-option-string): Support a custom
option seperator string.
(org-latex--make-option-string, org-latex-minted-options,
org-latex-listings-options): The first line of the docstrings for
`org-latex-minted-options` and `org-latex-listings-options` describe the
variables as "association lists", yet `org-latex--make-option-string`
does not handle association lists and an example of two-value lists is
provided. To make the behaviour match the docstring,
`org-latex--make-option-string` is modified to work with either a list
two-value lists or an association list, and the examples in
`org-latex-minted-options` and `org-latex-listings-options` updated
accordingly.
---
lisp/ox-latex.el | 38 ++++++++++++++++++++++++--------------
1 file changed, 24 insertions(+), 14 deletions(-)
diff --git a/lisp/ox-latex.el b/lisp/ox-latex.el
index ed66a51c0..6a29efcba 100644
--- a/lisp/ox-latex.el
+++ b/lisp/ox-latex.el
@@ -1006,12 +1006,16 @@ (defcustom org-latex-listings-options nil
These options are supplied as a comma-separated list to the
\\lstset command. Each element of the association list should be
-a list containing two strings: the name of the option, and the
-value. For example,
+a list or cons cell containing two strings: the name of the
+option, and the value. For example,
(setq org-latex-listings-options
\\='((\"basicstyle\" \"\\\\small\")
(\"keywordstyle\" \"\\\\color{black}\\\\bfseries\\\\underbar\")))
+ ; or
+ (setq org-latex-listings-options
+ \\='((\"basicstyle\" . \"\\\\small\")
+ (\"keywordstyle\" . \"\\\\color{black}\\\\bfseries\\\\underbar\")))
will typeset the code in a small size font with underlined, bold
black keywords.
@@ -1059,11 +1063,14 @@ (defcustom org-latex-minted-options nil
These options are supplied within square brackets in
\\begin{minted} environments. Each element of the alist should
-be a list containing two strings: the name of the option, and the
-value. For example,
+be a list or cons cell containing two strings: the name of the
+option, and the value. For example,
(setq org-latex-minted-options
\\='((\"bgcolor\" \"bg\") (\"frame\" \"lines\")))
+ ; or
+ (setq org-latex-minted-options
+ \\='((\"bgcolor\" . \"bg\") (\"frame\" . \"lines\")))
will result in source blocks being exported with
@@ -1506,21 +1513,24 @@ (defun org-latex--find-verb-separator (s)
when (not (string-match (regexp-quote (char-to-string c)) s))
return (char-to-string c))))
-(defun org-latex--make-option-string (options)
+(defun org-latex--make-option-string (options &optional seperator)
"Return a comma separated string of keywords and values.
OPTIONS is an alist where the key is the options keyword as
a string, and the value a list containing the keyword value, or
nil."
(mapconcat (lambda (pair)
- (pcase-let ((`(,keyword ,value) pair))
- (concat keyword
- (and (> (length value) 0)
- (concat "="
- (if (string-match-p (rx (any "[]")) value)
- (format "{%s}" value)
- value))))))
- options
- ","))
+ (let ((keyword (car pair))
+ (value (pcase (cdr pair)
+ ((pred stringp) (cdr pair))
+ ((pred consp) (cadr pair)))))
+ (concat keyword
+ (when value
+ (concat "="
+ (if (string-match-p (rx (any "[]")) value)
+ (format "{%s}" value)
+ value))))))
+ options
+ (or seperator ",")))
(defun org-latex--wrap-label (element output info)
"Wrap label associated to ELEMENT around OUTPUT, if appropriate.
--
2.35.3
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #5: 0004-ox-latex-Introduce-engraved-code-highlighting.patch --]
[-- Type: text/x-patch, Size: 15169 bytes --]
From e0310e21e260a930e06d704ec8893ab1e75518aa Mon Sep 17 00:00:00 2001
From: TEC <tec@tecosaur.com>
Date: Sun, 21 Nov 2021 20:04:12 +0800
Subject: [PATCH 4/4] ox-latex: Introduce "engraved" code highlighting
* lisp/ox-latex.el (org-latex-src-block, org-latex-src-block--engraved,
org-latex-inline-src-block, org-latex-inline-src-block--engraved,
org-latex-template, org-latex-listings): Make use of the engraved-faces
package (available on ELPA) to provide an alternative LaTeX code
highlighting backend which functions similarly to htmlize.el for HTML
exports.
(org-latex-engraved-preamble, org-latex-engraved-options): Introduce
variables to construct the preamble for engraved code blocks.
* lisp/ox-beamer.el (org-beamer-template): Modify to add engrave-faces
preamble when applicable.
---
lisp/ox-beamer.el | 9 ++
lisp/ox-latex.el | 235 +++++++++++++++++++++++++++++++++++++++++++++-
2 files changed, 241 insertions(+), 3 deletions(-)
diff --git a/lisp/ox-beamer.el b/lisp/ox-beamer.el
index 6be73c91e..ca1aeafe4 100644
--- a/lisp/ox-beamer.el
+++ b/lisp/ox-beamer.el
@@ -857,6 +857,15 @@ (defun org-beamer-template (contents info)
(let ((template (plist-get info :latex-hyperref-template)))
(and (stringp template)
(format-spec template (org-latex--format-spec info))))
+ ;; engrave-faces-latex preamble
+ (let ((engraved-p (eq org-latex-listings 'engraved))
+ (src-p (org-element-map (plist-get info :parse-tree)
+ '(src-block inline-src-block) #'identity))
+ (fixedw-p
+ (org-element-map (plist-get info :parse-tree)
+ '(example-block fixed-width) #'identity)))
+ (when (or src-p fixedw-p)
+ (org-latex-generate-engraved-preamble info src-p)))
;; Document start.
"\\begin{document}\n\n"
;; Title command.
diff --git a/lisp/ox-latex.el b/lisp/ox-latex.el
index 6a29efcba..4cc82f6e7 100644
--- a/lisp/ox-latex.el
+++ b/lisp/ox-latex.el
@@ -37,6 +37,8 @@ (defvar org-latex-default-packages-alist)
(defvar org-latex-packages-alist)
(defvar orgtbl-exp-regexp)
+(declare-function engrave-faces-latex-gen-preamble "ext:engrave-faces-latex")
+(declare-function engrave-faces-latex-buffer "ext:engrave-faces-latex")
\f
;;; Define Back-End
@@ -125,6 +127,8 @@ (org-export-define-backend 'latex
(:latex-default-quote-environment nil nil org-latex-default-quote-environment)
(:latex-default-table-mode nil nil org-latex-default-table-mode)
(:latex-diary-timestamp-format nil nil org-latex-diary-timestamp-format)
+ (:latex-engraved-options nil nil org-latex-engraved-options)
+ (:latex-engraved-preamble nil nil org-latex-engraved-preamble)
(:latex-footnote-defined-format nil nil org-latex-footnote-defined-format)
(:latex-footnote-separator nil nil org-latex-footnote-separator)
(:latex-format-drawer-function nil nil org-latex-format-drawer-function)
@@ -946,7 +950,24 @@ (defcustom org-latex-listings nil
(add-to-list \\='org-latex-packages-alist \\='(\"\" \"listings\"))
(add-to-list \\='org-latex-packages-alist \\='(\"\" \"color\"))
-Alternatively,
+There are two fancier options for fontification.
+
+The first fancy alternative,
+
+ (setq org-latex-listings \\='engraved)
+
+causes source code to be run through
+`engrave-faces-latex-buffer', which generates colorings using
+Emacs' font-lock information. This requires the engrave-faces
+package (availible from ELPA), and the fvextra LaTeX package be
+installed.
+
+The styling of the engraved result can customised with
+`org-latex-engraved-preamble' and `org-latex-engraved-options'.
+The default preamble also uses the tcolorbox LaTeX package in
+addition to fvextra.
+
+The second fancy alternative,
(setq org-latex-listings \\='minted)
@@ -971,8 +992,9 @@ (defcustom org-latex-listings nil
:type '(choice
(const :tag "Use listings" t)
(const :tag "Use minted" minted)
+ (const :tag "Use engrave-faces-latex" engraved)
(const :tag "Export verbatim" nil))
- :safe (lambda (s) (memq s '(t nil minted))))
+ :safe (lambda (s) (memq s '(t nil minted engraved))))
(defcustom org-latex-listings-langs
'((emacs-lisp "Lisp") (lisp "Lisp") (clojure "Lisp")
@@ -1142,6 +1164,109 @@ (defcustom org-latex-custom-lang-environments nil
:version "26.1"
:package-version '(Org . "9.0"))
+(defcustom org-latex-engraved-preamble
+ "\\usepackage{fvextra}
+
+[FVEXTRA-SETUP]
+
+\\renewcommand\\theFancyVerbLine{\\footnotesize\\color{black!40!white}\\arabic{FancyVerbLine}}
+
+\\providecolor{codebackground}{HTML}{f7f7f7}
+\\providecolor{codeborder}{HTML}{f0f0f0}
+\\providecolor{EFD}{HTML}{28292e}
+
+% TODO have code boxes keep line vertical alignment
+\\usepackage[breakable,xparse]{tcolorbox}
+\\DeclareTColorBox[]{Code}{o}%
+{colback=codebackground, colframe=codeborder,
+ fontupper=\\footnotesize\\setlength{\\fboxsep}{0pt},
+ colupper=EFD,
+ IfNoValueTF={#1}%
+ {boxsep=2pt, arc=2.5pt, outer arc=2.5pt,
+ boxrule=0.5pt, left=2pt}%
+ {boxsep=2.5pt, arc=0pt, outer arc=0pt,
+ boxrule=0pt, leftrule=1.5pt, left=0.5pt},
+ right=2pt, top=1pt, bottom=0.5pt,
+ breakable}"
+ "Preamble content injected when using engrave-faces-latex for source blocks.
+This is relevant when `org-latex-listings' is set to `engraved'.
+
+There is quite a lot of flexibility in what this preamble can be, as long as it:
+- Loads the fvextra package.
+- Defines a \"Code\" environment (note the capital C), which can be
+ later used to wrap \"Verbatim\" environments (provided by fvextra).
+
+A macro-like placeholder is used to set fvextra's defaults according to
+`org-latex-engraved-options':
+
+ [FVEXTRA-SETUP]"
+ :group 'org-export-latex
+ :type 'string
+ :package-version '(Org . "9.6"))
+
+(defcustom org-latex-engraved-options
+ '(("commandchars" . "\\\\\\{\\}")
+ ("highlightcolor" . "white!95!black!80!blue")
+ ("breaklines" . "true")
+ ("breaksymbol" . "\\color{white!60!black}\\tiny\\ensuremath{\\hookrightarrow}"))
+ "Association list of options for the latex fvextra package when engraving code.
+
+These options are set using \\fvset{...} in the preamble of the
+LaTeX export. Each element of the alist should be a list or cons
+cell containing two strings: the name of the option, and the
+value. For example,
+
+ (setq org-latex-engraved-options
+ \\='((\"bgcolor\" \"bg\") (\"frame\" \"lines\")))
+ ; or
+ (setq org-latex-engraved-options
+ \\='((\"bgcolor\" . \"bg\") (\"frame\" . \"lines\")))
+
+will result in the following LaTeX in the preamble
+
+\\fvset{%
+ bgcolor=bg,
+ frame=lines}
+
+This will affect all fvextra environments. Note that the same
+options will be applied to all blocks. If you need
+block-specific options, you may use the following syntax:
+
+ #+ATTR_LATEX: :options key1=value1,key2=value2
+ #+BEGIN_SRC <LANG>
+ ...
+ #+END_SRC")
+
+(defun org-latex-generate-engraved-preamble (info syntax-colours-p)
+ (let* ((engraved-options
+ (plist-get info :latex-engraved-options))
+ (engraved-preamble-template
+ (plist-get info :latex-engraved-preamble))
+ (engraved-preamble
+ (if (string-match "^[ \t]*\\[FVEXTRA-SETUP\\][ \t]*\n?"
+ org-latex-engraved-preamble)
+ (replace-match
+ (concat
+ "\\fvset{%\n "
+ (org-latex--make-option-string engraved-options ",\n ")
+ "}\n")
+ t t
+ engraved-preamble-template)
+ engraved-preamble-template)))
+ (if syntax-colours-p
+ (concat
+ "\n% Setup for code blocks [1/2]\n\n"
+ engraved-preamble
+ "\n\n% Setup for code blocks [2/2]: syntax highlighting colors\n"
+ (if (require 'engrave-faces-latex nil t)
+ (engrave-faces-latex-gen-preamble)
+ (message "Cannot engrave source blocks. Consider installing `engrave-faces'.")
+ "% WARNING syntax highlighting unavailible as engrave-faces-latex was missing.\n")
+ "\n")
+ (concat
+ "\n% Setup for code blocks\n\n"
+ engraved-preamble
+ "\n"))))
;;;; Compilation
@@ -1756,6 +1881,15 @@ (defun org-latex-template (contents info)
(let ((template (plist-get info :latex-hyperref-template)))
(and (stringp template)
(format-spec template spec)))
+ ;; engrave-faces-latex preamble
+ (let ((engraved-p (eq org-latex-listings 'engraved))
+ (src-p (org-element-map (plist-get info :parse-tree)
+ '(src-block inline-src-block) #'identity))
+ (fixedw-p
+ (org-element-map (plist-get info :parse-tree)
+ '(example-block fixed-width) #'identity)))
+ (when (or src-p fixedw-p)
+ (org-latex-generate-engraved-preamble info src-p)))
;; Document start.
"\\begin{document}\n\n"
;; Title command.
@@ -2142,12 +2276,13 @@ (defun org-latex-inline-src-block (inline-src-block _contents info)
(pcase (plist-get info :latex-listings)
('nil (org-latex--text-markup code 'code info))
('minted (org-latex-inline-src-block--minted info code lang))
+ ('engraved (org-latex-inline-src-block--engraved info code lang))
(_ (org-latex-inline-src-block--listings info code lang)))))
(defun org-latex-inline-src-block--minted (info code lang)
(let ((mint-lang (or (cadr (assq (intern lang)
(plist-get info :latex-minted-langs)))
- (downcase org-lang)))
+ (downcase lang)))
(options (org-latex--make-option-string
(plist-get info :latex-minted-options))))
(format "\\mintinline%s{%s}{%s}"
@@ -2155,6 +2290,23 @@ (defun org-latex-inline-src-block--minted (info code lang)
mint-lang
code)))
+(defun org-latex-inline-src-block--engraved (info code lang)
+ (if (require 'engrave-faces-latex nil t)
+ (let (engraved-buffer engraved-code)
+ (setq engraved-buffer
+ (with-temp-buffer
+ (insert code)
+ (funcall (org-src-get-lang-mode lang))
+ (engrave-faces-latex-buffer)))
+ (setq engraved-code
+ (with-current-buffer engraved-buffer
+ (buffer-string)))
+ (kill-buffer engraved-buffer)
+ (format "\\Verb{%s}"
+ engraved-code))
+ (message "Cannot engrave inline src block, `engrave-faces-latex' is unavailible.")
+ (insert (org-latex--text-markup code 'code info))))
+
(defun org-latex-inline-src-block--listings (info code lang)
(let* ((lst-lang (or (cadr (assq (intern lang)
(plist-get info :latex-listings-langs)))
@@ -3013,6 +3165,9 @@ (defun org-latex-src-block (src-block _contents info)
num-start retain-labels attributes float custom-env))
((eq listings 'minted)
(org-latex-src-block--minted src-block info lang caption caption-above-p label
+ num-start retain-labels attributes float))
+ ((eq listings 'engraved)
+ (org-latex-src-block--engraved src-block info lang caption caption-above-p label
num-start retain-labels attributes float))
(t
(org-latex-src-block--listings src-block info lang caption caption-above-p label
@@ -3129,6 +3284,80 @@ (defun org-latex-src-block--minted
;; Return value.
(format float-env body)))
+(defun org-latex-src-block--engraved
+ (src-block info lang caption caption-above-p _label
+ num-start retain-labels attributes float)
+ "Transcode a SRC-BLOCK element from Org to LaTeX, using engrave-faces-latex.
+LANG, CAPTION, CAPTION-ABOVE-P, LABEL, NUM-START, RETAIN-LABELS, ATTRIBUTES
+and FLOAT are extracted from SRC-BLOCK and INFO in `org-latex-src-block'."
+ (if (require 'engrave-faces-latex nil t)
+ (let* ((caption-str (org-latex--caption/label-string src-block info))
+ (placement (or (org-unbracket-string "[" "]" (plist-get attributes :placement))
+ (plist-get info :latex-default-figure-position)))
+ (float-env
+ (cond
+ ((string= "multicolumn" float)
+ (format "\\begin{listing*}[%s]\n%s%%s\n%s\\end{listing*}"
+ placement
+ (if caption-above-p caption-str "")
+ (if caption-above-p "" caption-str)))
+ (caption
+ (format "\\begin{listing}[%s]\n%s%%s\n%s\\end{listing}"
+ placement
+ (if caption-above-p caption-str "")
+ (if caption-above-p "" caption-str)))
+ ((string= "t" float)
+ (concat (format "\\begin{listing}[%s]\n"
+ placement)
+ "%s\n\\end{listing}"))
+ (t "%s")))
+ (options (plist-get info :latex-engraved-options))
+ (content-buffer
+ (with-temp-buffer
+ (insert
+ (let* ((code-info (org-export-unravel-code src-block))
+ (max-width
+ (apply 'max
+ (mapcar 'length
+ (org-split-string (car code-info)
+ "\n")))))
+ (org-export-format-code
+ (car code-info)
+ (lambda (loc _num ref)
+ (concat
+ loc
+ (when ref
+ ;; Ensure references are flushed to the right,
+ ;; separated with 6 spaces from the widest line
+ ;; of code.
+ (concat (make-string (+ (- max-width (length loc)) 6)
+ ?\s)
+ (format "(%s)" ref)))))
+ nil (and retain-labels (cdr code-info)))))
+ (funcall (org-src-get-lang-mode lang))
+ (engrave-faces-latex-buffer)))
+ (content
+ (with-current-buffer content-buffer
+ (buffer-string)))
+ (body
+ (format
+ "\\begin{Code}\n\\begin{Verbatim}[%s]\n%s\\end{Verbatim}\n\\end{Code}"
+ ;; Options.
+ (concat
+ (org-latex--make-option-string
+ (append
+ (when (and num-start (not (assoc "linenos" options)))
+ `(("linenos")
+ ("firstnumber" ,(number-to-string (1+ num-start)))))
+ (let ((local-options (plist-get attributes :options)))
+ (and local-options (list local-options))))))
+ content)))
+ (kill-buffer content-buffer)
+ ;; Return value.
+ (format float-env body))
+ (message "Cannot engrave src block, `engrave-faces-latex' is unavailible.")
+ (insert (org-latex--text-markup code 'code info))))
+
(defun org-latex-src-block--listings
(src-block info lang caption caption-above-p label
num-start retain-labels attributes float)
--
2.35.3
^ permalink raw reply related [relevance 12%]
* Re: [PATCH] Remote link localisation, i.e. exporting remote images
2022-01-29 16:00 53% [PATCH] Remote link localisation, i.e. exporting remote images Timothy
@ 2022-01-31 11:40 93% ` Timothy
0 siblings, 0 replies; 200+ results
From: Timothy @ 2022-01-31 11:40 UTC (permalink / raw)
To: orgmode
[-- Attachment #1: Type: text/plain, Size: 39 bytes --]
I’ve just pushed this as 6ee4551 :)
^ permalink raw reply [relevance 93%]
* [PATCH] Remote link localisation, i.e. exporting remote images
@ 2022-01-29 16:00 53% Timothy
2022-01-31 11:40 93% ` Timothy
0 siblings, 1 reply; 200+ results
From: Timothy @ 2022-01-29 16:00 UTC (permalink / raw)
To: orgmode
[-- Attachment #1: Type: text/plain, Size: 583 bytes --]
Hi All,
Following Ihor’s recent org-persist improvements, I’ve prepared a patch making
use of it to allow for remote resource links to be transformed to local file
links during export.
This feature is implemented in ox.el, and made use of in ox-latex.el (for now)
— you can now link to https and tramp files and it should /just work/™.
Here’s a demo of what you can expect:
<file:/tmp/image-link-localisation-demo.png>
The patch is attached. If there aren’t any objections raised, I plan to merge it
shortly (in a day or two).
All the best,
Timothy
[-- Attachment #2: image-link-localisation-demo.png --]
[-- Type: image/png, Size: 133357 bytes --]
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #3: 0001-ox-Add-link-localisation-feature-using-persist.patch --]
[-- Type: text/x-patch, Size: 4277 bytes --]
From 721db5de07ca667acde997c621cf62b557f9dc3b Mon Sep 17 00:00:00 2001
From: TEC <tec@tecosaur.com>
Date: Sat, 29 Jan 2022 23:49:52 +0800
Subject: [PATCH] ox: Add link localisation feature using persist
* lisp/ox.el (org-export-link-remote-p): A new function to determine
whether a link refers to a remote resource.
(org-export-link--remote-local-copy): Download and return the local
location of a remote resource link.
(org-export-link-localise): Transform remote links to refer to a local
copy of the resource.
* lisp/ox-latex.el (org-latex-link, org-latex-inline-image-rules): Make
use of the new functions for remote resources in ox.el to support
embedding https and tramp -linked files.
---
lisp/ox-latex.el | 9 ++++++---
lisp/ox.el | 41 +++++++++++++++++++++++++++++++++++++++++
2 files changed, 47 insertions(+), 3 deletions(-)
diff --git a/lisp/ox-latex.el b/lisp/ox-latex.el
index 58252c6b8..5dda9b3ab 100644
--- a/lisp/ox-latex.el
+++ b/lisp/ox-latex.el
@@ -755,8 +755,11 @@ (defcustom org-latex-default-figure-position "htbp"
(defcustom org-latex-inline-image-rules
`(("file" . ,(rx "."
- (or "pdf" "jpeg" "jpg" "png" "ps" "eps" "tikz" "pgf" "svg")
- eos)))
+ (or "pdf" "jpeg" "jpg" "png" "ps" "eps" "tikz" "pgf" "svg")
+ eos))
+ ("https" . ,(rx "."
+ (or "jpeg" "jpg" "png" "ps" "eps" "tikz" "pgf" "svg")
+ eos)))
"Rules characterizing image files that can be inlined into LaTeX.
A rule consists in an association whose key is the type of link
@@ -2588,7 +2591,7 @@ (defun org-latex-link (link desc info)
;; Link type is handled by a special function.
((org-export-custom-protocol-maybe link desc 'latex info))
;; Image file.
- (imagep (org-latex--inline-image link info))
+ (imagep (org-latex--inline-image (org-export-link-localise link) info))
;; Radio link: Transcode target's contents and use them as link's
;; description.
((string= type "radio")
diff --git a/lisp/ox.el b/lisp/ox.el
index 831b3bf12..a258ed57f 100644
--- a/lisp/ox.el
+++ b/lisp/ox.el
@@ -4446,6 +4446,47 @@ (defun org-export-file-uri (filename)
(concat (if (string-prefix-p "/" fullname) "file://" "file:///")
fullname)))))
+(defun org-export-link-remote-p (link)
+ "Returns non-nil if the link refers to a remote resource."
+ (or (member (org-element-property :type link) '("http" "https" "ftp"))
+ (and (string= (org-element-property :type link) "file")
+ (file-remote-p (org-element-property :path link)))))
+
+(defun org-export-link--remote-local-copy (link)
+ "Download the remote resource specified by LINK, and return its local path."
+ ;; TODO work this into ol.el as a link parameter, say :download.
+ (let* ((location-type
+ (pcase (org-element-property :type link)
+ ((or "http" "https" "ftp") 'url)
+ ((and "file" (guard (file-remote-p
+ (org-element-property :path link))))
+ 'file)
+ (_ (error "Cannot copy %s:%s to a local file"
+ (org-element-property :type link)
+ (org-element-property :path link)))))
+ (path
+ (pcase location-type
+ ('url
+ (concat (org-element-property :type link)
+ ":" (org-element-property :path link)))
+ ('file
+ (org-element-property :path link)))))
+ (or (org-persist-read location-type path)
+ (org-persist-register location-type path
+ :write-immediately t))))
+
+(defun org-export-link-localise (link)
+ "If LINK refers to a remote resource, modify it to point to a local downloaded copy."
+ (when (org-export-link-remote-p link)
+ (let* ((local-path (org-export-link--remote-local-copy link)))
+ (setcdr link
+ (thread-first (cadr link)
+ (plist-put :type "file")
+ (plist-put :path local-path)
+ (plist-put :raw-link (concat "file:" local-path))
+ list))))
+ link)
+
;;;; For References
;;
;; `org-export-get-reference' associate a unique reference for any
--
2.34.1
^ permalink raw reply related [relevance 53%]
* Re: [PATCH] Add support for $…$ latex fragments followed by a dash
@ 2022-01-28 16:37 90% ` Timothy
0 siblings, 0 replies; 200+ results
From: Timothy @ 2022-01-28 16:37 UTC (permalink / raw)
To: Max Nikulin; +Cc: emacs-orgmode
[-- Attachment #1: Type: text/plain, Size: 1240 bytes --]
Hi Max,
> There is no point to discuss deprecation of $…$ and ... while usage of
> such constructs is not discouraged by the org manual
Isn’t the point of discussing depreciation now that we’d change the manual etc.
to discourage it? 😛
FWIW, I have an extra 2c to add: I think that there’s a danger in having $…$
/almost/ behave like LaTeX, as the closer it is the more surprising the edge cases
are, and due to the nature of Org there will /always/ be a collection of edge
cases with $…$. By comparison, \(…\) has much less ’surprising’ behaviour.
>> If we do deprecate support for $…$, it might also be a good idea to
>> see if we can add a utility function which would make it easier for
>> people to migrate existing documents to the new/alternative syntax. For
>> the same reason it is hard to reliably parse $…$ syntax, we probably
>> can’t automate that transition, but we should be able to reduce the effort
>> required to update existing documents.
Tim, as mentioned before I’m strongly in favour of a ~half decade transition
including utility functions to shift existing TeX constructs to LaTeX, and
adding warnings, well before dropping support.
All the best,
Timothy
^ permalink raw reply [relevance 90%]
* [PATCH] Re: Bug: org-agenda-sort-notime-is-late is not correctly handled by timestamp comparison [9.4.6 (9.4.6-12-gdcc3a8-elpaplus @ /Users/charlestam/.emacs.d/elpa/org-plus-contrib-20210830/)]
@ 2021-12-30 9:20 76% ` Timothy
0 siblings, 0 replies; 200+ results
From: Timothy @ 2021-12-30 9:20 UTC (permalink / raw)
To: Charles Tam; +Cc: emacs-orgmode
[-- Attachment #1.1: Type: text/plain, Size: 393 bytes --]
Hi Charles,
Thanks for reporting this, and sorry it’s taken so long for someone to respond
(it’s been a busy year for the maintainers).
I’ve confirmed both your issue report (thanks for the detailed steps), and your
suggested fix. As such, I’ve produced a patch (attached). It would be good if
someone else could check this looks fine and apply it.
All the best,
Timothy
[-- Attachment #1.2: Type: text/html, Size: 26003 bytes --]
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-org-agenda-Make-timestamp-ordering-match-docs.patch --]
[-- Type: text/x-patch, Size: 1155 bytes --]
From 9ecd0a9266338d7222281c7ccb16808c319646aa Mon Sep 17 00:00:00 2001
From: TEC <tec@tecosaur.com>
Date: Thu, 30 Dec 2021 17:16:29 +0800
Subject: [PATCH] org-agenda: Make timestamp ordering match docs
* lisp/org-agenda.el: When `org-agenda-sort-notime-is-late' is non-nil,
an absent timestamp is now (correctly) treated as maximal.
Bug reported by: Charles Tam <me@charlest.net> in
https://list.orgmode.org/CAKu+9YVNPSHG4HVtPFa2L2tP6yBdjJ38Teyr8OSDmCg0ZEOe9Q@mail.gmail.com
---
lisp/org-agenda.el | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/lisp/org-agenda.el b/lisp/org-agenda.el
index 721ef2ced..4321a4f0b 100644
--- a/lisp/org-agenda.el
+++ b/lisp/org-agenda.el
@@ -7729,7 +7729,7 @@ (defsubst org-cmp-ts (a b type)
\"timestamp_ia\", compare within each of these type. When TYPE
is the empty string, compare all timestamps without respect of
their type."
- (let* ((def (and (not org-agenda-sort-notime-is-late) -1))
+ (let* ((def (if org-agenda-sort-notime-is-late 99999999 -1))
(ta (or (and (string-match type (or (get-text-property 1 'type a) ""))
(get-text-property 1 'ts-date a))
def))
--
2.34.1
^ permalink raw reply related [relevance 76%]
* Faces for inline src blocks (was: [PATCH] Fontification for inline src blocks)
@ 2021-12-02 13:57 91% ` Timothy
0 siblings, 0 replies; 200+ results
From: Timothy @ 2021-12-02 13:57 UTC (permalink / raw)
To: Eric S Fraga; +Cc: org-mode-email
[-- Attachment #1: Type: text/plain, Size: 980 bytes --]
Hi Eric,
> However, I am finding the result not very pleasing unfortunately.
> Specifically, I am not happy with the use of other pre-existing faces
> (shadow and org-meta-line) for this purpose. These other faces have
> their specific uses and the resulting combination for inline src blocks,
> for me, is ugly. I do not wish to modify those faces for this use case
> as it will affect their use everywhere else.
Yep, I’ve been quite open to the prospect of adding faces, just not entirely
sure how much / what I should do. Since I didn’t want that block this feature
we’ve currently got the one-face version.
The various elements that could have a face are:
⁃ the src_ prefix
⁃ the lang component
⁃ headers
⁃ the square brackets delimiting the headers / curly brackets delimiting the content
⁃ the content
⁃ the whole block (this is what currently has a dedicated face)
Let me know what your thoughts are.
All the best,
Timothy
^ permalink raw reply [relevance 91%]
* Re: [PATCH] Fix ob-plantuml over TRAMP
@ 2021-12-02 9:43 93% ` Timothy
0 siblings, 0 replies; 200+ results
From: Timothy @ 2021-12-02 9:43 UTC (permalink / raw)
To: Guillaume Buisson (gbuisson); +Cc: emacs-orgmode
[-- Attachment #1: Type: text/plain, Size: 904 bytes --]
Hi Guillaume,
Thanks for picking this up and submitting a patch.
Have you considered using `tramp-handle-file-exists-p'? I’m not overly familiar
with tramp or this sort of issue, but it looks like it could be exactly what we want.
> My Emacs Workflow involves connecting to a dev server over SSH so I can use my
> machines as thin clients and avoid synchronizing files, for that I do pretty
> much everything over TRAMP as I don’t want to lose the benefits of GUI Emacs.
> While everything mostly works impressively fine, I noticed writing my
> specifications that ob-plantuml fails to generate diagrams.
>
> It seems to me that there is a redundant check which uses `file-exists-p` even
> if using TRAMP, the plantuml jar is located on the remote server, so it fails
> with an error even though the command to actually render the diagrams works
> fine.
All the best,
Timothy
^ permalink raw reply [relevance 93%]
* Re: [PATCH] ob-shell-test, test-ob-shell and introduction
@ 2021-12-02 9:39 93% ` Timothy
0 siblings, 0 replies; 200+ results
From: Timothy @ 2021-12-02 9:39 UTC (permalink / raw)
To: Matt; +Cc: emacs-orgmode
[-- Attachment #1: Type: text/plain, Size: 713 bytes --]
Hi Matt,
> > [FSF copyright assignment]. Have you done that yet?
>
> I just verified with my employer that my contract grants an exception for this
> project. Just emailed the request to assign@gnu.org. Also, got access from
> Bastien for worg. I figure it’s probably best to reserve any more changes ’til
> the paper work is done?
Great to hear that won’t get in the way of things 🙂. Feel free to develop and
share patches before the assignment is complete, we’ll just wait till it’s gone
through before merging (the process should just be a quick email or two and take
no more than a few days, just let us know if it’s dragging out).
Hope that helps.
All the best,
Timothy
^ permalink raw reply [relevance 93%]
* Re: [PATCH] Fix regex for determining image width from attribute
@ 2021-12-01 4:54 72% ` Timothy
0 siblings, 0 replies; 200+ results
From: Timothy @ 2021-12-01 4:54 UTC (permalink / raw)
To: Matt Huszagh; +Cc: Max Nikulin, emacs-orgmode
[-- Attachment #1: Type: text/plain, Size: 4048 bytes --]
Hi Matt,
Thanks for your thoughtful deliberation on this.
> I think the essential disagreement is whether org should take an action if not
> explicitly told to do so. I think org should only perform some action if given
> a clear directive. In this context, I feel that org is guessing what the user
> wants and taking an action based on that guess.
I broadly agree with this, but I think this is provided by the four forms that
`org-image-actual-width' can take:
⁃ `t', in which case the actual image width is always used
⁃ an integer, in which case that will always be used as the width
⁃ `nil', which produces the guessing behaviour we’re discussing
⁃ `(val)', which guesses, falling back on `val'
> Ok, back to the fact that there are multiple considerations here. The
> first issue is whether specifying a width for a backend reflects an
> intention to have that same width in the org buffer. As I previously
> stated, I don’t agree that one implies the other. But, as also
> previously discussed, this was a decision that was made almost 10 years
> ago, so changing it would be a breaking change, etc. Because of that,
> I’m not totally sure what org should do, and I expect a lot of people
> won’t want to change this.
I’m not opposed to /expanding/ the behaviour (with due consideration), which could
resolve some of your concerns, but I don’t think it would be good to prevent the
current behaviour, which at this point seems well-established.
> The other consideration is if we take the first point as a given (that
> org should use width directives for other backends), should it also
> attempt to interpret directives that are ambiguous? In this case, do we
> interpret 1.2 as 1.2? If could only be ,
> I’d be inclined to agree that this is logical. I also understand the
> case for , though this is slightly less clear. But, what if
> someone used 1.2? Seems a bit unusual I know, but maybe
> someone would want this. Again, I don’t think we should guess if there’s
> a chance we could be wrong.
I feel this very much depends on how bad “guessing wrong” is, and as previously
discussed, since it’s rather easy to correct or set `org-image-actual-width' to
prevent this, I’m not sure it warrants being terribly concerned about.
> I totally agree with you that we don’t want to implement a pseudo latex
> parser here. But I feel like all this complexity is easily resolved by
> just requiring that people be explicit about their intentions (i.e.,
> specify #+attr_org: :width). That would avoid all the complex behavior
> and surprises that could result from making intelligent guesses about
> what the user wants.
I think prioritising `#+attr_org: :width' makes a lot of sense, but I feel quite
reluctant to /require/ it.
> Anyway, let me know what you want in terms of the patch. I still think
> prioritizing attr_org should be its own patch and changing the regex and
> all the other behavior should be a separate issue. But, if you’d like me
> to perform the change I mentioned in my last email, I can take the time
> to write that up and include it in the same patch.
Thanks for continuing with this. Moving forward, I think it would be best to:
⁃ Make a patch just for prioritising `#+attr_org'
⁃ Make a patch just improving the regex (before or after the `#+attr_org' patch)
⁃ Discuss changing the behaviour of image previews separately later / in another
thread, linking to this thread when doing so.
How does that sound?
Lastly, a comment on your documentation patch from earlier. I like the changes
to `org-image-actual-width', however I think you’ve been over-eager with scrapping
the current docstring for `org-display-inline-image--width'. Since the behaviour
is implemented there, I think it should at a minimum be documented there.
The docstring for a function referring to a variable’s documentation for how it’s
handled by the function seems a bit weird.
All the best,
Timothy
^ permalink raw reply [relevance 72%]
* Re: [PATCH] Fontification for inline src blocks
@ 2021-11-30 12:46 93% ` Timothy
0 siblings, 0 replies; 200+ results
From: Timothy @ 2021-11-30 12:46 UTC (permalink / raw)
To: sebastien.miquel; +Cc: org-mode-email
[-- Attachment #1: Type: text/plain, Size: 252 bytes --]
Hi Sebastien,
> Sorry for the late reply, but isn’t there a `message' call leftover from
> debugging ?
Ooops! Time for a clean-up patch to fix the things you and Ihor’s just noticed.
Thanks for mentioning this.
All the best,
Timothy
^ permalink raw reply [relevance 93%]
* Re: [PATCH] Fontification for inline src blocks
2021-11-29 19:21 49% ` Timothy
@ 2021-11-30 11:44 93% ` Timothy
0 siblings, 1 reply; 200+ results
From: Timothy @ 2021-11-30 11:44 UTC (permalink / raw)
To: Ihor Radchenko; +Cc: org-mode-email
[-- Attachment #1: Type: text/plain, Size: 40 bytes --]
Pushed 🙂.
All the best,
Timothy
^ permalink raw reply [relevance 93%]
* Re: Subject: [PATCH] Fix DISPLAY error on exporting org with plantuml to html
@ 2021-11-30 4:18 90% ` Timothy
0 siblings, 0 replies; 200+ results
From: Timothy @ 2021-11-30 4:18 UTC (permalink / raw)
To: Sun Lin; +Cc: Bastien Guerry, marcowahlsoft@gmail.com, emacs-orgmode@gnu.org
[-- Attachment #1: Type: text/plain, Size: 628 bytes --]
Hi Sun,
> Can any help merge the patch? Or should I request Bastien to merge the patch?
Thanks for not forgetting about this. As I commented before, I this looks
sensible enough to apply, and so I’ve just pushed it as f9dcc3d with a tweaked
commit message.
You’ve also been added to the list of TINYCHANGE contributors on
<https://orgmode.org/worg/contributors.html>. If you submit more than 20
cumulative lines of non-trivial code, you’ll need to get FSF assignment.
Thanks for sharing the issue and making a patch for it 🙂 hopefully we’ll see
you around in the future.
All the best,
Timothy
^ permalink raw reply [relevance 90%]
* Re: [PATCH] Fontification for inline src blocks
@ 2021-11-29 19:21 49% ` Timothy
2021-11-30 11:44 93% ` Timothy
0 siblings, 1 reply; 200+ results
From: Timothy @ 2021-11-29 19:21 UTC (permalink / raw)
To: Ihor Radchenko; +Cc: org-mode-email
[-- Attachment #1: Type: text/plain, Size: 923 bytes --]
Hi Ihor,
> That’s an option. Though you should also consider a paragraph ending at
> EOB. Searching for “” will fail with error then.
Don’t worry, that’s just a snippet. The full logic is as follows
┌────
│ (min limit (or (save-excursion (and (search-forward "\n" limit t 2) (point)))
│ (point-max)))
└────
>> [use org-element]
Ah right. We now also have the new thread about using org-element. I think that
sounds like a great change overall, but am still keen for this patch to go
through for the moment — just as a stop gap till org-element exposes all the
necessary information and there are some nice examples of using it for
fontification.
I’ve attached the latest version of the patch. At this point I consider it
fairly well-reviewed, so I’ll push it tomorrow if I don’t hear of any
last-minute issues.
All the best,
Timothy
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-org-src-Implement-native-inline-src-fontification.patch --]
[-- Type: text/x-patch, Size: 4781 bytes --]
From 690718bd2a31f9293572aa7a583a31a0615d18c8 Mon Sep 17 00:00:00 2001
From: TEC <tec@tecosaur.com>
Date: Tue, 13 Jul 2021 02:43:29 +0800
Subject: [PATCH] org-src: Implement native inline src fontification
* lisp/org-src.el (org-fontify-inline-src-blocks,
org-fontify-inline-src-blocks-1): Create a function to search the buffer
up to a limit for inline src blocks. Light fontification is applied to
matched inline src blocks. When `org-src-fontify-natively' is
set, `org-src-font-lock-fontify-block' is applied to the content.
* lisp/org.el (org-set-font-lock-defaults): Add
`org-fontify-inline-src-blocks' to `org-font-lock-extra-keywords', which
is locally bound inside `org-set-font-lock-defaults'.
* lisp/org-faces.el: Introduce a new face `org-inline-src-block' which
inherits from `org-block' by default.
---
lisp/org-faces.el | 4 ++++
lisp/org-src.el | 44 ++++++++++++++++++++++++++++++++++++++++++++
lisp/org.el | 1 +
3 files changed, 49 insertions(+)
diff --git a/lisp/org-faces.el b/lisp/org-faces.el
index b151045a9..272762789 100644
--- a/lisp/org-faces.el
+++ b/lisp/org-faces.el
@@ -459,6 +459,10 @@ (defface org-block-end-line '((t (:inherit org-block-begin-line)))
"Face used for the line delimiting the end of source blocks."
:group 'org-faces)
+(defface org-inline-src-block '((t (:inherit org-block)))
+ "Face used for inline source blocks as a whole."
+ :group 'org-faces)
+
(defface org-verbatim '((t (:inherit (fixed-pitch shadow))))
"Face for fixed-with text like code snippets."
:group 'org-faces
diff --git a/lisp/org-src.el b/lisp/org-src.el
index 51dde602d..639a447e8 100644
--- a/lisp/org-src.el
+++ b/lisp/org-src.el
@@ -654,6 +654,50 @@ (defun org-src-font-lock-fontify-block (lang start end)
'(font-lock-fontified t fontified t font-lock-multiline t))
(set-buffer-modified-p modified)))))
+(defun org-fontify-inline-src-blocks (limit)
+ "Try to apply `org-fontify-inline-src-blocks-1'."
+ (condition-case nil
+ (org-fontify-inline-src-blocks-1 limit)
+ (error (message "Org mode fontification error in %S at %d"
+ (current-buffer)
+ (line-number-at-pos)))))
+
+(defun org-fontify-inline-src-blocks-1 (limit)
+ "Fontify inline src_LANG blocks, from `point' up to LIMIT."
+ (let ((case-fold-search t)
+ (initial-point (point)))
+ (while (re-search-forward "\\_<src_\\([^ \t\n[{]+\\)[{[]?" limit t) ; copied from `org-element-inline-src-block-parser'
+ (let ((beg (match-beginning 0))
+ (lang-beg (match-beginning 1))
+ (lang-end (match-end 1))
+ pt)
+ (font-lock-append-text-property lang-beg lang-end 'face 'org-meta-line)
+ (font-lock-append-text-property beg lang-beg 'face 'shadow)
+ (font-lock-append-text-property beg lang-end 'face 'org-inline-src-block)
+ (setq pt (goto-char lang-end))
+ ;; `org-element--parse-paired-brackets' doesn't take a limit, so to
+ ;; prevent it searching the entire rest of the buffer we temporarily
+ ;; narrow the active region.
+ (save-restriction
+ (narrow-to-region beg (min limit (or (save-excursion (and (search-forward "\n" limit t 2) (point)))
+ (point-max))))
+ (message "buf: %S" (substring-no-properties (buffer-string)))
+ (when (ignore-errors (org-element--parse-paired-brackets ?\[))
+ (font-lock-append-text-property pt (point) 'face 'org-inline-src-block)
+ (setq pt (point)))
+ (when (ignore-errors (org-element--parse-paired-brackets ?\{))
+ (remove-text-properties pt (point) '(face nil))
+ (font-lock-append-text-property pt (1+ pt) 'face '(org-inline-src-block shadow))
+ (unless (= (1+ pt) (1- (point)))
+ (if org-src-fontify-natively
+ (org-src-font-lock-fontify-block
+ (buffer-substring-no-properties lang-beg lang-end)
+ (1+ pt) (1- (point)))
+ (font-lock-append-text-property (1+ pt) (1- (point)) 'face 'org-inline-src-block)))
+ (font-lock-append-text-property (1- (point)) (point)'face '(org-inline-src-block shadow))
+ (setq pt (point)))))
+ t)))
+
\f
;;; Escape contents
diff --git a/lisp/org.el b/lisp/org.el
index 025513e7a..ec59ddf44 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -5785,6 +5785,7 @@ (defun org-set-font-lock-defaults ()
'(9 'org-special-keyword t))
;; Blocks and meta lines
'(org-fontify-meta-lines-and-blocks)
+ '(org-fontify-inline-src-blocks)
;; Citations
'(org-cite-activate))))
(setq org-font-lock-extra-keywords (delq nil org-font-lock-extra-keywords))
--
2.33.1
^ permalink raw reply related [relevance 49%]
* Re: [PATCH] Accept more :tangle-mode specification forms
2021-11-21 14:33 64% ` Timothy
@ 2021-11-29 18:57 91% ` Timothy
0 siblings, 0 replies; 200+ results
From: Timothy @ 2021-11-29 18:57 UTC (permalink / raw)
To: Tim Cross; +Cc: emacs-orgmode
[-- Attachment #1: Type: text/plain, Size: 868 bytes --]
Hi Tim,
> I’ll let you (/the ML) know when I’ve taken a look at stiky bits, and whether I
> think I’m able to create something that works. My intuition is that if ls -l can
> properly represent sticky bits (and my rudimentary understanding is that it can)
> it should be fine for specifying them too. We’ll see.
I’ve gone away and had a look, then come back and had a think. This has resulted
in 9ce7802. Since we just have to worry about suid/sgid (as :tangle-mode is only
applied to the file produced [with the sticky bit being dir-specific]), not much
is required — we just allow the `s' in place of `x' for the user/group executable
flag.
This is pretty trivial as we’re still relying on `file-modes-symbolic-to-number'
for this, and in a very straight-forward way. So, I think we should be fine now 🙂.
All the best,
Timothy
^ permalink raw reply [relevance 91%]
* Re: [patch] fix ox-latex async export bug
@ 2021-11-29 5:15 93% ` Timothy
0 siblings, 0 replies; 200+ results
From: Timothy @ 2021-11-29 5:15 UTC (permalink / raw)
To: Tim Cross; +Cc: emacs-orgmode
[-- Attachment #1: Type: text/plain, Size: 635 bytes --]
Hi Tim,
> I’m wondering if this could be a problem when exporting to latex if the
>underlying latex process encounters errors and is waiting for user input before
>it can continue (which happens if there are problems in the tex source latex is
>trying to process)?
>
> It might be worth checking next time you encounter an error if you can
> run latex on the generated *.tex file and see if it waits for user
> input?
If you look at the default value of `org-latex-pdf-process', it has the flag
`-interaction=nonstopmode' which should mean the process never pauses and waits
for user input.
All the best,
Timothy
^ permalink raw reply [relevance 93%]
* Re: [PATCH] Fix regex for determining image width from attribute
@ 2021-11-29 5:13 93% ` Timothy
0 siblings, 1 reply; 200+ results
From: Timothy @ 2021-11-29 5:13 UTC (permalink / raw)
To: Matt Huszagh; +Cc: Max Nikulin, emacs-orgmode
[-- Attachment #1: Type: text/plain, Size: 497 bytes --]
Hi Matt,
> I also still don’t really like the behavior
> here. I don’t think it makes sense to interpret a width as 120% if we
> have something like
>
> #+attr_latex: :width 1.2
What would be a more sensible interpretation in your mind? The “true” value
depends on the number of columns, and fetching that information seems a bit
unreasonable. Since this isn’t just used if nothing else if given, I see a 120%
interpretation as fairly reasonable.
All the best,
Timothy
^ permalink raw reply [relevance 93%]
* Re: [PATCH] Fix regex for determining image width from attribute
@ 2021-11-23 5:39 93% ` Timothy
0 siblings, 1 reply; 200+ results
From: Timothy @ 2021-11-23 5:39 UTC (permalink / raw)
To: Matt Huszagh; +Cc: emacs-orgmode
[-- Attachment #1: Type: text/plain, Size: 100 bytes --]
Hi Matt,
(sigh) well that’s silly. Thanks, I’ve just pushed that.
All the best,
Timothy
^ permalink raw reply [relevance 93%]
* Re: [PATCH] Fix regex for determining image width from attribute
@ 2021-11-23 5:14 93% ` Timothy
0 siblings, 1 reply; 200+ results
From: Timothy @ 2021-11-23 5:14 UTC (permalink / raw)
To: Matt Huszagh; +Cc: emacs-orgmode
[-- Attachment #1: Type: text/plain, Size: 158 bytes --]
Hi Matt,
This issue and Kyle’s change were resolved in another thread, just FYI this is
fixed now. Thanks for mentioning it.
All the best,
Timothy
^ permalink raw reply [relevance 93%]
* Re: [PATCH] ob-shell-test, test-ob-shell and introduction
@ 2021-11-22 18:43 89% ` Timothy
0 siblings, 1 reply; 200+ results
From: Timothy @ 2021-11-22 18:43 UTC (permalink / raw)
To: Matt; +Cc: emacs-orgmode
[-- Attachment #1: Type: text/plain, Size: 1301 bytes --]
Hi Matt,
> I’m interested in getting async into ob-shell.el. Since I’ve never contributed
>before, I figure it’d be good to start with a few easy tasks.
Fantastic! Great to hear from you, and I hope it goes well. Feel free to send
further emails for if you get stuck. If you intend to do more than just one or
two small tweaks (it sounds like you have bigger plans than that), you’ll need
what’s known as [FSF copyright assignment]. Have you done that yet?
> It looks to me like the stdin and cmdline header args aren’t documented anywhere
> (at least I couldn’t find anything). To make sure I’m using them correctly
> before making a patch for the manual, here are some tests.
Great! I’m not overly familiar with these, so I’ll leave other people to take a
look at the tests you’ve written, but your approach sounds good. 👍
> Please let me know if things look okay. It wasn’t clear to me how to send along
> a message with git send-email, so I formatted these patches and included them as
> an attachment. Is that fine?
Patches attached to an email are perfectly fine here.
Thanks for getting in touch, and I hope to see you around 🙂.
All the best,
Timothy
[FSF copyright assignment] <https://orgmode.org/contribute.html#copyright>
^ permalink raw reply [relevance 89%]
* Re: [PATCH] Fix regex for determining image width from attribute
@ 2021-11-22 17:54 93% ` Timothy
0 siblings, 1 reply; 200+ results
From: Timothy @ 2021-11-22 17:54 UTC (permalink / raw)
To: Matt Huszagh; +Cc: emacs-orgmode
[-- Attachment #1: Type: text/plain, Size: 300 bytes --]
Hi Matt,
I’ve just pushed the change I described in 4514a32. This improves the
interpretation of :width attributes and makes a value of “t” work as discussed.
I have not prioritised #+attr_org for now, but that sounds like a change we
could make in the future.
All the best,
Timothy
^ permalink raw reply [relevance 93%]
* Re: [PATCH] Fontification for inline src blocks
@ 2021-11-22 14:37 93% ` Timothy
0 siblings, 1 reply; 200+ results
From: Timothy @ 2021-11-22 14:37 UTC (permalink / raw)
To: Ihor Radchenko; +Cc: org-mode-email
[-- Attachment #1: Type: text/plain, Size: 1336 bytes --]
Hi Ihor,
>>>> org-inline-src-fontify-max-length
>> The description may need updating, as that’s a tad inaccurate. That value
>> actually limits how far forwards a paired paren is searched for. There’s no
>> spurious fontification.
>
> I can see the purpose. However, it still looks like overcomplication.
> org-element-context takes care about this issue simply by narrowing to
> current element (inline src block is an object and hence must end within
> current element).
Well, one simple change we could do is just replace
org-inline-src-fontify-max-length with the addition of `(save-excursion
(search-forward "\n" limit nil) (point))' to the restriction.
>>> It looks like you are repeating the job of org-element-context here. Why
>>> don’t you just get the proper object?
>>
>> IIRC `org-element-context’ doesn’t separate out the `src_’, `lang’, `[options]’, and
>> `{content}’ of an inline source code block (which we want).
>
> Sounds like an omission in org-element-context. At least, the parser
> could return :contents-begin and :contents-end. Then, you would also not
> need to re-implement the parser.
Perhaps. However frankly I don’t think it would do that much to reduce the
complexity, and what’s in this patch seems to work fairly nicely.
All the best,
Timothy
^ permalink raw reply [relevance 93%]
* Re: [PATCH] Fontification for inline src blocks
@ 2021-11-22 13:43 44% ` Timothy
0 siblings, 1 reply; 200+ results
From: Timothy @ 2021-11-22 13:43 UTC (permalink / raw)
To: Ihor Radchenko; +Cc: org-mode-email
[-- Attachment #1: Type: text/plain, Size: 3725 bytes --]
Hi Ihor,
> I have some comments. See below.
Thanks for going through this, and for all your help previously.
I appreciate it :)
>> (org-inline-src-fontify-max-length): Create a variable to limit the
>> maximum length of an inline-src block fontified, to protect from lag
>> spikes (e.g. when typing out src_lang{ and half of the buffer is
>> fontified).
>
> I do not like this. Even with this variable, some part of buffer may be
> spuriously fontified. Maybe you just verify that you are at actual
> inline-src block by examining org-element-context?
The description may need updating, as that’s a tad inaccurate. That value
actually limits how far forwards a paired paren is searched for. There’s no
spurious fontification.
>> +(defun org-fontify-inline-src-blocks (limit)
>> + “Try to apply `org-fontify-inline-src-blocks-1’.”
>> + (condition-case nil
>> + (progn
>> + (org-fontify-inline-src-blocks-1 limit)
>> + (org-fontify-inline-src-results limit))
>
> org-fontify-inline-src-results is not defined in this patch.
Ah. Thanks for catching this!
>> + (font-lock-append-text-property lang-beg lang-end ’face ’org-meta-line)
>> + (font-lock-append-text-property beg lang-beg ’face ’shadow)
>> + (font-lock-append-text-property beg lang-end ’face ’org-inline-src-block)
>
> Is there some special reason why you apply both ’shadow and
> ’org-inline-src-block? What about ’org-meta-line face? Maybe
> ’org-meta-line should not be hard-coded?
I think there’s an argument for more faces that can be made because of element
like this, but it comes down to the idea that in a `src_lang[options]{content}'
construct `src_' is effectively visual noise, particularly once fortification
occurs and it’s obvious that it’s inline code even without it. So, I find it
nicest if it’s faded, which `shadow' does. Also applying `org-inline-src-block'
allows for a consistent background colour across the whole construct.
>> + (setq pt (goto-char lang-end))
>> + ;; `org-element–parse-paired-brackets’ doesn’t take a limit, so to
>> + ;; prevent it searching the entire rest of the buffer we temporarily
>> + ;; narrow the active region.
>> + (save-restriction
>> + (narrow-to-region beg (min (point-max)
>> + limit
>> + (+ lang-end org-inline-src-fontify-max-length)))
>> + (when (ignore-errors (org-element–parse-paired-brackets ?\[))
>> + (font-lock-append-text-property pt (point) ’face ’org-inline-src-block)
>> + (setq pt (point)))
>> + (when (ignore-errors (org-element–parse-paired-brackets ?\{))
>
> It looks like you are repeating the job of org-element-context here. Why
> don’t you just get the proper object?
IIRC `org-element-context' doesn’t separate out the `src_', `lang', `[options]', and
`{content}' of an inline source code block (which we want).
>> + (remove-text-properties pt (point) ’(face nil))
>> + (font-lock-append-text-property pt (1+ pt) ’face ’(org-block shadow))
>
> Do you really intend to use ’org-block and ’shadow faces here? Not
> ’org-inline-src-block?
Ah, that was an oversight. Thanks for catching that, changed to
`(org-inline-src-block shadow)'.
>> +(defcustom org-inline-src-prettify-results t
>
> Looks like a stray defcustom. At least, it is not mentioned in the
> commit message and not used within the patch.
Removed.
> Best,
> Ihor
Thanks again! See an updated patch attached.
All the best,
Timothy
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-org-src-Implement-native-inline-src-fontification.patch --]
[-- Type: text/x-patch, Size: 5474 bytes --]
From 08fff19eb6242339f9fe5549de0bc54520a3d603 Mon Sep 17 00:00:00 2001
From: TEC <tec@tecosaur.com>
Date: Tue, 13 Jul 2021 02:43:29 +0800
Subject: [PATCH] org-src: Implement native inline src fontification
* lisp/org-src.el (org-fontify-inline-src-blocks,
org-fontify-inline-src-blocks-1): Create a function to search the buffer
up to a limit for inline src blocks. Light fontification is applied to
matched inline src blocks. When `org-src-fontify-natively' is
set, `org-src-font-lock-fontify-block' is applied to the content.
* lisp/org.el (org-set-font-lock-defaults): Add
`org-fontify-inline-src-blocks' to `org-font-lock-extra-keywords', which
is locally bound inside `org-set-font-lock-defaults'.
(org-inline-src-fontify-max-length): Create a variable to limit the
maximum length of an inline-src block fontified, to protect from lag
spikes (e.g. when typing out src_lang{ and half of the buffer is
fontified).
* lisp/org-faces.el: Introduce a new face `org-inline-src-block' which
inherits from `org-block' by default.
---
lisp/org-faces.el | 4 ++++
lisp/org-src.el | 44 ++++++++++++++++++++++++++++++++++++++++++++
lisp/org.el | 9 +++++++++
3 files changed, 57 insertions(+)
diff --git a/lisp/org-faces.el b/lisp/org-faces.el
index b151045a9..272762789 100644
--- a/lisp/org-faces.el
+++ b/lisp/org-faces.el
@@ -459,6 +459,10 @@ (defface org-block-end-line '((t (:inherit org-block-begin-line)))
"Face used for the line delimiting the end of source blocks."
:group 'org-faces)
+(defface org-inline-src-block '((t (:inherit org-block)))
+ "Face used for inline source blocks as a whole."
+ :group 'org-faces)
+
(defface org-verbatim '((t (:inherit (fixed-pitch shadow))))
"Face for fixed-with text like code snippets."
:group 'org-faces
diff --git a/lisp/org-src.el b/lisp/org-src.el
index 51dde602d..fc9ddc27e 100644
--- a/lisp/org-src.el
+++ b/lisp/org-src.el
@@ -654,6 +654,50 @@ (defun org-src-font-lock-fontify-block (lang start end)
'(font-lock-fontified t fontified t font-lock-multiline t))
(set-buffer-modified-p modified)))))
+(defun org-fontify-inline-src-blocks (limit)
+ "Try to apply `org-fontify-inline-src-blocks-1'."
+ (condition-case nil
+ (org-fontify-inline-src-blocks-1 limit)
+ (error (message "Org mode fontification error in %S at %d"
+ (current-buffer)
+ (line-number-at-pos)))))
+
+(defun org-fontify-inline-src-blocks-1 (limit)
+ "Fontify inline src_LANG blocks, from `point' up to LIMIT."
+ (let ((case-fold-search t)
+ (initial-point (point)))
+ (while (re-search-forward "\\_<src_\\([^ \t\n[{]+\\)[{[]?" limit t) ; copied from `org-element-inline-src-block-parser'
+ (let ((beg (match-beginning 0))
+ (lang-beg (match-beginning 1))
+ (lang-end (match-end 1))
+ pt)
+ (font-lock-append-text-property lang-beg lang-end 'face 'org-meta-line)
+ (font-lock-append-text-property beg lang-beg 'face 'shadow)
+ (font-lock-append-text-property beg lang-end 'face 'org-inline-src-block)
+ (setq pt (goto-char lang-end))
+ ;; `org-element--parse-paired-brackets' doesn't take a limit, so to
+ ;; prevent it searching the entire rest of the buffer we temporarily
+ ;; narrow the active region.
+ (save-restriction
+ (narrow-to-region beg (min (point-max)
+ limit
+ (+ lang-end org-inline-src-fontify-max-length)))
+ (when (ignore-errors (org-element--parse-paired-brackets ?\[))
+ (font-lock-append-text-property pt (point) 'face 'org-inline-src-block)
+ (setq pt (point)))
+ (when (ignore-errors (org-element--parse-paired-brackets ?\{))
+ (remove-text-properties pt (point) '(face nil))
+ (font-lock-append-text-property pt (1+ pt) 'face '(org-inline-src-block shadow))
+ (unless (= (1+ pt) (1- (point)))
+ (if org-src-fontify-natively
+ (org-src-font-lock-fontify-block
+ (buffer-substring-no-properties lang-beg lang-end)
+ (1+ pt) (1- (point)))
+ (font-lock-append-text-property (1+ pt) (1- (point)) 'face 'org-inline-src-block)))
+ (font-lock-append-text-property (1- (point)) (point)'face '(org-inline-src-block shadow))
+ (setq pt (point)))))
+ t)))
+
\f
;;; Escape contents
diff --git a/lisp/org.el b/lisp/org.el
index 331bd9f65..637d2646c 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -5279,6 +5279,14 @@ (defcustom org-allow-promoting-top-level-subtree nil
:version "24.1"
:group 'org-appearance)
+(defcustom org-inline-src-fontify-max-length 200
+ "Maximum content length of an inline src block that will be fontified.
+This is only relevant when `org-src-fontify-natively' is t."
+ :type 'integer
+ :package-version '(Org . "9.5")
+ :group 'org-appearance
+ :group 'org-babel)
+
(defun org-fontify-meta-lines-and-blocks (limit)
(condition-case nil
(org-fontify-meta-lines-and-blocks-1 limit)
@@ -5785,6 +5793,7 @@ (defun org-set-font-lock-defaults ()
'(9 'org-special-keyword t))
;; Blocks and meta lines
'(org-fontify-meta-lines-and-blocks)
+ '(org-fontify-inline-src-blocks)
;; Citations
'(org-cite-activate))))
(setq org-font-lock-extra-keywords (delq nil org-font-lock-extra-keywords))
--
2.33.1
^ permalink raw reply related [relevance 44%]
* Re: [PATCH] Fontification for inline src blocks
2021-11-21 14:09 49% ` Timothy
@ 2021-11-22 11:52 45% ` Timothy
0 siblings, 2 replies; 200+ results
From: Timothy @ 2021-11-22 11:52 UTC (permalink / raw)
To: org-mode-email
[-- Attachment #1: Type: text/plain, Size: 439 bytes --]
Hi Everyone,
I think there’s room in the future to add more faces for this, but I it occurs
to me that the main complaint raised in this thread can be resolved by adding
one new face: `org-inline-src-block' (which inherits from `org-block') by default.
See attached for a patch which just adds this face. I feel like this might be
the final version of this patch so I’d appreciate thoughts on this.
All the best,
Timothy
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-org-src-Implement-native-inline-src-fontification.patch --]
[-- Type: text/x-patch, Size: 5915 bytes --]
From 133b7a90853f7f9062bae40af2efc8fd22781125 Mon Sep 17 00:00:00 2001
From: TEC <tec@tecosaur.com>
Date: Tue, 13 Jul 2021 02:43:29 +0800
Subject: [PATCH] org-src: Implement native inline src fontification
* lisp/org-src.el (org-fontify-inline-src-blocks,
org-fontify-inline-src-blocks-1): Create a function to search the buffer
up to a limit for inline src blocks. Light fontification is applied to
matched inline src blocks. When `org-src-fontify-natively' is
set, `org-src-font-lock-fontify-block' is applied to the content.
* lisp/org.el (org-set-font-lock-defaults): Add
`org-fontify-inline-src-blocks' to `org-font-lock-extra-keywords', which
is locally bound inside `org-set-font-lock-defaults'.
(org-inline-src-fontify-max-length): Create a variable to limit the
maximum length of an inline-src block fontified, to protect from lag
spikes (e.g. when typing out src_lang{ and half of the buffer is
fontified).
* lisp/org-faces.el: Introduce a new face `org-inline-src-block' which
inherits from `org-block' by default.
---
lisp/org-faces.el | 4 ++++
lisp/org-src.el | 46 ++++++++++++++++++++++++++++++++++++++++++++++
lisp/org.el | 18 ++++++++++++++++++
3 files changed, 68 insertions(+)
diff --git a/lisp/org-faces.el b/lisp/org-faces.el
index b151045a9..272762789 100644
--- a/lisp/org-faces.el
+++ b/lisp/org-faces.el
@@ -459,6 +459,10 @@ (defface org-block-end-line '((t (:inherit org-block-begin-line)))
"Face used for the line delimiting the end of source blocks."
:group 'org-faces)
+(defface org-inline-src-block '((t (:inherit org-block)))
+ "Face used for inline source blocks as a whole."
+ :group 'org-faces)
+
(defface org-verbatim '((t (:inherit (fixed-pitch shadow))))
"Face for fixed-with text like code snippets."
:group 'org-faces
diff --git a/lisp/org-src.el b/lisp/org-src.el
index 51dde602d..f2aff1f43 100644
--- a/lisp/org-src.el
+++ b/lisp/org-src.el
@@ -654,6 +654,52 @@ (defun org-src-font-lock-fontify-block (lang start end)
'(font-lock-fontified t fontified t font-lock-multiline t))
(set-buffer-modified-p modified)))))
+(defun org-fontify-inline-src-blocks (limit)
+ "Try to apply `org-fontify-inline-src-blocks-1'."
+ (condition-case nil
+ (progn
+ (org-fontify-inline-src-blocks-1 limit)
+ (org-fontify-inline-src-results limit))
+ (error (message "Org mode fontification error in %S at %d"
+ (current-buffer)
+ (line-number-at-pos)))))
+
+(defun org-fontify-inline-src-blocks-1 (limit)
+ "Fontify inline src_LANG blocks, from `point' up to LIMIT."
+ (let ((case-fold-search t)
+ (initial-point (point)))
+ (while (re-search-forward "\\_<src_\\([^ \t\n[{]+\\)[{[]?" limit t) ; copied from `org-element-inline-src-block-parser'
+ (let ((beg (match-beginning 0))
+ (lang-beg (match-beginning 1))
+ (lang-end (match-end 1))
+ pt)
+ (font-lock-append-text-property lang-beg lang-end 'face 'org-meta-line)
+ (font-lock-append-text-property beg lang-beg 'face 'shadow)
+ (font-lock-append-text-property beg lang-end 'face 'org-inline-src-block)
+ (setq pt (goto-char lang-end))
+ ;; `org-element--parse-paired-brackets' doesn't take a limit, so to
+ ;; prevent it searching the entire rest of the buffer we temporarily
+ ;; narrow the active region.
+ (save-restriction
+ (narrow-to-region beg (min (point-max)
+ limit
+ (+ lang-end org-inline-src-fontify-max-length)))
+ (when (ignore-errors (org-element--parse-paired-brackets ?\[))
+ (font-lock-append-text-property pt (point) 'face 'org-inline-src-block)
+ (setq pt (point)))
+ (when (ignore-errors (org-element--parse-paired-brackets ?\{))
+ (remove-text-properties pt (point) '(face nil))
+ (font-lock-append-text-property pt (1+ pt) 'face '(org-block shadow))
+ (unless (= (1+ pt) (1- (point)))
+ (if org-src-fontify-natively
+ (org-src-font-lock-fontify-block
+ (buffer-substring-no-properties lang-beg lang-end)
+ (1+ pt) (1- (point)))
+ (font-lock-append-text-property (1+ pt) (1- (point)) 'face 'org-inline-src-block)))
+ (font-lock-append-text-property (1- (point)) (point)'face '(org-inline-src-block shadow))
+ (setq pt (point)))))
+ t)))
+
\f
;;; Escape contents
diff --git a/lisp/org.el b/lisp/org.el
index 331bd9f65..fc2ec622f 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -5279,6 +5279,23 @@ (defcustom org-allow-promoting-top-level-subtree nil
:version "24.1"
:group 'org-appearance)
+(defcustom org-inline-src-fontify-max-length 200
+ "Maximum content length of an inline src block that will be fontified.
+This is only relevant when `org-src-fontify-natively' is t."
+ :type 'integer
+ :package-version '(Org . "9.5")
+ :group 'org-appearance
+ :group 'org-babel)
+
+(defcustom org-inline-src-prettify-results t
+ "Whether to use (ab)use prettify-symbols-mode on {{{results(...)}}}.
+Either t or a cons cell of strings which are used as substitutions
+for the start and end of inline results, respectively."
+ :type '(choice boolean (cons string string))
+ :package-version '(Org . "9.5")
+ :group 'org-appearance
+ :group 'org-babel)
+
(defun org-fontify-meta-lines-and-blocks (limit)
(condition-case nil
(org-fontify-meta-lines-and-blocks-1 limit)
@@ -5785,6 +5802,7 @@ (defun org-set-font-lock-defaults ()
'(9 'org-special-keyword t))
;; Blocks and meta lines
'(org-fontify-meta-lines-and-blocks)
+ '(org-fontify-inline-src-blocks)
;; Citations
'(org-cite-activate))))
(setq org-font-lock-extra-keywords (delq nil org-font-lock-extra-keywords))
--
2.33.1
^ permalink raw reply related [relevance 45%]
* Re: [PATCH] Fix regex for determining image width from attribute
@ 2021-11-22 8:29 91% ` Timothy
0 siblings, 1 reply; 200+ results
From: Timothy @ 2021-11-22 8:29 UTC (permalink / raw)
To: Matt Huszagh; +Cc: emacs-orgmode
[-- Attachment #1: Type: text/plain, Size: 1641 bytes --]
Hi Matt,
> Unfortunately, I think this makes a valid use case
> impossible. Specifically, I like to be able to set an image width
> explicitly with #+attr_org (or some other attr_ for the corresponding
> export) and fall back to the actual image width when this isn’t
> specified. This includes the ability to use the actual image width in an
> org buffer, but an explicitly-set image width for export. For example,
> for my blog I often have attr_html set, but I want the image to use its
> actual width when displayed in org.
Thanks for explaining a use case! That’s most helpful.
> I don’t see how this is possible with the current implementation.But, it
> works naturally with the implementation I have in mind
Actually, it’s almost possible with the current implementation. Consider this
example:
┌────
│ #+attr_org: :width t
│ #+attr_html: :width 20%
│ [[file:image.png]]
└────
At the moment Org tries to interpret `t' as a number (and obviously fails),
however with a small tweak that I think would be very reasonable to make, this
would cause the behaviour you describe.
What do you think?
> (IIRC this is how it previously worked, but I could be mistaken).
You are mistaken. The previous implementation looked for `#+attr_*' too, but
didn’t recognise proportional values.
> Maybe a solution to accomplish all goals would be to add an #+attr_fallback
> (or attr_default, attr_any, attr_all, etc.) that is used for any backend
> unless a specific setting is made for that backend.
Hmmm, I’m not sure this is called for.
All the best,
Timothy
^ permalink raw reply [relevance 91%]
* Supported Emacs version (was: [PATCH] Fix window width when line numbers present)
@ 2021-11-22 5:51 90% ` Timothy
0 siblings, 0 replies; 200+ results
From: Timothy @ 2021-11-22 5:51 UTC (permalink / raw)
To: Bastien; +Cc: Matt Huszagh, emacs-orgmode, Nicolas Goaziou
[-- Attachment #1: Type: text/plain, Size: 817 bytes --]
Hi Bastien,
> Our commitment is that the latest Org version is compatible with the
> last three stable versions of Emacs.
>
> So when Emacs 28 and Org 9.6 are both out, we guarantee that Org is
> compatible with Emacs 28, 27 and 26.
>
> Does that explain it better?
Thanks for clarifying. That’s perfectly clear, and re-reading the content of
<https://orgmode.org/worg/org-maintenance.html#emacs-compatibility> I think that
is too and I just must have read it strangely the first time??
On the topic of Emacs version compatibility, I’ve just taken a peek at
org-compat.el and notice that we still have code for Emacs < 24.4 compatibility.
I’m tempted to make some patches to remove all the Emacs < 26 compatibility code
if we no longer need it. What do you think?
All the best,
Timothy
^ permalink raw reply [relevance 90%]
* Re: [PATCH] Fix window width when line numbers present
@ 2021-11-22 5:31 93% ` Timothy
0 siblings, 1 reply; 200+ results
From: Timothy @ 2021-11-22 5:31 UTC (permalink / raw)
To: Bastien; +Cc: Matt Huszagh, emacs-orgmode, Nicolas Goaziou
[-- Attachment #1: Type: text/plain, Size: 397 bytes --]
Hi Bastien,
> We can safely assume that Org 9.6 will be released after Emacs 28, so
> let’s use `line-number-display-width’ on main.
So I take this to mean that we will now assume that Org 9.6+ will target Emacs
29? This seems reasonable to me, but doesn’t quite accord with how I read
<https://orgmode.org/worg/org-maintenance.html#emacs-compatibility>.
All the best,
Timothy
^ permalink raw reply [relevance 93%]
* Re: [PATCH] Fix window width when line numbers present
@ 2021-11-22 3:16 93% ` Timothy
1 sibling, 0 replies; 200+ results
From: Timothy @ 2021-11-22 3:16 UTC (permalink / raw)
To: Nicolas Goaziou; +Cc: Matt Huszagh, emacs-orgmode
[-- Attachment #1: Type: text/plain, Size: 617 bytes --]
Nicolas Goaziou <mail@nicolasgoaziou.fr> writes:
> `line-number-display-width’ is Emacs 26+. So I guess it is unfortunately
> not acceptable on main branch.
Ooops, thanks for picking that up Nicolas. I see we actually have
┌────
│ (if (fboundp 'line-number-display-width)
│ (defalias 'org-line-number-display-width 'line-number-display-width)
│ (defun org-line-number-display-width (&rest _) 0))
└────
in org-compat.el, but I think that fallback definition could be improved — even
just `(or display-line-numbers-width 0)' would be better.
All the best,
Timothy
^ permalink raw reply [relevance 93%]
* Re: [PATCH] Fix regex for determining image width from attribute
@ 2021-11-21 19:20 81% ` Timothy
0 siblings, 1 reply; 200+ results
From: Timothy @ 2021-11-21 19:20 UTC (permalink / raw)
To: Matt Huszagh; +Cc: emacs-orgmode
[-- Attachment #1: Type: text/plain, Size: 1444 bytes --]
Hi Matt,
> A recent patch started computing the inline image width from any attr_
> line. This is incorrect, as it matches settings like attr_latex, or
> attr_html. We only want to look for settings specifically for the org
> buffer. This patch fixes that.
Once again, thank you for the patch. The fact that the current regexp matches
`#+attr_latex' and `#+attr_html' is in fact by design though*. This is because I
consider it safe to assume that a `#+attr_*' which gives non-integer width between
0 and 2 can be safely assumed to be that proportion of the page width. e.g.
`#+attr_latex: :width 0.7\linewidth' or `#+attr_html: :width 70%'.
This way, a good guess can be made without having do have both an
`#+attr_latex/html' /and/ an `#+attr_org' line for the width. Should this assumption
be incorrect, a subsequent `#+attr_org' line will override the other `#+attr_*'.
Should there be edge-cases where this assumption doesn’t hold, I’d be interested
in patches that improves the logic here. As long as this holds more often than
not though, this should be a net positive for user experience as I see it.
Do please let me know if there are any good examples of unintended /
counter-intuitive behaviour you’re aware of.
All the best,
Timothy
* Well, it’s worked this way for a while, and I made a deliberate choice to keep
this behaviour when expanding the width to recognise proportional values.
^ permalink raw reply [relevance 81%]
* Re: [PATCH] Fix window width when line numbers present
2021-11-21 19:14 92% ` Timothy
@ 2021-11-21 19:19 93% ` Timothy
1 sibling, 0 replies; 200+ results
From: Timothy @ 2021-11-21 19:19 UTC (permalink / raw)
To: Matt Huszagh; +Cc: emacs-orgmode
[-- Attachment #1: Type: text/plain, Size: 92 bytes --]
Oops, I forgot to mark this patch as applied for updates.orgmode.org.
Done in this message.
^ permalink raw reply [relevance 93%]
* Re: [PATCH] Fix window width when line numbers present
@ 2021-11-21 19:14 92% ` Timothy
2021-11-21 19:19 93% ` Timothy
1 sibling, 1 reply; 200+ results
From: Timothy @ 2021-11-21 19:14 UTC (permalink / raw)
To: Matt Huszagh; +Cc: emacs-orgmode
[-- Attachment #1: Type: text/plain, Size: 916 bytes --]
Hi Matt,
> This is a very small patch that I believe fixes a previous, incorrect
> fix for computing the window text area when line numbers are
> present. The previous fix seemed to assume that
> display-line-numbers-width being nil meant that this means line numbers
> are not present. However, it can also mean (as described in the
> variable documentation) that the line number width is computed
> dynamically.
Thanks for this patch. I wasn’t aware of `line-number-display-width' when I wrote
that, but it looks like a better fit than my `(or ... 0)' statement. As such, I’ve
just applied your patch as cd3e138, tweaking the commit message to no longer go
over the maximum length :)
Looking at the docstring for `line-number-display-width', it seems that the
pixelwise mode may be more useful for our purposes, but that improvement can be
in a subsequent patch.
All the best,
Timothy
^ permalink raw reply [relevance 92%]
* Re: [PATCH] Accept more :tangle-mode specification forms
@ 2021-11-21 14:33 64% ` Timothy
2021-11-29 18:57 91% ` Timothy
0 siblings, 1 reply; 200+ results
From: Timothy @ 2021-11-21 14:33 UTC (permalink / raw)
To: Tim Cross; +Cc: emacs-orgmode
[-- Attachment #1: Type: text/plain, Size: 6101 bytes --]
Hi Tim,
Thanks for the way in which you’ve responded to my comments. I appreciate the
effort you’ve gone to to explain your views as opposed to simply saying you
disagree with some of my current thoughts :)
Tim Cross <theophilusx@gmail.com> writes:
> My suggestion is simply to look at the value and if it is not a string, reject
> it outright. […] This is not a change in org-babel-parse-arguments,
> but rather a change in how we interpret those arguments.
Ah I see, I did not think you were suggesting this. I’m quite wary of this as it
would break all current `:tangle-mode (identity #oXYZ)' headers, which as I
understand it are /the/ way tangle-mode has been previously set.
Perhaps this is a good argument for deprecation? I think we’d need to give a
decently long transition period though (a few years).
> Allowing base 10 mode specifications is just a bad idea. The fact it has been
> permitted in the past is likely just an oversight rather than intentional
> behaviour.
I think we are of the same mind regarding base10 permissions specifications
being bad, but are niggling over what to do about this.
> Given the potential security issues involved
> here, I think we can legitimately obsolete such features (using
> acceptable change management approaches with suitable notification for
> users etc).
I’m certainly open to deprecation, though I’d like to hear from some of the
other “main Org people” (e.g. Bastien, Nicolas) before doing anything along
these lines. Perhaps this would be worth making a second thread for?
> I understand your motivation. I dispute your claim it is an established
> and common convention.
Ok, cool. Since we should have a while till the next Org release, nothing is set
in stone yet and hopefully this will give us time to see if the ls -l format is
fit for purpose or not. I think it will be, but correctness is of course more
important than niceness.
>> [sticky bits and the ls -l format]
>
> This is very difficult Timothy. I really do appreciate all the work you
> have done here and your patience, which makes what I’m going to say all
> the more difficult. My big concern here is that you don’t understand
> this area with sufficient depth of understanding to really appreciate
> some of the subtleties involved here. This makes me concerned that any
> implementation of a new way to specify mode settings may have some
> unexpected side effects or hidden issues which could be exploited in
> unexpected ways (worse case) or simply have unexpected bugs which result
> in mode settings which are not what the user intended. As someone who
> has used Unix since 1980 and Linux since 1995, I’ve experienced my share
> of issues relating to file modes and their interaction with different
> filesystems, NFS, different platforms, character sets, locales etc.
> Implementing a new approach as you are proposing is something I would be
> extremely wary about.
>
> If you do plan to go forward with this approach, please ensure you are
> very confident in your understanding of the sticky bit, setuid/setgid
> and associated interaction with execute etc.
Thanks for explaining your position thoroughly here. I don’t need any convincing
that a solid understanding is necessary for a good implementation. I had a quick
peek and estimated the time I’d need to properly come to terms with sticky bits —
hence my estimate of a few days before I look at implementing this.
> I suspect you do have the skills to implement correctly given sufficient
> time, testing and motivation. However, I am concerned your initial stab
> at this may be somewhat naive and requires more consideration. My main
> concern is that once you take all the subtleties into consideration, the
> complexity of your ls -l approach will exceed its utility and
> maintainability. I could also be completely wrong.
I’ll let you (/the ML) know when I’ve taken a look at stiky bits, and whether I
think I’m able to create something that works. My intuition is that if ls -l can
properly represent sticky bits (and my rudimentary understanding is that it can)
it should be fine for specifying them too. We’ll see.
> Choice is good. However, as I mentioned in a previous post, the problem
> with choice is complexity and the biggest source of security problems is
> complexity. Keep in mind that what you do now is something which will
> need to be maintained by others in the future. It needs to be clear,
> concise and as simple as possible (but of course, no simpler!).
I like to think that the current implementation is fairly short and clean. If I
can’t add sticky bits “nicely”, I’ll reconsider things.
> Consider this simple scenario. The tangled output is being written to a
> directory which requires specific permissions for security reasons -
> perhaps it is some type of ftp server where permissions will determine
> what can be seen by whom. The data might contain sensitive information.
> The user specifies what they thing is the correct mode specification,
> but the7y get it wrong. Org comes along and looks at what they specified
> and decides it cannot interpret what the user has specified, so applies
> a default (and potentially completely wrong) mode, exposing sensitive
> data to others who should not have had access.
>
> Use a default if the user does not specify a mode, but if they specify a
> mode and org cannot interpret what they specified, then do nothing -
> don’t generate the tangled output at all. This is the only safe
> approach.
Thanks for the example. This sounds reasonable to me, and has prompted me to
test what’s actually happening at the moment.
Seems like the user-error I raise actually causes the tangling for that file
/and all subsequent files/ to fail, i.e. no content is written. It looks like we
actually want to loosen the current behaviour :P
Alright, that’s it for now. You can expect an update in a few days on sticky
bits.
All the best,
Timothy
^ permalink raw reply [relevance 64%]
* Re: [PATCH] Fontification for inline src blocks
2021-04-28 7:14 88% ` Timothy
@ 2021-11-21 14:09 49% ` Timothy
2021-11-22 11:52 45% ` Timothy
2 siblings, 1 reply; 200+ results
From: Timothy @ 2021-11-21 14:09 UTC (permalink / raw)
To: org-mode-email
[-- Attachment #1: Type: text/plain, Size: 477 bytes --]
Hi All,
Since the contentious component of my previous patches has been the
`{{{results()}}}' prettification, I’ve prepared an alternate version that I’m
hoping everybody will be fairly happy with (fingers crossed!) that tosses out
the results prettification for now.
I think Protesilaos’ comments on making some new faces deserve consideration,
but could easily be done subsequently, as I’m quite keen to get this merged for
now.
All the best,
Timothy
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-org-src-Implement-native-inline-src-fontification.patch --]
[-- Type: text/x-patch, Size: 5149 bytes --]
From 53d2851e248c4f4e4076878a999cbf647b401578 Mon Sep 17 00:00:00 2001
From: TEC <tec@tecosaur.com>
Date: Tue, 13 Jul 2021 02:43:29 +0800
Subject: [PATCH] org-src: Implement native inline src fontification
* lisp/org-src.el (org-fontify-inline-src-blocks,
org-fontify-inline-src-blocks-1): Create a function to search the buffer
up to a limit for inline src blocks. Light fontification is applied to
matched inline src blocks. When `org-src-fontify-natively' is
set, `org-src-font-lock-fontify-block' is applied to the content.
* lisp/org.el (org-set-font-lock-defaults): Add
`org-fontify-inline-src-blocks' to `org-font-lock-extra-keywords', which
is locally bound inside `org-set-font-lock-defaults'.
(org-inline-src-fontify-max-length): Create a variable to limit the
maximum length of an inline-src block fontified, to protect from lag
spikes (e.g. when typing out src_lang{ and half of the buffer is
fontified).
---
lisp/org-src.el | 46 ++++++++++++++++++++++++++++++++++++++++++++++
lisp/org.el | 18 ++++++++++++++++++
2 files changed, 64 insertions(+)
diff --git a/lisp/org-src.el b/lisp/org-src.el
index 51dde602d..c3a6a40bc 100644
--- a/lisp/org-src.el
+++ b/lisp/org-src.el
@@ -654,6 +654,52 @@ (defun org-src-font-lock-fontify-block (lang start end)
'(font-lock-fontified t fontified t font-lock-multiline t))
(set-buffer-modified-p modified)))))
+(defun org-fontify-inline-src-blocks (limit)
+ "Try to apply `org-fontify-inline-src-blocks-1'."
+ (condition-case nil
+ (progn
+ (org-fontify-inline-src-blocks-1 limit)
+ (org-fontify-inline-src-results limit))
+ (error (message "Org mode fontification error in %S at %d"
+ (current-buffer)
+ (line-number-at-pos)))))
+
+(defun org-fontify-inline-src-blocks-1 (limit)
+ "Fontify inline src_LANG blocks, from `point' up to LIMIT."
+ (let ((case-fold-search t)
+ (initial-point (point)))
+ (when (re-search-forward "\\_<src_\\([^ \t\n[{]+\\)[{[]?" limit t) ; copied from `org-element-inline-src-block-parser'
+ (let ((beg (match-beginning 0))
+ (lang-beg (match-beginning 1))
+ (lang-end (match-end 1))
+ pt)
+ (font-lock-append-text-property lang-beg lang-end 'face 'org-meta-line)
+ (font-lock-append-text-property beg lang-beg 'face 'shadow)
+ (font-lock-append-text-property beg lang-end 'face 'org-block)
+ (setq pt (goto-char lang-end))
+ ;; `org-element--parse-paired-brackets' doesn't take a limit, so to
+ ;; prevent it searching the entire rest of the buffer we temporarily
+ ;; narrow the active region.
+ (save-restriction
+ (narrow-to-region beg (min (point-max)
+ limit
+ (+ lang-end org-inline-src-fontify-max-length)))
+ (when (ignore-errors (org-element--parse-paired-brackets ?\[))
+ (font-lock-append-text-property pt (point) 'face 'org-block)
+ (setq pt (point)))
+ (when (ignore-errors (org-element--parse-paired-brackets ?\{))
+ (remove-text-properties pt (point) '(face nil))
+ (font-lock-append-text-property pt (1+ pt) 'face '(org-block shadow))
+ (unless (= (1+ pt) (1- (point)))
+ (if org-src-fontify-natively
+ (org-src-font-lock-fontify-block
+ (buffer-substring-no-properties lang-beg lang-end)
+ (1+ pt) (1- (point)))
+ (font-lock-append-text-property (1+ pt) (1- (point)) 'face 'org-block)))
+ (font-lock-append-text-property (1- (point)) (point)'face '(org-block shadow))
+ (setq pt (point)))))
+ t)))
+
\f
;;; Escape contents
diff --git a/lisp/org.el b/lisp/org.el
index eeefb4af3..6a424991c 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -5279,6 +5279,23 @@ (defcustom org-allow-promoting-top-level-subtree nil
:version "24.1"
:group 'org-appearance)
+(defcustom org-inline-src-fontify-max-length 200
+ "Maximum content length of an inline src block that will be fontified.
+This is only relevant when `org-src-fontify-natively' is t."
+ :type 'integer
+ :package-version '(Org . "9.5")
+ :group 'org-appearance
+ :group 'org-babel)
+
+(defcustom org-inline-src-prettify-results t
+ "Whether to use (ab)use prettify-symbols-mode on {{{results(...)}}}.
+Either t or a cons cell of strings which are used as substitutions
+for the start and end of inline results, respectively."
+ :type '(choice boolean (cons string string))
+ :package-version '(Org . "9.5")
+ :group 'org-appearance
+ :group 'org-babel)
+
(defun org-fontify-meta-lines-and-blocks (limit)
(condition-case nil
(org-fontify-meta-lines-and-blocks-1 limit)
@@ -5785,6 +5802,7 @@ (defun org-set-font-lock-defaults ()
'(9 'org-special-keyword t))
;; Blocks and meta lines
'(org-fontify-meta-lines-and-blocks)
+ '(org-fontify-inline-src-blocks)
;; Citations
'(org-cite-activate))))
(setq org-font-lock-extra-keywords (delq nil org-font-lock-extra-keywords))
--
2.33.1
^ permalink raw reply related [relevance 49%]
* Dodgy Worg publishing? (was: [patch] Fix link to Library of Babel)
@ 2021-11-21 7:04 93% ` Timothy
0 siblings, 0 replies; 200+ results
From: Timothy @ 2021-11-21 7:04 UTC (permalink / raw)
To: Thomas S. Dye; +Cc: Bastien, emacs-orgmode
[-- Attachment #1: Type: text/plain, Size: 381 bytes --]
Hi Thomas,
Thanks for catching this problem. To me this looks more like a problem with the
worg publishing than an outdated link. I’ve cc’d Bastien as he’s much more
familiar with the Worg publish process than I am.
“Thomas S. Dye” <tsd@tsdye.online> writes:
> The attached patch changes a 404 link to the working link used on Worg.
All the best,
Timothy
^ permalink raw reply [relevance 93%]
* Re: [PATCH] org-src: Reset buffer-modified-p after fontifying
@ 2021-11-21 6:58 93% ` Timothy
0 siblings, 0 replies; 200+ results
From: Timothy @ 2021-11-21 6:58 UTC (permalink / raw)
To: Clément Pit-Claudel; +Cc: emacs-orgmode
Hi Clément,
I've just had a look at your patch, and it seems very reasonable to me.
Hence, I've just pushed it as ebd06c1 :)
> Hi all,
>
> * lisp/org-src.el (org-src-font-lock-fontify-block): Reset the
> modification flag of the temporary fontification buffer after
> fontifying.
>
> Without this some modes cause Emacs to prompt about unsaved buffers
> when exiting: `Save buffer *org-src-fontification:...-mode*?'
>
> (I'm seeing this with Proof General's coq-mode, specifically.)
>
> Clément.
>
> [2. text/x-patch; 0001-org-src-Reset-buffer-modified-p-after-fontifying.patch]...
--
Timothy
^ permalink raw reply [relevance 93%]
* Re: [PATCH] Accept more :tangle-mode specification forms
@ 2021-11-21 4:27 93% ` Timothy
0 siblings, 0 replies; 200+ results
From: Timothy @ 2021-11-21 4:27 UTC (permalink / raw)
To: Greg Minshall; +Cc: tomas, emacs-orgmode
[-- Attachment #1: Type: text/plain, Size: 508 bytes --]
Hi Greg,
> i’d push back, even here, on allowing decimal. file modes are bit
> masks. to me, offering a way to set a bit mask via a *decimal* value
> seems a mistake.
Just a quick note (see my long recent reply to Tim where I expand on this more),
but this isn’t new behaviour (isn’t actually affected by my recent changes) and
my concerns are with the viability of the necessary changes rather than whether
this would be good (we are of the same mind I think).
All the best,
Timothy
^ permalink raw reply [relevance 93%]
* Re: [PATCH] Accept more :tangle-mode specification forms
@ 2021-11-21 4:02 67% ` Timothy
0 siblings, 1 reply; 200+ results
From: Timothy @ 2021-11-21 4:02 UTC (permalink / raw)
To: Tim Cross; +Cc: emacs-orgmode
Hi Tim,
>> The parsing of “555” to the integer 555 is done by
>> org-babel-parse-header-arguments, and so can’t really be changed.
>
> I don't understand this. Why can't it be changed?
Well, it can't be changed without changing
org-babel-parse-header-arguments, which is quite a major change and I
suspect may be a breaking change.
Maybe it's fine? I just don't feel confident about this.
> When I said disable base 10 values, what I meant was generate an error
> if the value looks like it is base 10 i.e. does not have a leading o or
> #o. This makes it clear it has to be specified as an octal value and
> will alert users to this fact.
This is all well and good, but the point I'm making is that since due to
the current behaviour of org-babel-parse-header-arguments we can't
distinguish between :tangle-mode (identity #o555) and :tangle-mode 365
putting this idea /into practice/ doesn't look like it will be easy.
It's also worth noting that with regard to the recent changes that have
been made, this is not a new issue.
>> I think the ls-style is quite valuable for two reasons. It’s
>> well-established thanks to ls, and is particularly good for
>> understanding permissions at a glance.
>
> I would agree it is an established way to display the permissions
> associated with a filesystem object, but disagree it is a well
> established way to set such values - I know of no other tool which uses
> this format.
The driving motivation here is that while the tools which you mention do
not use this for setting permissions (e.g. chmod), they are only used
for /setting/ permissions. Since Org files aren't write-only, and
occasionally we go back and look at what we've written :P I think
allowing a format that is optimised for ease-of-reading instead of
ease-of-writing makes some sense. It is in this respect that I think
ls -l style is a good idea.
> It is also not the same as the ls -l display (no object
> type indicator). The ls -l also displays sticky bit, uid and gid. Does
> your format also support setting these values (something which can be
> done with the octal or symbolic formats) i.e. support s, S, t and T for
> the 'executable' bit for user/group?
Ah, I'm afraid that I'm not that up-together on sticky bits. I suspect
that it's not just the ls -l style that will need tweaking. I'll read up
on this in the next few days and update the ML.
> Personally, I prefer the symbolic form as it is shorter and clear. I
> find the ls -l form too easy to get wrong (especially with getting the
> number of '-' correct).
Isn't choice a great thing? :D In seriousness, this is exactly why I
think it's worth providing these options. At least thinking back to when
I started using Linux a few years ago I would have said the same thing
about the octal form, and was completely unfamiliar with chmod. I expect
different people to have different preferences with these three options,
but for one of them to be something most people are happy with.
>> Tim suggested that invalid forms should cause tangling to fail, but I feel this
>> may be a bit much. Personally I’m inclined to either
>> • warn, and don’t touch the file permissions (this is what currently occurs)
>> • use a very conservative file permission (e.g. rw——-).
>
> I'm unsure on this. My concern is people may not notice the warning and
> then be surprised later. Given the potential security issues, a later
> surprise is something to be avoided even if it is inconvenient. With
> respect to the default action to take, I would suggest we also need to
> look at the default umask setting for the user and if that is more
> restrictive, use that rather than some value like rw------- For all we
> know, the user has set a specific umask for a valid reason and will be
> surprised if emacs just ignores that to do what it wants (another
> surprise to be avoided).
> The user is not required to specify a mode. However, if they do and if
> we cannot interpret what they have specified without ambiguity, we
> should throw an error and cease processing. Making a guess as to what
> they intended in this situation is IMO a big mistake.
I don't see how using the default permissions is a potential security
risk? Could it surprise the user, yes, but that seems unavoidable when
the user is doing something invalid.
> My only preference for "#o" over just "o" prefix is to clearly signal to
> the user that it is an octal value and avoid the situation where you
> might glance a value and see the leading 'o' as a '0', missing the point
> it is an octal value not a decimal one. However, this seems like a low
> risk, so I'm happy either way.
Well, I've got "o" for now but that's not set in stone. With a lower
case "o" I feel the risk for confusion with "0" is quite low (besides
which a "0" prefix seems to be the C-style for octal anyway).
All the best,
Timothy
^ permalink raw reply [relevance 67%]
* Re: [PATCH] Accept more :tangle-mode specification forms
@ 2021-11-20 14:50 93% ` Timothy
0 siblings, 1 reply; 200+ results
From: Timothy @ 2021-11-20 14:50 UTC (permalink / raw)
To: tomas; +Cc: emacs-orgmode
[-- Attachment #1: Type: text/plain, Size: 1006 bytes --]
Hi Thomas (& co.),
>> […] I’m thinking either “o555” or “#o555” would be a good improvement over
>> “(identity #o555), but am open to other suggestions.
>
> That’s reasonable. I’d even tend to disallow decimal. In usage, it’s too
> exotic and the potential for someone entering “just a number” expecting
> for it to be read as octal is too high. Is it worth the risk?
I’ve just pushed three commits that
1. Add “o555” as an octal shorthand
2. Perform a simple check that integer modes are valid*
3. Make the ls-style regex stricter
> Timothy, I really admire your patience, and your incredibly friendly way
> of doing things :)
Thanks. It helps that this list is fairly friendly to begin with :)
All the best,
Timothy
* For example, “:tangle-mode 755” will now produce the warning:
“1363 is not a valid file mode octal. Did you give the decimal value 755 by
mistake?”. Maybe it would be worth adding “if so try o755” or similar?
^ permalink raw reply [relevance 93%]
* Re: [PATCH] Accept more :tangle-mode specification forms
@ 2021-11-20 8:08 60% ` Timothy
0 siblings, 2 replies; 200+ results
From: Timothy @ 2021-11-20 8:08 UTC (permalink / raw)
To: Tim Cross; +Cc: emacs-orgmode
[-- Attachment #1: Type: text/plain, Size: 3195 bytes --]
Hi Tom, Tim, Thomas, and Greg,
Thank you all for your thoughts. I’ll try to respond to all the main points
raised below.
First off, in case it wasn’t clear in my earlier email when I said “#o555 works”
or the like I was being lazy and really meaning “(identity #o555)” works.
The parsing of “555” to the integer 555 is done by
org-babel-parse-header-arguments, and so can’t really be changed. For a simple
octal notation our best bet is adding non-digit characters so it is left as a
string, e.g. “o555”.
┌────
│ 1 -> (org-babel-parse-header-arguments ":tangle-mode 555" light)
│ 1 <- org-babel-parse-header-arguments: ((:tangle-mode . 555))
│ ======================================================================
│ 1 -> (org-babel-parse-header-arguments ":tangle-mode o555" light)
│ 1 <- org-babel-parse-header-arguments: ((:tangle-mode . "o555"))
└────
So while I’d like it if we could easily apply Tom’s suggestion to “change the
radix for bare integers to 8 when reading that particular header”, I don’t think
that’s very feasible, unfortunately.
Giving errors when a base 10 value has been given by accident would be a nice
idea, but in practice isn’t easy as many base 10 values are valid octal values,
e.g. #o555 = 365. Likewise, I don’t think Tim’s suggestion of disallowing base
10 values is feasible.
Regarding the concern that “we are making a rod for our back by trying to make
this overly clever” and that the change makes it too complex — I disagree.
Having had this discussion earlier we’ve ended up with,
• a shorthand for octal
• ls-style
• chmod-style
I think this small collection of distinct and simple input methods isn’t overly
clever or complex, and feel that it strikes the right balance between too many
options and too little flexibility.
Octal is great, for those that are familiar with it. Likewise, chmod-style is
quite natural for those who are used to chmod. There’s little added complexity
to the Org code base as we simply pass this to the Emacs function
file-modes-symbolic-to-number. I think the ls-style is quite valuable for two
reasons. It’s well-established thanks to ls, and is particularly good for
understanding permissions at a glance. For reading Org files I think this is
advantageous compared to the other styles. I’m don’t find assertions that this
is non-typical or unpredictable well-founded. Each style/syntax is well-defined,
simple, distinct, and taken from very common/wide spread usage.
Tim suggested that invalid forms should cause tangling to fail, but I feel this
may be a bit much. Personally I’m inclined to either
• warn, and don’t touch the file permissions (this is what currently occurs)
• use a very conservative file permission (e.g. rw——-).
So, as I see it the main decision that needs to be made is how to handle the
octal shorthand, now that it’s clear that the original plan is flawed? I’m
thinking either “o555” or “#o555” would be a good improvement over “(identity
#o555), but am open to other suggestions.
All the best,
Timothy
^ permalink raw reply [relevance 60%]
* Re: [PATCH] Accept more :tangle-mode specification forms
2021-11-18 10:20 93% ` Timothy
@ 2021-11-18 17:22 87% ` Timothy
0 siblings, 1 reply; 200+ results
From: Timothy @ 2021-11-18 17:22 UTC (permalink / raw)
To: Org Mode List
[-- Attachment #1: Type: text/plain, Size: 842 bytes --]
Hi All,
I thought I’d checked for this, but I’ve just noticed that :tangle-mode 755
doesn’t actually work as expected. I assumed 755 would be passed as a string but
org-babel-parse-header-arguments actually turns it into an integer, just like
(identity #o755). Obviously 755 != #o755 and so this causes issues.
As it stands “755” works, but that isn’t great (most importantly, it’s easy to
confuse). Since it’s easier to add than remove things like this, we could just
get rid of this for now, but a convenient octal notation was a large chunk of
the motivation here IIRC.
We could also change the implementation to handle :tangle-mode o755, which will
make org-babel-parse-header-arguments parse the argument as a string.
I’m be keen to hear other people’s thoughts on this.
All the best,
Timothy
^ permalink raw reply [relevance 87%]
* Re: [PATCH] org.el (org-display-inline-image--width): Small fix
@ 2021-11-18 12:06 93% ` Timothy
0 siblings, 0 replies; 200+ results
From: Timothy @ 2021-11-18 12:06 UTC (permalink / raw)
To: emacs-orgmode
Just marking this patch as applied for updates.orgmode.org.
Nicolas Goaziou <mail@nicolasgoaziou.fr> writes:
> Hello,
>
> Sébastien Miquel <sebastien.miquel@posteo.eu> writes:
>
>> Subject: [PATCH] org.el (org-display-inline-image--width): Small fix
>
> I expounded the commit message and applied your patch. Thank you.
>
> Regards,
^ permalink raw reply [relevance 93%]
* Re: [PATCH] Treat :tangle-mode as an octal value not integer
@ 2021-11-18 12:04 93% ` Timothy
0 siblings, 0 replies; 200+ results
From: Timothy @ 2021-11-18 12:04 UTC (permalink / raw)
To: emacs-orgmode
Just removing this from updates.orgmode.org.
^ permalink raw reply [relevance 93%]
* Re: [PATCH] ob-R async evaluation
@ 2021-11-18 10:36 93% ` Timothy
0 siblings, 0 replies; 200+ results
From: Timothy @ 2021-11-18 10:36 UTC (permalink / raw)
To: Jeremie Juste; +Cc: emacs-orgmode
Hi Jeremie,
Sorry it's taken a while to get to this. I've just gone through your
patch and it looks quite reasonable. I also took the liberty of
fixing the indentation in a few spots and tweaking your commit message.
This has just been pushed as 58db28d.
> I'm attaching a patch that clean up a bit of non conventional coding
> practices (mainly because of my ignorance), in ob-R. These were
> initially generating warning during the compilation of org-mode.
By the way, just letting you know that your mail client declared your
.patch to be a PDF file 😛.
> [2. application/pdf; 0001-ob-R.el-Patch-4-async-evaluation.patch]...
--
Timothy
^ permalink raw reply [relevance 93%]
* Re: [PATCH] Accept more :tangle-mode specification forms
2021-10-05 14:45 93% ` Timothy
@ 2021-11-18 10:20 93% ` Timothy
2021-11-18 17:22 87% ` Timothy
1 sibling, 1 reply; 200+ results
From: Timothy @ 2021-11-18 10:20 UTC (permalink / raw)
To: Org Mode List
Hi All,
This has just been pushed as described in fa97f9a39.
See some tests I performed before pushing below.
#+begin_src text :tangle-mode (identity #o345) :tangle t1.txt
this works
#+end_src
#+begin_src text :tangle-mode 433 :tangle t2.txt
this works
#+end_src
#+begin_src text :tangle-mode u+x :tangle t3.txt
this works
#+end_src
#+begin_src text :tangle-mode rw-r--r-- :tangle t4.txt
this works
#+end_src
#+begin_src text :tangle-mode hey :tangle t5.txt
invalid, error message given
#+end_src
--
Timothy
^ permalink raw reply [relevance 93%]
* Re: [PATCH] org-manual.org: org-cite additions
@ 2021-11-18 8:08 93% ` Timothy
0 siblings, 0 replies; 200+ results
From: Timothy @ 2021-11-18 8:08 UTC (permalink / raw)
To: Bruce D'Arcus; +Cc: emacs-orgmode
Hi Bruce,
Thanks for this patch. I've had a read through and it all looks good to
me. I've just applied this with minor tweaks as 30dbfc6.
> This is a minor patch to address the most obvious missing pieces that
> have confused people.
--
Timothy
^ permalink raw reply [relevance 93%]
* Re: Subject: [PATCH] Fix DISPLAY error on exporting org with plantuml to html
@ 2021-11-18 7:38 92% ` Timothy
0 siblings, 1 reply; 200+ results
From: Timothy @ 2021-11-18 7:38 UTC (permalink / raw)
To: Sun Lin; +Cc: emacs-orgmode
Hi Sun,
> [snipped patch description]
> Please help review the patch. Thanks.
> [2. text/x-patch; 0001-Fix-DISPLAY-error-on-exporting-org-with-plantuml-to-.patch]...
Thanks for your patience. This looks quite straight-forward. I don't use
or have plantuml so I'm in a poor position to test.
However, I can use google, and it seems that -Djava.awt.headless=true
just uses Java for some graphics operations which are normally delegated
to the system graphics stack.
This seems rather safe to me, and so I'd be inclined to take your word
that this is a beneficial change and merge the patch.
All the best,
Timothy
^ permalink raw reply [relevance 92%]
* Re: [PATCH] Prevent displayed images from being re-scaled
2021-10-02 20:30 93% ` Timothy
@ 2021-10-25 13:49 93% ` Timothy
0 siblings, 0 replies; 200+ results
From: Timothy @ 2021-10-25 13:49 UTC (permalink / raw)
To: Org-Mode Mailing List
[-- Attachment #1: Type: text/plain, Size: 70 bytes --]
It’s been quite a few days, so I’ve just pushed this as 9dc08c9.
^ permalink raw reply [relevance 93%]
* Re: [PATCH] Rename headline to heading
@ 2021-10-15 9:56 93% ` Timothy
0 siblings, 0 replies; 200+ results
From: Timothy @ 2021-10-15 9:56 UTC (permalink / raw)
To: André A. Gomes; +Cc: Bastien, emacs-orgmode
[-- Attachment #1: Type: text/plain, Size: 382 bytes --]
Hi André,
I haven’t gone through the patches you’ve sent, but it looks like you’ve put a
tremendous amount of effort into this! It’s fantastic to see. I think I can
speak for the Org community when I say thank you.
André A. Gomes <andremegafone@gmail.com> writes:
> Hi Bastien and All,
>
> This is a first attempt towards the goal.
All the best,
Timothy
^ permalink raw reply [relevance 93%]
* Re: [PATCH] Accept more :tangle-mode specification forms
@ 2021-10-05 16:13 93% ` Timothy
0 siblings, 0 replies; 200+ results
From: Timothy @ 2021-10-05 16:13 UTC (permalink / raw)
To: unknown@email.com; +Cc: emacs-orgmode
[-- Attachment #1: Type: text/plain, Size: 326 bytes --]
Hi Jeremy,
> I think this is a good idea and don’t see any problems (or other
> suggestions) with the proposed formats.
>
> The existing (identity #o0755) will still function, correct?
> i.e. backward compatibility.
It should yes. I’ll double check before I actually push the commit.
All the best,
Timothy
^ permalink raw reply [relevance 93%]
* Re: [PATCH] Accept more :tangle-mode specification forms
2021-09-30 18:14 52% [PATCH] Accept more :tangle-mode specification forms Timothy
@ 2021-10-05 14:45 93% ` Timothy
2021-11-18 10:20 93% ` Timothy
1 sibling, 2 replies; 200+ results
From: Timothy @ 2021-10-05 14:45 UTC (permalink / raw)
To: Org Mode List
[-- Attachment #1: Type: text/plain, Size: 841 bytes --]
Hi Everyone,
It feels like we’re near a patch that would be good to merge. I would very much
like to get feedback on what I proposed in my reply to Tom though (see below).
>> That said, reducing the number of forms as Eric suggests would
>> be a happy medium.
>
> Indeed, I’ve basically supported every form I could think of. I’m currently
> inclined to cut it down to:
> • 755
> • “rwxrw-r–” (`ls -l’ style)
> • chmod style with `org-babel-tangle-default-mode’ and `file-modes-symbolic-to-number’
>
> Maybe with (if anybody says they would like this)
> • #o755 (elisp octal)
> • 0755 (C octal)
> • “rwx” = user perm, bit-or’d with `org-babel-tangle-default-mode’ for the rest
> (i.e. `org-babel-tangle-default-mode’, but not exceeding the user perm)
All the best,
Timothy
^ permalink raw reply [relevance 93%]
* Re: [PATCH] Don't fill displayed equations
@ 2021-10-04 7:15 93% ` Timothy
0 siblings, 0 replies; 200+ results
From: Timothy @ 2021-10-04 7:15 UTC (permalink / raw)
To: Tom Gillespie; +Cc: Org Mode List
[-- Attachment #1: Type: text/plain, Size: 764 bytes --]
Hi Tom,
> From time to time I encounter random patterns that I don’t want to be
> reformatted during a fill operation. Maybe a custom variable like
> org-fill-paragraph-skip-regexp or similar that could be set by the user?
> For Timothy’s use case he would set it to the regexp provided in the
> original patch? Not sure how much of the implementation in the patch
> is dependent on that particular regexp, but a general solution that
> could even be set per org file might be a very useful new feature.
Hmmm, that’s an interesting idea. I suppose you could have something like a list
of cons cells where the car is a regexp matching the start of the “don’t touch”
region and the cdr a regexp matching the end.
All the best,
Timothy
^ permalink raw reply [relevance 93%]
* Re: [PATCH] Don't fill displayed equations
2021-09-30 20:45 63% ` Timothy
@ 2021-10-04 6:05 83% ` Timothy
1 sibling, 1 reply; 200+ results
From: Timothy @ 2021-10-04 6:05 UTC (permalink / raw)
To: Org Mode List
Hi All,
Given the way the conversation has evolved I think it may be worth revisiting
another viewpoint to see if anybody has any nice ideas.
As things are, regardless of the complexities of parsing and inline vs.
block elements etc., just considering the user experience when running
org-fill on an example like the one below, the behaviour isn't /nice/.
Might there be some way we could allow for people who are used to LaTeX
and/or like \[ ... \] to have fill behaviour that leaves \[ ... \]
blocks alone? My original idea was changing how org-fill works for
everyone, the discussion has gone on to changing \[ ... \] to a block
element -- both of these seem to have rather significant issues.
Ihor came up with the idea of making org-fill something more
customisable by the user, so that someone could have this behaviour
without making Org behave un-idiomatically for everyone. I proposed
maybe just having a setting could be a halfway house between my original
patch and his idea.
Does anybody have any other thoughts?
> If you’re wondering why I’m so opposed to the current behaviour, that is probably
> best explained by a more realistic demo that what I have in the commit message.
>
> ┌────
> │ Since \(\cos\) is an even function, we can negate the numerator of the argument
> │ without changing the result, giving
> │ \[
> │ \cos \left( \pi \frac{C_1-x}{2C_1+D} \right) \ , \quad C_1 = \frac{D}{2}.
> │ \]
> │ this will be positive over \(x \in (0,D)\), and so we can rewrite \(\tilde{y}\) as,
> │ \[
> │ \tilde{y}(x) = \frac{2D}{\pi} \log \cos \left( \pi \frac{\frac{D}{2}-x}{2D} \right) + C_2.
> │ \]
> │ Once again considering that \(y(0)=y(D)=0\), it is clear that
> │ \[
> │ C_2 = - \frac{2D}{\pi} \log \cos \left( \frac{\pi}{4} \right) = - \frac{2D}{\pi} \log 2^{-\frac{1}{2}} = \frac{D}{\pi} \log 2.
> │ \]
> │ The complete solution for \(\tilde{y}\) is hence,
> │ \[
> │ \tilde{y} = \frac{2D}{\pi} \log \cos \left( \pi \frac{D-2x}{4D} \right) + \frac{D}{\pi} \log 2.
> │ \]
> └────
> is currently filled to
> ┌────
> │ Since \(\cos\) is an even function, we can negate the numerator of the argument
> │ without changing the result, giving \[ \cos \left( \pi \frac{C_1-x}{2C_1+D}
> │ \right) \ , \quad C_1 = \frac{D}{2}. \] this will be positive over \(x \in (0,D)\),
> │ and so we can rewrite \(\tilde{y}\) as, \[ \tilde{y}(x) = \frac{2D}{\pi} \log \cos \left( \pi
> │ \frac{\frac{D}{2}-x}{2D} \right) + C_2. \] Once again considering that
> │ \(y(0)=y(D)=0\), it is clear that \[ C_2 = - \frac{2D}{\pi} \log \cos \left(
> │ \frac{\pi}{4} \right) = - \frac{2D}{\pi} \log 2^{-\frac{1}{2}} = \frac{D}{\pi} \log 2.
> │ \] The complete solution for \(\tilde{y}\) is hence, \[ \tilde{y} = \frac{2D}{\pi} \log \cos
> │ \left( \pi \frac{D-2x}{4D} \right) + \frac{D}{\pi} \log 2. \]
> └────
--
Timothy
^ permalink raw reply [relevance 83%]
* Re: [PATCH] Don't fill displayed equations
@ 2021-10-03 9:42 93% ` Timothy
0 siblings, 0 replies; 200+ results
From: Timothy @ 2021-10-03 9:42 UTC (permalink / raw)
To: Ihor Radchenko; +Cc: Org Mode List, Nicolas Goaziou
[-- Attachment #1: Type: text/plain, Size: 304 bytes --]
Hi Ihor,
> Then would you mind proposing a patch for org-fill-element in
> particular? At least, you seem to have a motivation for this particular
> function ;)
Perhaps in a few weeks, for now I’m a bit to busy for anything other than
“accidental” 😛 patches.
All the best,
Timothy
^ permalink raw reply [relevance 93%]
* Re: [PATCH] Fontification for inline src blocks
@ 2021-10-03 9:22 83% ` Timothy
0 siblings, 0 replies; 200+ results
From: Timothy @ 2021-10-03 9:22 UTC (permalink / raw)
To: Ihor Radchenko; +Cc: Protesilaos Stavrou, org-mode-email
[-- Attachment #1: Type: text/plain, Size: 1864 bytes --]
Hi Ihor,
> What about separating the src_{nil} fontification into separate patch? I
> think that part raised no objections.
That sounds like a good idea to me. We may as well get that in.
> As for the results prettifications, I look at this and similar ideas as
> at Emacs themes. It looks nice on your screenshot with your fonts and
> colours, but may not be good for other people. Similar to org-bullets
> and co.
The behaviour makes me think of link prettification more than what Emacs themes
do. Hiding the text {{{results( with an overlay seems like something a
major/minor mode should be responsible for, not a theme.
> I can see how some people (I am among those people) want to reduce the
> markup noise beyond hiding emphasis markers. However, some people
> prefer not to hide text in buffer under “bells and whistles”.
Indeed, and it’s good to have this option. This is why I also introduced a new
setting, `org-inline-src-prettify-results' (similarly named to
`org-pretty-entities').
> Maybe we can create some kind of “prettify-symbol themes” replacing different
> markup elements in bulk with nice symbols/svg (e.g. inline results, block
> headers/footers, uninteresting property drawers aka org-custom-properties,
> bullets, etc)? WDYT? Also, CCing Prot as it might be of interest for him.
> Best, Ihor
I think it could make sense for some prettification capabilities to be built
into Org well. Currently there are a few little things we have, but it seems to
be handled inconsistently and I think it could be nice to provide a more unified
approach. There are also things like
<https://github.com/awth13/org-appear/blob/master/org-appear.el> which I feel just
make a lot of sense with Org (you never have to guess if `point' is before or
after a markup character).
All the best,
Timothy
^ permalink raw reply [relevance 83%]
* Re: [PATCH] Don't fill displayed equations
@ 2021-10-03 9:14 93% ` Timothy
0 siblings, 1 reply; 200+ results
From: Timothy @ 2021-10-03 9:14 UTC (permalink / raw)
To: Ihor Radchenko; +Cc: Org Mode List, Nicolas Goaziou
[-- Attachment #1: Type: text/plain, Size: 568 bytes --]
Ihor Radchenko <yantar92@gmail.com> writes:
> I personally would prefer modular function as a whole. For my taste,
> Org code has too much of (case (variant 1) (variant 2) …)-style
> functions (i.e. org-todo, org-cycle, org-ctrl-c-ctrl-c, org-store-link,
> etc) and they are a pain to debug and advice for users.
Mmmm, I’m with you on this in general. I also think the code base has far too
many monolithic “200 line” functions which are crying out to be split up.
Now if I could just clone myself once or twice… 😛
All the best,
Timothy
^ permalink raw reply [relevance 93%]
* Re: [PATCH] Don't fill displayed equations
@ 2021-10-03 8:50 93% ` Timothy
0 siblings, 1 reply; 200+ results
From: Timothy @ 2021-10-03 8:50 UTC (permalink / raw)
To: Ihor Radchenko; +Cc: Org Mode List, Nicolas Goaziou
[-- Attachment #1: Type: text/plain, Size: 525 bytes --]
Hi Ihor,
> What about making org-fill-element modular? We may define separate fill
> functions for different elements and let the user override them
> individually if the user prefer so. It may be implemented similar to
> export functionality with customisable formatters for different
> elements.
Thanks for that idea. Perhaps something along those lines may be the best
solution here. If we don’t want to make the whole function modular, perhaps we
could make a setting for this?
All the best,
Timothy
^ permalink raw reply [relevance 93%]
* Re: [PATCH] Fontification for inline src blocks
@ 2021-10-03 7:16 93% ` Timothy
0 siblings, 1 reply; 200+ results
From: Timothy @ 2021-10-03 7:16 UTC (permalink / raw)
To: Ihor Radchenko; +Cc: org-mode-email
Ihor Radchenko <yantar92@gmail.com> writes:
> Let me bump this thread again and mark it as a patch ;)
Thanks for the bump. I'd like to get this working, but I don't know how best to
deal with the "prettification" of {{{results(=value=)}}}, which is the major blocker as I
see it.
Other than that, this all works fantastically as far as I can tell from a few
months of usage of my branch of Org 🙂.
--
Timothy
^ permalink raw reply [relevance 93%]
* Re: [PATCH] Prevent displayed images from being re-scaled
@ 2021-10-03 5:45 93% ` Timothy
0 siblings, 0 replies; 200+ results
From: Timothy @ 2021-10-03 5:45 UTC (permalink / raw)
To: Bastien; +Cc: Org-Mode Mailing List
[-- Attachment #1: Type: text/plain, Size: 291 bytes --]
Bastien <bzg@gnu.org> writes:
> Nitpick: I suggest shortening the ChangeLog part like this:
> *snip*
> The ChangeLog part should not be too verbose, you can add explanations
> after it.
Thanks Bastien, I’ll use that message when I push the commit 👍.
All the best,
Timothy
^ permalink raw reply [relevance 93%]
* Re: [PATCH] Prevent displayed images from being re-scaled
2021-09-29 13:33 71% [PATCH] Prevent displayed images from being re-scaled Timothy
@ 2021-10-02 20:30 93% ` Timothy
2021-10-25 13:49 93% ` Timothy
1 sibling, 1 reply; 200+ results
From: Timothy @ 2021-10-02 20:30 UTC (permalink / raw)
To: Org-Mode Mailing List
[-- Attachment #1: Type: text/plain, Size: 119 bytes --]
Hi All,
I intend to push this in the next few days, assuming I don’t get any feedback.
All the best,
Timothy
^ permalink raw reply [relevance 93%]
* Re: [PATCH] Don't fill displayed equations
@ 2021-10-02 18:28 93% ` Timothy
0 siblings, 0 replies; 200+ results
From: Timothy @ 2021-10-02 18:28 UTC (permalink / raw)
To: Tom Gillespie; +Cc: Max Nikulin, emacs-orgmode
[-- Attachment #1: Type: text/plain, Size: 1148 bytes --]
Hi Tom,
> The answer is that can only occur inside paragraphs. The issues
> here are exactly the same as the issues for inline footnotes. Org gives
> us a bit more power, but not the full power because Org is Org, not
> Latex. Making available outside of a paragraph would be a massive
> breaking change.
>
> In Timothy’s original example he is narrowly skirting the syntax to
> allow that all to remain a single paragraph, but stick in a newline
> anywhere and boom, no more paragraph, no more equation.
I don’t understand what you’re talking about here. You can already use `\[ ... \]'
outside a paragraph, e.g.
┌────
│ blah blah blah
│
│ \[
│ not part of a paragraph
│ \]
│
│ blah blah blah
└────
I also don’t see how footnotes are analogous, as footnotes are placed in the
middle of a line of text.
If you could explain your thoughts here a bit more, that would be appreciated.
> I guess one thing I’m missing/not understanding is when/why people
> want to use instead of full #+begin_export latex block?
org-latex-preview :)
All the best,
Timothy
^ permalink raw reply [relevance 93%]
* Re: [PATCH] Don't fill displayed equations
@ 2021-10-02 11:24 93% ` Timothy
0 siblings, 1 reply; 200+ results
From: Timothy @ 2021-10-02 11:24 UTC (permalink / raw)
To: Nicolas Goaziou; +Cc: Org Mode List
[-- Attachment #1: Type: text/plain, Size: 487 bytes --]
Hi Nicolas,
> *snip lots of text*
Thanks for going through my points in detail. I think I understand your
perspective much better now. At this point though, I’m not really sure what to
make of `\[ ... \]', I now feel like it’s sitting in some sort of markup limbo
where it can’t be either fully LaTeX-y or fully Org-y. I still think it would be
good to improve this, but I no longer have such a firm idea that “modifying fill
is the way”.
All the best,
Timothy
^ permalink raw reply [relevance 93%]
* Re: [PATCH] Don't fill displayed equations
@ 2021-10-02 10:18 83% ` Timothy
0 siblings, 1 reply; 200+ results
From: Timothy @ 2021-10-02 10:18 UTC (permalink / raw)
To: Eric S Fraga; +Cc: emacs-orgmode, Nicolas Goaziou
[-- Attachment #1: Type: text/plain, Size: 1220 bytes --]
Hi Eric,
>> text
>> 1+1=3
>> text
>>
>> is a single paragraph in LaTeX.
> This is true and probably the most convincing argument in this debate.
I can’t help but think that this line of thinking is a bit of a trap, because
what LaTeX’s idea of a paragraph does not line up with Org’s. I think the more
pertinent consideration is that `\[ ... \]' changes LaTeX into vertical mode,
which does not allow for any other content on the ’line’ — which is far
closer to Org’s concept of a block element than an inline element.
Frankly, I think the issue is that the semantics of `\[ ... \]' simply don’t play
well with Org. Unfortunately, due to the Org/LaTeX difference I don’t see any
ideologically “pure” way we can have it in Org. The most idiomatic solution
would be to just remove support for `\[ ... \]' *. Otherwise, we have to treat
`\[ ... \]' specially in if we want ’sensible’ behaviour — as I mention in my
reply to Nicolas, we’re already parsing it differently to other inline markup…
All the best,
Timothy
* However, I am not advocating for this: There’s both the obvious comparability
issue, but I also rather like using `\[ ... \]' myself.
^ permalink raw reply [relevance 83%]
* Re: [PATCH] Accept more :tangle-mode specification forms
@ 2021-10-01 18:14 82% ` Timothy
0 siblings, 0 replies; 200+ results
From: Timothy @ 2021-10-01 18:14 UTC (permalink / raw)
To: Tom Gillespie; +Cc: tomas, emacs-orgmode, mail
[-- Attachment #1: Type: text/plain, Size: 1255 bytes --]
Hi Tom,
Thanks for going through the replies so far and refining your thoughts.
> *snip a whole bunch of comments*
I think I’m of the same mind as you that if we try to mentally separate Org the
markup format and Org the emacs mode, the format should not specify the
interpretation of the :tangle-mode value.
I think the best way to have it would be,
⁃ Org the format, :tangle-mode takes a value representing the file permissions
the tangled file should have. Optional: here are some common examples that
might be recognised
⁃ Org the emacs mode, :tangle-mode’s value is interpreted like so (…)
> That said, reducing the number of forms as Eric suggests would
> be a happy medium.
Indeed, I’ve basically supported every form I could think of. I’m currently
inclined to cut it down to:
• 755
• “rwxrw-r–” (`ls -l' style)
• chmod style with `org-babel-tangle-default-mode' and `file-modes-symbolic-to-number'
Maybe with (if anybody says they would like this)
• #o755 (elisp octal)
• 0755 (C octal)
• “rwx” = user perm, bit-or’d with `org-babel-tangle-default-mode' for the rest
(i.e. `org-babel-tangle-default-mode', but not exceeding the user perm)
All the best,
Timothy
^ permalink raw reply [relevance 82%]
* Re: [PATCH] Don't fill displayed equations
@ 2021-10-01 7:43 69% ` Timothy
1 sibling, 1 reply; 200+ results
From: Timothy @ 2021-10-01 7:43 UTC (permalink / raw)
To: Nicolas Goaziou; +Cc: Org Mode List
Nicolas Goaziou <mail@nicolasgoaziou.fr> writes:
> Timothy <tecosaur@gmail.com> writes:
>
>> I think there are also some relevant points which I haven’t mentioned so far,
>> separate from my thoughts that since we’re using the LaTeX syntax we should be
>> consistent with how LaTeX treats this.
>
> I'm not convinced about this. I don't think it is even possible.
By this, I'm specifically thinking of the fact that \( ... \) is inline,
and \[ ... \] is a display equation. What's the point of Org having both
if they're treated the same in "org syntax", on top of the inconstancy
that creates with HTML, LaTeX exports etc. where it is once again
treated as a display equation? Perhaps the discussion should shift from
my specific patch to this general situation, but this behaviour feels
wrong to me.
>>> As I wrote above, they do not belong to the same category of syntax.
>>> There’s no reason to special case ....
>>
>> I think we already do special-case `\[ ... \]' somewhat. When refer to inline
>> elements like bold, verbatim, italic, etc. they sit in the text. Semantically,
>> this doesn’t hold for `\[ ... \]' either. The semantically inline maths element is
>> `\( ... \)'. Considering other “inline” syntax elements, like bold, verbatim,
>> italic, etc. if you spread the delimiters across multiple lines that doesn’t
>> work. So I’d argue the ship has already sailed on treating `\[ ... \]' differently
>> to other inline elements.
>
> I'm not sure about what you mean. \[...\] is no different than, e.g.,
> verbatim. It's an inline element, with all that it implies.
Is it? I can't use verbatim like this:
=
some
verbatim
text
=
but I can do
\[
some
display
equation
\]
It seems to me that \[ ... \] is already treated differently from other
inline markup.
> Now, if you want to discuss changing syntax for \[...\] and make it
> a block element, you can of course do it to your heart's content (it has
> been discussed already in this ML and I don't have an opinion on the
> subject), but please don't make filling do bizarre things (not all Org
> users use LaTeX or even like LaTeXisms), just because LaTeX modes behave
> differently.
If that's the only way that Org could treat \[ ... \] differently from
\( ... \), I'd be strongly in favour of this.
>> If you’re wondering why I’m so opposed to the current behaviour, that is probably
>> best explained by a more realistic demo that what I have in the commit message.
>> [*snip*]
> In every case above, you can already use
> \begin{equation*}...\end{equation*}, so I don't see the point.
I prefer \[ ... \] over \begin{equation*}...\end{equation*} as it's much
more succinct, and helps reduce the "markup noise" in my documents. I
don't think this is an insignificant concern, brevity may not be
something I'm very good at in emails 😛 but is something I look for in
syntax.
> You already have all you need without breaking filling function for
> the rest of us.
I must admit, I don't see the downside here --- how does this break the
filling function for the rest of you? This only affects \[ ... \] blocks
that have already been put on their own line.
> I don't think it is a worse experience, unless you apply expectations
> from LaTeX to Org. It just doesn't work.
Why can't we apply LaTeX expectations to LaTeX elements in Org? Applying
LaTeX expectations to Org as a whole is clearly a silly idea, but Org
copies \[ .. \] from LaTeX and it is a LaTeX construct.
> Notwithstanding filling behaviour, \[...\] in Org is much more limited
> than \[...\] in LaTeX.
I'd be curious to hear how, as I personally haven't run into any
instances where \[ ... \] has behaved differently other than when an
environment starts on a new line in of a \[ ... \] block (which can
easily be fixed by putting something like \!\ at the start of the line).
> If you need to write or copy "advanced" LaTeX code, Org provides
> dedicated environments.
I don't want "advanced" LaTeX code, I just want my display equations to
be treated as display equations consistently 😂.
Anyway, thanks for engaging with this Nicolas. Even if my patch is a bad
idea, I hope that by the end of this conversation we may arrive at an
agreement on how \[ ... \] should be treated.
--
Timothy
^ permalink raw reply [relevance 69%]
* Re: [PATCH] Accept more :tangle-mode specification forms
@ 2021-10-01 6:59 71% ` Timothy
0 siblings, 1 reply; 200+ results
From: Timothy @ 2021-10-01 6:59 UTC (permalink / raw)
To: Tom Gillespie; +Cc: Org Mode List
[-- Attachment #1: Type: text/plain, Size: 2738 bytes --]
Hi Tom,
Thanks for giving me your thoughts on this. I have a few thoughts in response :)
> I strongly oppose this patch. It adds far too much complexity to the
> org grammar. Representation of numbers is an extremely nasty part of
> nearly every language, and I suggest that org steer well clear of
> trying to formalize this.
I’m not quite sure I see your point here, as I don’t see how this affects the
grammar of Org at all. The :attribute value syntax is unaffected, this just
changes how a particular :attribute’s value is interpreted. Attribute specific
interpretation is normal, with “:file ~/hello” you expect `~' to be interpreted as
`$HOME', but were I to give “:session ~/hello” I would not expect `~' to be
expanded etc.
Similarly, with regard to the representation of numbers, I’m not sure that
applies here, as the value is still a string not a number, it’s just
interpreted. Arguably, we’re not even representing numbers here but representing
file permissions which are currently abstracted by a numerical representation.
> With an eye to future portability I suggest that no special cases be given to
> [snipped for later] tangle mode without very careful consideration.
Mmmm, we defiantly want to think about what options we allow for, but I don’t
think that precludes us from accepting more than one common permissions
representations.
> [the snip]: something as important for security as tangle mode
Thank you for considering potential security implications, this is something
that I didn’t consider when writing the patch, but if we allow for a confusing
format that could deceive people into tangling files in modes they didn’t
realise they were tangling to.
I think there are two relevant points here
⁃ If we only allow very widely-understood, standard representations, I think the
risk of people misunderstanding a :tangle-mode value is acceptably low
⁃ If you consider things this way, since arbitrary lisp closures are currently
permitted, one can already trivially create a much more misleading
:tangle-mode value with the current code.
> Emacs lisp closures have clear semantics in Org and the number syntax is clear
See my earlier comments on the semantics being unaffected, and this not being a
number syntax.
> If users are concerned about the verbosity of (identity #o0600) they could go
> with the sorter (or #o0600).
Perhaps, but I personally find it easier to interpret “rwxr-xr–” for example
than “(or #o754)”, and I feel quite confident in guessing that
a. I’m not alone
b. Nobody that understands “#o754” will have difficult understanding “rwxr-xr–”
All the best,
Timothy
^ permalink raw reply [relevance 71%]
* Re: [PATCH] Don't fill displayed equations
2021-09-30 19:28 93% ` Timothy
@ 2021-09-30 20:45 63% ` Timothy
2021-10-04 6:05 83% ` Timothy
1 sibling, 2 replies; 200+ results
From: Timothy @ 2021-09-30 20:45 UTC (permalink / raw)
To: Nicolas Goaziou; +Cc: Org Mode List
[-- Attachment #1: Type: text/plain, Size: 3095 bytes --]
Hi Nicolas,
I think there are also some relevant points which I haven’t mentioned so far,
separate from my thoughts that since we’re using the LaTeX syntax we should be
consistent with how LaTeX treats this.
> As I wrote above, they do not belong to the same category of syntax.
> There’s no reason to special case ....
I think we already do special-case `\[ ... \]' somewhat. When refer to inline
elements like bold, verbatim, italic, etc. they sit in the text. Semantically,
this doesn’t hold for `\[ ... \]' either. The semantically inline maths element is
`\( ... \)'. Considering other “inline” syntax elements, like bold, verbatim,
italic, etc. if you spread the delimiters across multiple lines that doesn’t
work. So I’d argue the ship has already sailed on treating `\[ ... \]' differently
to other inline elements.
If you’re wondering why I’m so opposed to the current behaviour, that is probably
best explained by a more realistic demo that what I have in the commit message.
┌────
│ Since \(\cos\) is an even function, we can negate the numerator of the argument
│ without changing the result, giving
│ \[
│ \cos \left( \pi \frac{C_1-x}{2C_1+D} \right) \ , \quad C_1 = \frac{D}{2}.
│ \]
│ this will be positive over \(x \in (0,D)\), and so we can rewrite \(\tilde{y}\) as,
│ \[
│ \tilde{y}(x) = \frac{2D}{\pi} \log \cos \left( \pi \frac{\frac{D}{2}-x}{2D} \right) + C_2.
│ \]
│ Once again considering that \(y(0)=y(D)=0\), it is clear that
│ \[
│ C_2 = - \frac{2D}{\pi} \log \cos \left( \frac{\pi}{4} \right) = - \frac{2D}{\pi} \log 2^{-\frac{1}{2}} = \frac{D}{\pi} \log 2.
│ \]
│ The complete solution for \(\tilde{y}\) is hence,
│ \[
│ \tilde{y} = \frac{2D}{\pi} \log \cos \left( \pi \frac{D-2x}{4D} \right) + \frac{D}{\pi} \log 2.
│ \]
└────
is currently filled to
┌────
│ Since \(\cos\) is an even function, we can negate the numerator of the argument
│ without changing the result, giving \[ \cos \left( \pi \frac{C_1-x}{2C_1+D}
│ \right) \ , \quad C_1 = \frac{D}{2}. \] this will be positive over \(x \in (0,D)\),
│ and so we can rewrite \(\tilde{y}\) as, \[ \tilde{y}(x) = \frac{2D}{\pi} \log \cos \left( \pi
│ \frac{\frac{D}{2}-x}{2D} \right) + C_2. \] Once again considering that
│ \(y(0)=y(D)=0\), it is clear that \[ C_2 = - \frac{2D}{\pi} \log \cos \left(
│ \frac{\pi}{4} \right) = - \frac{2D}{\pi} \log 2^{-\frac{1}{2}} = \frac{D}{\pi} \log 2.
│ \] The complete solution for \(\tilde{y}\) is hence, \[ \tilde{y} = \frac{2D}{\pi} \log \cos
│ \left( \pi \frac{D-2x}{4D} \right) + \frac{D}{\pi} \log 2. \]
└────
Suffice to say, I find the second terrible to read compared to the first.
Furthermore, when using org-latex-preview, wrapped `\[ ... \]' blocks join lines,
resulting in lines that are displayed going off edge of the page after filling.
Basically, this leads to a worse experience when using Org in what I would think
to be a perfectly reasonably way.
All the best,
Timothy
^ permalink raw reply [relevance 63%]
* Re: [PATCH] Don't fill displayed equations
@ 2021-09-30 19:28 93% ` Timothy
2021-09-30 20:45 63% ` Timothy
1 sibling, 0 replies; 200+ results
From: Timothy @ 2021-09-30 19:28 UTC (permalink / raw)
To: Nicolas Goaziou; +Cc: Org Mode List
Nicolas Goaziou <mail@nicolasgoaziou.fr> writes:
>> Given that \[ ... \] is an alias for \begin{equation*} ...
>> \end{equation*}
>
> This is true in LaTeX, not in Org, obviously.
Isn't the whole point of the \[ ... \], \( ... \), $ ... $, $$ ... $$,
and \begin{env} ... \end{env} and constructs in Org to be consistent
with LaTeX?
--
Timothy
^ permalink raw reply [relevance 93%]
* Re: [PATCH] Don't fill displayed equations
@ 2021-09-30 18:54 93% ` Timothy
0 siblings, 1 reply; 200+ results
From: Timothy @ 2021-09-30 18:54 UTC (permalink / raw)
To: Nicolas Goaziou; +Cc: Org Mode List
Nicolas Goaziou <mail@nicolasgoaziou.fr> writes:
> I strongly disagree with this. \[...\] is an inline element, not a block
> element. As such, it can be filled, and filling function should obey to
> the inner structure of the document.
>
> You can use a real block element here, e.g.,
> \begin{equation*}...\end{equation*}, which will not be filled.
Given that \[ ... \] is an alias for \begin{equation*} ...
\end{equation*} I don't see why it should be treated any differently
when filling.
--
Timothy
^ permalink raw reply [relevance 93%]
* [PATCH] Accept more :tangle-mode specification forms
@ 2021-09-30 18:14 52% Timothy
2021-10-05 14:45 93% ` Timothy
0 siblings, 2 replies; 200+ results
From: Timothy @ 2021-09-30 18:14 UTC (permalink / raw)
To: Org Mode List
[-- Attachment #1: Type: text/plain, Size: 1191 bytes --]
Hello,
Currently, the only way to set a file mode when tangling seems to be
:tangle-mode (identity #o755)
In a [prior thread], Jeremy proposed that :tangle-mode should convert octal
number strings to the required decimal form. I think we should go further, and
so have prepared the attached patch based on a snippet I shared in the thread.
To quote the docstring of the new function I’m introducing, this patch now
accepts the following :tangle-mode forms:
• an integer (returned without modification)
• “#o755” (elisp-style octal)
• “0755” (c style octal)
• “755” (chmod style octal)
• “rwxrw-r–” (ls style specification)
• “a=rw,u+x” (chmod style)
• “rwx” (interpreted as “u=rwx”)
Why be so permissive? I’d refer you to my reasoning in the prior thread:
I think there are a few arguably “sensible” formats that a user could reasonably
assume, and if we can support most of them without introducing ambiguity in
parsing or interpretation (and I think we can), can’t we make everyone happy?
All the best,
Timothy
[prior thread] <https://list.orgmode.org/20210928145448.245883-1-jeremy@cowgar.com/>
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-ob-tangle-Accept-more-tangle-mode-forms.patch --]
[-- Type: text/x-patch, Size: 3691 bytes --]
From 5087de0d70151c33d66eb13dda84d78a361d7053 Mon Sep 17 00:00:00 2001
From: TEC <tec@tecosaur.com>
Date: Fri, 1 Oct 2021 02:02:22 +0800
Subject: [PATCH] ob-tangle: Accept more :tangle-mode forms
* lisp/ob-tangle.el (org-babel-tangle): Accept many more forms for
:tangle-mode, including octal strings (#o755, 0755, 755), ls forms (rwx,
rw-r--r--), and chmod forms (a=rw,u+x). The interpretation of the input
is now handled by the new function `org-babel-interpret-file-mode' which
references the new variable `org-babel-tangle-default-mode' when
considering relative mode forms.
---
lisp/ob-tangle.el | 42 +++++++++++++++++++++++++++++++++++++++++-
1 file changed, 41 insertions(+), 1 deletion(-)
diff --git a/lisp/ob-tangle.el b/lisp/ob-tangle.el
index 2dd1d031c..28a235429 100644
--- a/lisp/ob-tangle.el
+++ b/lisp/ob-tangle.el
@@ -140,6 +140,14 @@ (defcustom org-babel-process-comment-text 'org-remove-indentation
:version "24.1"
:type 'function)
+(defcustom org-babel-tangle-default-mode #o544
+ "The default mode used for tangled files, as an integer.
+The default value 356 correspands to the octal #o544, which is
+read-write permissions for the user, read-only for everyone else."
+ :group 'org-babel
+ :version "9.6"
+ :type 'integer)
+
(defun org-babel-find-file-noselect-refresh (file)
"Find file ensuring that the latest changes on disk are
represented in the file."
@@ -255,7 +263,7 @@ (defun org-babel-tangle (&optional arg target-file lang-re)
(when she-bang
(unless tangle-mode (setq tangle-mode #o755)))
(when tangle-mode
- (add-to-list 'modes tangle-mode))
+ (add-to-list 'modes (org-babel-interpret-file-mode tangle-mode)))
;; Possibly create the parent directories for file.
(let ((m (funcall get-spec :mkdirp)))
(and m fnd (not (string= m "no"))
@@ -298,6 +306,38 @@ (defun org-babel-tangle (&optional arg target-file lang-re)
path-collector))
path-collector))))
+(defun org-babel-interpret-file-mode (mode)
+ "Determine the integer representation of a file MODE specification.
+The following forms are currently recognised:
+- an integer (returned without modification)
+- \"#o755\" (elisp-style octal)
+- \"0755\" (c style octal)
+- \"755\" (chmod style octal)
+- \"rwxrw-r--\" (ls style specification)
+- \"a=rw,u+x\" (chmod style) *
+- \"rwx\" (interpreted as \"u=rwx\") *
+
+* The interpretation of these forms relies on `file-modes-symbolic-to-number',
+ and uses `org-babel-tangle-default-mode' as the base mode."
+ (cond
+ ((integerp mode) mode)
+ ((not (stringp mode))
+ (error "File mode %S not recognised as a valid format." mode))
+ ((string-match-p "^0?[0-7][0-7][0-7]$" mode)
+ (string-to-number mode 8))
+ ((string-match-p "^#o[0-7][0-7][0-7]$" mode)
+ (string-to-number (substring mode 2) 8))
+ ((string-match-p "^[ugoa]*\\(?:[+-=][rwxXstugo]*\\)+\\(,[ugoa]*\\(?:[+-=][rwxXstugo]*\\)+\\)*$" mode)
+ (file-modes-symbolic-to-number mode org-babel-tangle-default-mode))
+ ((string-match-p "^[rwx-]\\{3\\}$" mode)
+ (file-modes-symbolic-to-number (concat "u=" mode) org-babel-tangle-default-mode))
+ ((string-match-p "^[rwx-]\\{9\\}$" mode)
+ (file-modes-symbolic-to-number (concat "u=" (substring mode 0 3)
+ ",g=" (substring mode 3 6)
+ ",a=" (substring mode 6 9))
+ 0))
+ (t (error "File mode %S not recognised as a valid format." mode))))
+
(defun org-babel-tangle-clean ()
"Remove comments inserted by `org-babel-tangle'.
Call this function inside of a source-code file generated by
--
2.33.0
^ permalink raw reply related [relevance 52%]
* Re: [PATCH] Treat :tangle-mode as an octal value not integer
@ 2021-09-30 18:13 93% ` Timothy
0 siblings, 0 replies; 200+ results
From: Timothy @ 2021-09-30 18:13 UTC (permalink / raw)
To: Jeremy Cowgar; +Cc: emacs-orgmode
[-- Attachment #1: Type: text/plain, Size: 185 bytes --]
Hi Jeremy,
> I love it! Much better than my proposed patch.
I’m about to send a patch based on my snippet, so I’m marking this patch as cancelled.
All the best,
Timothy
^ permalink raw reply [relevance 93%]
* Re: [PATCH] Don't fill displayed equations
2021-09-30 17:20 66% [PATCH] Don't fill displayed equations Timothy
@ 2021-09-30 17:44 74% ` Timothy
1 sibling, 0 replies; 200+ results
From: Timothy @ 2021-09-30 17:44 UTC (permalink / raw)
To: Org Mode List
[-- Attachment #1: Type: text/plain, Size: 307 bytes --]
The initial patch was just slightly off. Here's a correct version.
Timothy <tecosaur@gmail.com> writes:
> As such, I have attached a patch which adds fill “cuts” around `\[' and
> `\]', when `\[' occurs at the start of a line. This leaves the display equation
> delimiters on their own line.
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-org-Don-t-fill-displayed-equations-into-text.patch --]
[-- Type: text/x-patch, Size: 2129 bytes --]
From d6d2221a7a9bf5e3cf93265c13cb643bcfe46929 Mon Sep 17 00:00:00 2001
From: TEC <tec@tecosaur.com>
Date: Fri, 1 Oct 2021 01:14:21 +0800
Subject: [PATCH] org: Don't fill displayed equations into text
* list/org.el (org-fill-element): If a displayed equation (\[ ... \])
starts on its own line, it should not be filled into the rest of the
text. I.e.,
some nice text
\[
1+1=2
\]
more text.
should not become,
some nice text \[ 1+1=3 \] more text.
While the above example may not look bad, with non-trivial equations
this can become quite messy.
---
lisp/org.el | 12 +++++++++++-
1 file changed, 11 insertions(+), 1 deletion(-)
diff --git a/lisp/org.el b/lisp/org.el
index 405f0f0f9..ff86a9dd0 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -19551,16 +19551,26 @@ (defun org-fill-element (&optional justify)
(org-element-property :contents-end element))))
;; Do nothing if point is at an affiliated keyword.
(if (< (line-end-position) beg) t
- ;; Fill paragraph, taking line breaks into account.
(save-excursion
(goto-char beg)
(let ((cuts (list beg)))
+ ;; Cut fill on line breaks.
(while (re-search-forward "\\\\\\\\[ \t]*\n" end t)
(when (eq 'line-break
(org-element-type
(save-excursion (backward-char)
(org-element-context))))
(push (point) cuts)))
+ ;; Cut fill on displayed equations.
+ (while (re-search-forward "^[ \t]*\\\\\\[" end t)
+ (let ((el (org-element-context)))
+ (when (eq 'latex-fragment (org-element-type el))
+ (setf cuts (append
+ (list (org-element-property :end el)
+ (- (org-element-property :end el) 2)
+ (+ (org-element-property :begin el) 2)
+ (org-element-property :begin el))
+ cuts)))))
(dolist (c (delq end cuts))
(fill-region-as-paragraph c end justify)
(setq end c))))
--
2.33.0
^ permalink raw reply related [relevance 74%]
* [PATCH] Don't fill displayed equations
@ 2021-09-30 17:20 66% Timothy
2021-09-30 17:44 74% ` Timothy
0 siblings, 2 replies; 200+ results
From: Timothy @ 2021-09-30 17:20 UTC (permalink / raw)
To: Org Mode List
[-- Attachment #1: Type: text/plain, Size: 898 bytes --]
Hi All,
If a displayed equation (`\[ ... \]') starts on its own line, I don’t think it
should be filled into the rest of the text. I.e.,
┌────
│ some nice text
│ \[
│ 1+1=2
│ \]
│ more text.
└────
should not become,
┌────
│ some nice text \[ 1+1=3 \] more text.
└────
While the above example may not look bad, with non-trivial equations
this can become quite messy.
As such, I have attached a patch which adds fill “cuts” around `\[' and
`\]', when `\[' occurs at the start of a line. This leaves the display equation
delimiters on their own line.
I think this motivation for this change is fairly clear, and so without feedback
I intend to push this in a few days, however I if anybody has comments on the way
I’m currently implementing this, I’d like to hear your thoughts.
All the best,
Timothy
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-org-Don-t-fill-displayed-equations-into-text.patch --]
[-- Type: text/x-patch, Size: 2168 bytes --]
From d008ff3c2218e19bb501137715b05e06a0c511e3 Mon Sep 17 00:00:00 2001
From: TEC <tec@tecosaur.com>
Date: Fri, 1 Oct 2021 01:14:21 +0800
Subject: [PATCH] org: Don't fill displayed equations into text
* list/org.el (org-fill-element): If a displayed equation (\[ ... \])
starts on its own line, it should not be filled into the rest of the
text. I.e.,
some nice text
\[
1+1=2
\]
more text.
should not become,
some nice text \[ 1+1=3 \] more text.
While the above example may not look bad, with non-trivial equations
this can become quite messy.
---
lisp/org.el | 12 +++++++++++-
1 file changed, 11 insertions(+), 1 deletion(-)
diff --git a/lisp/org.el b/lisp/org.el
index 405f0f0f9..daf1d91b4 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -19551,10 +19551,10 @@ (defun org-fill-element (&optional justify)
(org-element-property :contents-end element))))
;; Do nothing if point is at an affiliated keyword.
(if (< (line-end-position) beg) t
- ;; Fill paragraph, taking line breaks into account.
(save-excursion
(goto-char beg)
(let ((cuts (list beg)))
+ ;; Cut fill on line breaks.
(while (re-search-forward "\\\\\\\\[ \t]*\n" end t)
(when (eq 'line-break
(org-element-type
@@ -19562,6 +19562,16 @@ (defun org-fill-element (&optional justify)
(org-element-context))))
(push (point) cuts)))
(dolist (c (delq end cuts))
+ ;; Cut fill on displayed equations.
+ (while (re-search-forward "^[ \t]*\\\\\\[" end t)
+ (let ((el (org-element-context)))
+ (when (eq 'latex-fragment (org-element-type el))
+ (setf cuts (append
+ (list (org-element-property :end el)
+ (- (org-element-property :end el) 2)
+ (+ (org-element-property :begin el) 2)
+ (org-element-property :begin el))
+ cuts)))))
(fill-region-as-paragraph c end justify)
(setq end c))))
t)))
--
2.33.0
^ permalink raw reply related [relevance 66%]
* Re: [PATCH] Treat :tangle-mode as an octal value not integer
@ 2021-09-29 14:58 78% ` Timothy
1 sibling, 1 reply; 200+ results
From: Timothy @ 2021-09-29 14:58 UTC (permalink / raw)
To: tomas; +Cc: emacs-orgmode
<tomas@tuxteam.de> writes:
> So you favour going the "full custom special parser". You're much more
> involved in Org, so I think your gut feeling counts more than mine here :)
Well, I'm not sure that my feeling is representative of experienced Org users,
my opinion basically boils down to:
>> I think as long as it’s clear what’s intended, and it’s not some home-baked
>> non-standard format, or terribly annoying to support — why not?
Rephrased: I think there are a few arguably "sensible" formats that a user could
reasonably assume, and if we can support most of them without introducing
ambiguity in parsing or interpretation (and I think we can), can't we make
everyone happy?
> `755' is the funniest one, since, strictly speaking it doesn't correspond
> to anything "out there" (note that the shell command `chmod' wants the
> leading zero, or, well, it will do surprising things if you don't
> provide it ;-)
Consider my suggestion amended to 0755 etc. :)
Anyway, as an example here's a code snippet that implements everything I've
mentioned.
#+begin_src emacs-lisp
(defvar org-tangle-default-mode #o544
"The default mode for tangled files, as an integer.")
(defun org-interpret-file-mode (mode)
(cond
((integerp mode) mode)
((not (stringp mode))
(user-error "File mode %S not recognised as a valid format." mode))
((string-match-p "^0[0-7][0-7][0-7]$" mode)
(string-to-number mode 8))
((string-match-p "^#o[0-7][0-7][0-7]$" mode)
(string-to-number (substring mode 2) 8))
((string-match-p "^[ugoa]*\\(?:[+-=][rwxXstugo]*\\)+\\(,[ugoa]*\\(?:[+-=][rwxXstugo]*\\)+\\)*$" mode)
(file-modes-symbolic-to-number mode 0))
((string-match-p "^[rwx-]\\{3\\}$" mode)
(file-modes-symbolic-to-number (concat "u=" mode) org-tangle-default-mode))
((string-match-p "^[rwx-]\\{9\\}$" mode)
(file-modes-symbolic-to-number (concat "u=" (substring mode 0 3)
",g=" (substring mode 3 6)
",a=" (substring mode 6 9))
org-tangle-default-mode))
(t (user-error "File mode %S not recognised as a valid format." mode))))
#+end_src
--
Timothy
^ permalink raw reply [relevance 78%]
* Re: [PATCH] Treat :tangle-mode as an octal value not integer
@ 2021-09-29 13:48 87% ` Timothy
0 siblings, 1 reply; 200+ results
From: Timothy @ 2021-09-29 13:48 UTC (permalink / raw)
To: Jeremy Cowgar; +Cc: emacs-orgmode
[-- Attachment #1: Type: text/plain, Size: 1086 bytes --]
Hi Jeremy,
> As an org user I would expect :tangle-mode 0660 to produce a file that
> has user rw, group rw, other nothing. Instead, what really happens
> currently is 0660 is treated as an integer which is actually
> 3140. This produces unexpected file permissions.
I agree that :tangle-mode could be more user-friendly. However, I think we can
go further. Currently, only (identity #o755 / 493) works, however I think it would be
good if it worked like chmod and accepted most of the following forms:
⁃ `#o755'
⁃ `755' (because people are used to this, as technically misleading as it may be,
as long as we can tell “:tangle-mode 356” from “:tangle-mode (identity #o544)”)
⁃ `rw' (equivalent to a=rw, and so #o555)
⁃ `a=rw,u+x' (equivalent to #o755) [hardest to support, so maybe?]
And then I’d also be in favour of accepting
⁃ `rw-r--r--' (equivalent to #o544)
I think as long as it’s clear what’s intended, and it’s not some home-baked
non-standard format, or terribly annoying to support — why not?
All the best,
Timothy
^ permalink raw reply [relevance 87%]
* [PATCH] Prevent displayed images from being re-scaled
@ 2021-09-29 13:33 71% Timothy
2021-10-02 20:30 93% ` Timothy
0 siblings, 2 replies; 200+ results
From: Timothy @ 2021-09-29 13:33 UTC (permalink / raw)
To: Org-Mode Mailing List
[-- Attachment #1: Type: text/plain, Size: 922 bytes --]
Hello,
After my last patch providing support for proportional image width attributes
(e.g. 70% of the text width), I noticed that the results looked slightly off.
Investigating the code lead me to `create-image' which takes the liberty of
re-scaling images based on your default font size. As you might imagine, this
can be problematic when if you say determine that image should be 70% of the
text width, the text width is 1000px, and so the image should be 700px wide —
but upon being told to make the image 700 pixels wide `create-image' decides to
make it say 850 pixels wide. I personally found that images >~80% wide were
being made wider than the buffer, which isn’t good.
To make image width behave as expected, we can just specify `:scale 1' when
calling `create-image', and that will stop it from re-interpreting the `:width'
specification. See the patch attached.
All the best,
Timothy
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-org-Don-t-change-image-size-based-on-font-size.patch --]
[-- Type: text/x-patch, Size: 1113 bytes --]
From 9c34dd6aba62d734f6ae9aecaffa76a0250bf495 Mon Sep 17 00:00:00 2001
From: TEC <tec@tecosaur.com>
Date: Wed, 29 Sep 2021 21:29:27 +0800
Subject: [PATCH] org: Don't change image size based on font size
* lisp/org.el (org--create-inline-image): When `create-image' is called
without the :scale parameter, the image size is expanded based on the
default font size (if it is larger than 10px). When displaying images
with a specified width in Org buffers, either in pixels or proportional
to the text width, this width should not be modified according the to
font size. Giving a :scale parameter of 1 prevents this font-size based
rescaling.
---
lisp/org.el | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/lisp/org.el b/lisp/org.el
index 2ec6566c0..0e7f926f0 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -16518,7 +16518,7 @@ (defun org--create-inline-image (file width)
width
'imagemagick)
remote?
- :width width))))
+ :width width :scale 1))))
(defun org-display-inline-images (&optional include-linked refresh beg end)
"Display inline images.
--
2.33.0
^ permalink raw reply related [relevance 71%]
* Re: [PATCH]
@ 2021-09-28 15:50 93% ` Timothy
0 siblings, 0 replies; 200+ results
From: Timothy @ 2021-09-28 15:50 UTC (permalink / raw)
To: Bastien Guerry; +Cc: Org Mode List
[-- Attachment #1: Type: text/plain, Size: 198 bytes --]
Bastien Guerry <bzg@gnu.org> writes:
>> It seems to me that the defvar declaration is good enough.
>
> I just pushed this.
Ah, cool. Thanks for taking care of this Bastien.
All the best,
Timothy
^ permalink raw reply [relevance 93%]
* [PATCH] (minor) Use lower case keywords in ox-org
@ 2021-09-28 14:58 64% Timothy
0 siblings, 0 replies; 200+ results
From: Timothy @ 2021-09-28 14:58 UTC (permalink / raw)
To: Org Mode List
[-- Attachment #1: Type: text/plain, Size: 335 bytes --]
Hello,
Just a little thing, if it’s of interest. A while ago I remember upper/lower
case keywords being discussed and the conclusion being that upper case keywords
were only to be used in the manual. Since `ox-org' isn’t the manual, I’ve gone and
lowered the case of all the keywords used there.
All the best,
Timothy
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-ox-org-Use-lower-case-keywords.patch --]
[-- Type: text/x-patch, Size: 2556 bytes --]
From d5c0cb92198d315031a5e4539e227b22a1f0b98b Mon Sep 17 00:00:00 2001
From: TEC <tec@tecosaur.com>
Date: Tue, 28 Sep 2021 22:45:55 +0800
Subject: [PATCH] ox-org: Use lower case keywords
* lisp/ox-org.el (org-org-identity, org-org-template): As it has
previously been clarified on the mailing list that upper-case keywords
are only intended for the manual[1], an Org export of an Org file should
use lower-case keywords.
[1]: https://list.orgmode.org/87tuuw3n15.fsf@nicolasgoaziou.fr/
---
lisp/ox-org.el | 14 +++++++-------
1 file changed, 7 insertions(+), 7 deletions(-)
diff --git a/lisp/ox-org.el b/lisp/ox-org.el
index c2b85473c..0c4290ebf 100644
--- a/lisp/ox-org.el
+++ b/lisp/ox-org.el
@@ -141,7 +141,7 @@ (defun org-org-identity (blob contents _info)
CONTENTS is its contents, as a string or nil. INFO is ignored."
(let ((case-fold-search t))
(replace-regexp-in-string
- "^[ \t]*#\\+ATTR_[-_A-Za-z0-9]+:\\(?: .*\\)?\n" ""
+ "^[ \t]*#\\+attr_[-_a-za-z0-9]+:\\(?: .*\\)?\n" ""
(org-export-expand blob contents t))))
(defun org-org-headline (headline contents info)
@@ -185,26 +185,26 @@ (defun org-org-template (contents info)
(org-element-map (plist-get info :parse-tree) 'keyword
(lambda (k)
(and (string-equal (org-element-property :key k) "OPTIONS")
- (concat "#+OPTIONS: "
+ (concat "#+options: "
(org-element-property :value k)))))
"\n"))
(and (plist-get info :with-title)
- (format "#+TITLE: %s\n" (org-export-data (plist-get info :title) info)))
+ (format "#+title: %s\n" (org-export-data (plist-get info :title) info)))
(and (plist-get info :with-date)
(let ((date (org-export-data (org-export-get-date info) info)))
(and (org-string-nw-p date)
- (format "#+DATE: %s\n" date))))
+ (format "#+date: %s\n" date))))
(and (plist-get info :with-author)
(let ((author (org-export-data (plist-get info :author) info)))
(and (org-string-nw-p author)
- (format "#+AUTHOR: %s\n" author))))
+ (format "#+author: %s\n" author))))
(and (plist-get info :with-email)
(let ((email (org-export-data (plist-get info :email) info)))
(and (org-string-nw-p email)
- (format "#+EMAIL: %s\n" email))))
+ (format "#+email: %s\n" email))))
(and (plist-get info :with-creator)
(org-string-nw-p (plist-get info :creator))
- (format "#+CREATOR: %s\n" (plist-get info :creator)))
+ (format "#+creator: %s\n" (plist-get info :creator)))
contents))
(defun org-org-timestamp (timestamp _contents _info)
--
2.33.0
^ permalink raw reply related [relevance 64%]
* Re: [PATCH]
@ 2021-09-27 17:52 93% ` Timothy
0 siblings, 1 reply; 200+ results
From: Timothy @ 2021-09-27 17:52 UTC (permalink / raw)
To: Bastien; +Cc: Org Mode List
[-- Attachment #1: Type: text/plain, Size: 559 bytes --]
Bastien <bzg@gnu.org> writes:
> Since this is a variable, a simple (defvar visual-fill-column-width)
> will silent the compiler.
I’ve just had another thought which wouldn’t add visual-fill-column-width to the
namespace (if that’s worth worrying about). Not sure if this is better or worse
though.
┌────
│ (/ (or (and (bound-and-true-p visual-fill-column-mode)
│ (or (bound-and-true-p visual-fill-column-mode) auto-fill-function))
└────
Might you have an opinion on this?
All the best,
Timothy
^ permalink raw reply [relevance 93%]
* Re: [PATCH]
@ 2021-09-27 15:36 93% ` Timothy
0 siblings, 1 reply; 200+ results
From: Timothy @ 2021-09-27 15:36 UTC (permalink / raw)
To: Bastien; +Cc: Org Mode List
[-- Attachment #1: Type: text/plain, Size: 740 bytes --]
Bastien <bzg@gnu.org> writes:
> This triggers a compiler warning about `visual-fill-column-width’ not
> being declared.
>
> This variable comes from
> <https://github.com/joostkremers/visual-fill-column>
>
> Why relying on this package? Any chance to avoid this dependency?
>
> If not, can you please add the needed declaration?
Here I’m not relying on the package, but trying to make it so that this will
still function as intended if the package is used, as it can modify the area
used for text in a buffer (hence the bound-and-true-p). I think this is worth
having, but obviously byte-compile errors aren’t nice. Would adding a
declare-function statement be the best thing to do here?
All the best,
Timothy
^ permalink raw reply [relevance 93%]
* Re: [PATCH]
@ 2021-09-27 12:20 93% ` Timothy
0 siblings, 1 reply; 200+ results
From: Timothy @ 2021-09-27 12:20 UTC (permalink / raw)
To: Bastien; +Cc: Org Mode List
[-- Attachment #1: Type: text/plain, Size: 306 bytes --]
Bastien <bzg@gnu.org> writes:
> It looks better, Thanks. The two patches don’t apply on main here.
> Can you apply the change yourself and add an entry in etc/ORG-NEWS?
I’ve written an ORG-NEWS entry, verified it works (and fixed a trivial
oversight), and pushed :)
All the best,
Timothy
^ permalink raw reply [relevance 93%]
* Re: [PATCH]
@ 2021-09-27 10:35 38% ` Timothy
0 siblings, 1 reply; 200+ results
From: Timothy @ 2021-09-27 10:35 UTC (permalink / raw)
To: Bastien; +Cc: Org Mode List
[-- Attachment #1: Type: text/plain, Size: 893 bytes --]
Hi Bastien,
Thanks for taking a look at my patch.
Bastien <bzg@gnu.org> writes:
> On a first look, it seems a bit hackish, but this is probably useful.
Taking a look at the commit, I can see how it doesn’t look particularly tidy. I
think this is more a function of the way that function is structured than my
change though. As such, I’ve had a second look at the code, and given how large
that function is, split off the width calculation into a new function, where
I’ve re-implemented the logic in (IMO) a cleaner way.
So now, in the original function there’s just
┌────
│ (let ((width (org-display-inline-image--width link))
└────
See the attached patch for the new function `org-display-inline-image--width' (to
be applied on top of my previous patch). Oh, and I’ve also added support for
`:width 70%'.
All the best,
Timothy
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0003-org-Support-displaying-X-width-images.patch --]
[-- Type: text/x-patch, Size: 1916 bytes --]
From d9c83a962c0ce26e3d7baf2a5b7a58ba054ef275 Mon Sep 17 00:00:00 2001
From: TEC <tec@tecosaur.com>
Date: Mon, 27 Sep 2021 19:16:58 +0800
Subject: [PATCH 3/3] org: Support displaying X% width images
* lisp/org.el (org-display-inline-image--width): Instead of interpreting
an image :width of X% as X pixels, take it as X% of the text width of
the buffer.
---
lisp/org.el | 9 +++++++--
1 file changed, 7 insertions(+), 2 deletions(-)
diff --git a/lisp/org.el b/lisp/org.el
index d61e74572..829df8cae 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -16647,7 +16647,8 @@ (defun org-display-inline-image--width (link)
- When `org-image-actual-width' is t, the image's pixel width is used.
- When `org-image-actual-width' is a number, that value will is used.
- When `org-image-actual-width' is nil or a list, the first :width attribute
- set (if it exists) is used to set the image width.
+ set (if it exists) is used to set the image width. A width of X% is
+ divided by 100.
If no :width attribute is given and `org-image-actual-width' is a list with
a number as the car, then that number is used as the default value.
If the value is a float between 0 and 2, it interpreted as that proportion
@@ -16667,7 +16668,11 @@ (defun org-display-inline-image--width (link)
(re-search-forward attr-re par-end t)))
(string-to-number (match-string 1))))
(attr-width-val
- (when attr-width (string-to-number attr-width)))
+ (cond
+ ((null attr-width) nil)
+ ((string-match-p "\\`[0-9.]+%")
+ (/ (string-to-number attr-width) 100.0))
+ (t (string-to-number attr-width))))
;; Fallback to `org-image-actual-width' if no explicit width is given.
(width (or attr-width-val (car org-image-actual-width))))
(if (and (floatp width) (<= 0 width 2.0))
--
2.33.0
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #3: 0002-org-Refactor-width-in-org-display-inline-images.patch --]
[-- Type: text/x-patch, Size: 6646 bytes --]
From 1fd5e43137a34418c149240b15fd4bdc311f4fd3 Mon Sep 17 00:00:00 2001
From: TEC <tec@tecosaur.com>
Date: Mon, 27 Sep 2021 18:46:03 +0800
Subject: [PATCH 2/3] org: Refactor width in `org-display-inline-images'
* lisp/org.el (org-display-inline-images,
org-display-inline-image--width): Extract the width determination in
`org-display-inline-images' into a new function
`org-display-inline-image--width' where I have taken the opportunity to
refactor the width-determination code.
---
lisp/org.el | 85 +++++++++++++++++++++++++++++------------------------
1 file changed, 47 insertions(+), 38 deletions(-)
diff --git a/lisp/org.el b/lisp/org.el
index 1a1feda78..d61e74572 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -16617,44 +16617,7 @@ (defun org-display-inline-images (&optional include-linked refresh beg end)
(ignore-errors (org-attach-expand path)))
(expand-file-name path))))
(when (and file (file-exists-p file))
- (let ((width
- ;; Apply `org-image-actual-width' specifications.
- (cond
- ((eq org-image-actual-width t) nil)
- ((listp org-image-actual-width)
- (let ((width
- (or
- ;; First try to find a width among
- ;; attributes associated to the paragraph
- ;; containing link.
- (pcase (org-element-lineage link '(paragraph))
- (`nil nil)
- (par (let* ((case-fold-search t)
- (end (org-element-property :post-affiliated par))
- (re "^[ \t]*#\\+attr_.*?: +.*?:width +\\(\\S-+\\)"))
- (when (org-with-point-at
- (org-element-property :begin par)
- (re-search-forward re end t))
- (string-to-number (match-string 1)))))))
- ;; Otherwise, fall-back to provided number.
- (car org-image-actual-width))))
- (if (and (floatp width) (<= 0 width 2.0))
- ;; A float in [0,2] should be interpereted as this portion of
- ;; the text width in the window. This works well with cases like
- ;; #+attr_latex: :width 0.X\{line,page,column,etc.}width,
- ;; as the "0.X" is pulled out as a float. We use 2 as the upper
- ;; bound as cases such as 1.2\linewidth are feasible.
- (round (* width
- (window-pixel-width)
- (/ (or (and (bound-and-true-p visual-fill-column-mode)
- (or visual-fill-column-width auto-fill-function))
- (when auto-fill-function fill-column)
- (window-text-width))
- (float (window-total-width)))))
- width))
- ((numberp org-image-actual-width)
- org-image-actual-width)
- (t nil)))
+ (let ((width (org-display-inline-image--width link))
(old (get-char-property-and-overlay
(org-element-property :begin link)
'org-image-overlay)))
@@ -16679,6 +16642,52 @@ (defun org-display-inline-images (&optional include-linked refresh beg end)
(overlay-put ov 'keymap image-map))
(push ov org-inline-image-overlays))))))))))))))))
+(defun org-display-inline-image--width (link)
+ "Determine the display width of the image LINK, in pixels.
+- When `org-image-actual-width' is t, the image's pixel width is used.
+- When `org-image-actual-width' is a number, that value will is used.
+- When `org-image-actual-width' is nil or a list, the first :width attribute
+ set (if it exists) is used to set the image width.
+ If no :width attribute is given and `org-image-actual-width' is a list with
+ a number as the car, then that number is used as the default value.
+ If the value is a float between 0 and 2, it interpreted as that proportion
+ of the text width in the buffer."
+ ;; Apply `org-image-actual-width' specifications.
+ (cond
+ ((eq org-image-actual-width t) nil)
+ ((listp org-image-actual-width)
+ (let* ((case-fold-search t)
+ (par (org-element-lineage link '(paragraph)))
+ (attr-re "^[ \t]*#\\+attr_.*?: +.*?:width +\\(\\S-+\\)")
+ (par-end (org-element-property :post-affiliated par))
+ ;; Try to find an attribute providing a :width.
+ (attr-width
+ (when (and par (org-with-point-at
+ (org-element-property :begin par)
+ (re-search-forward attr-re par-end t)))
+ (string-to-number (match-string 1))))
+ (attr-width-val
+ (when attr-width (string-to-number attr-width)))
+ ;; Fallback to `org-image-actual-width' if no explicit width is given.
+ (width (or attr-width-val (car org-image-actual-width))))
+ (if (and (floatp width) (<= 0 width 2.0))
+ ;; A float in [0,2] should be interpereted as this portion of
+ ;; the text width in the window. This works well with cases like
+ ;; #+attr_latex: :width 0.X\{line,page,column,etc.}width,
+ ;; as the "0.X" is pulled out as a float. We use 2 as the upper
+ ;; bound as cases such as 1.2\linewidth are feasible.
+ (round (* width
+ (window-pixel-width)
+ (/ (or (and (bound-and-true-p visual-fill-column-mode)
+ (or visual-fill-column-width auto-fill-function))
+ (when auto-fill-function fill-column)
+ (window-text-width))
+ (float (window-total-width)))))
+ width)))
+ ((numberp org-image-actual-width)
+ org-image-actual-width)
+ (t nil)))
+
(defun org-display-inline-remove-overlay (ov after _beg _end &optional _len)
"Remove inline-display overlay if a corresponding region is modified."
(let ((inhibit-modification-hooks t))
--
2.33.0
^ permalink raw reply related [relevance 38%]
* Re: [PATCH] ob-svgbob: New babel backend for SVGBob
@ 2021-09-26 20:35 89% ` Timothy
0 siblings, 0 replies; 200+ results
From: Timothy @ 2021-09-26 20:35 UTC (permalink / raw)
To: Bastien; +Cc: emacs-orgmode, Steven vanZyl
[-- Attachment #1: Type: text/plain, Size: 1153 bytes --]
Hi Bastien,
> Not later than a few hours ago, I removed several ob-* files:
> <https://git.savannah.gnu.org/cgit/emacs/org-mode.git/commit/?id=db67c7e9>
>
> (ob-svgbob.el should not go in org-contrib, though, because the
> org-contrib repo is for unmaintained libraries.)
>
> I suggest you maintain ob-svgbob.el as a contributed library to
> GNU ELPA (<https://elpa.gnu.org>) to help people find it. See the
> instructions here:
>
> <https://git.savannah.gnu.org/cgit/emacs/elpa.git/plain/README>
Thanks for taking a look at this. In light of your response I’m wondering about
the ob-* inclusion criteria. I recall when removal was being discussed the
concerns being with ob-* libraries that were some combination of:
⁃ Too niche
⁃ Being actively maintained
Which is why I thought SVGBob could be a good fit, as it’s a small useful
general-purpose tool that only takes ~50 lines of code for a library (and so I’d
be quite happy to maintain) and IMO fits in nicely with Org.
Would you mind elaborating a bit more on your thoughts on what makes an ob-*
library a good fit for Org or not?
All the best,
Timothy
^ permalink raw reply [relevance 89%]
* Re: [PATCH]
2021-09-26 11:51 54% [PATCH] Timothy
2021-09-26 12:01 93% ` [PATCH] Timothy
@ 2021-09-26 12:14 63% ` Timothy
1 sibling, 1 reply; 200+ results
From: Timothy @ 2021-09-26 12:14 UTC (permalink / raw)
To: Org Mode List
[-- Attachment #1: Type: text/plain, Size: 222 bytes --]
Hello again,
> I’ve prepared a patch which implements this logic
I've just noticed that I had (when x (if (floatp x) ..)) which is a bit
silly, so I've removed the unnecessary when. Here's the updated patch.
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-org-Display-proportional-image-widths.patch --]
[-- Type: text/x-patch, Size: 4155 bytes --]
From 2d8f151bb996e0159793b590baea50c530e3ed11 Mon Sep 17 00:00:00 2001
From: TEC <tec@tecosaur.com>
Date: Fri, 24 Sep 2021 01:39:31 +0800
Subject: [PATCH] org: Display proportional image widths
* lisp/org.el (org-display-inline-images): When the image width is given
as a float less than 2, interpret the value as that portion of the text
area width. This works well with cases such as "#+attr_latex: :width
0.6\linewidth" as this will now be interpreted as 60% of the text area
width. The upper bound is set to 2 not 1, as more than 100% of the text
width can be realistic, e.g. "1.2\linewidth" in LaTeX, but more than
200% seems unrealistic.
---
lisp/org.el | 46 ++++++++++++++++++++++++++++++----------------
1 file changed, 30 insertions(+), 16 deletions(-)
diff --git a/lisp/org.el b/lisp/org.el
index 66ca73d5e..1a1feda78 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -16622,22 +16622,36 @@ (defun org-display-inline-images (&optional include-linked refresh beg end)
(cond
((eq org-image-actual-width t) nil)
((listp org-image-actual-width)
- (or
- ;; First try to find a width among
- ;; attributes associated to the paragraph
- ;; containing link.
- (pcase (org-element-lineage link '(paragraph))
- (`nil nil)
- (p
- (let* ((case-fold-search t)
- (end (org-element-property :post-affiliated p))
- (re "^[ \t]*#\\+attr_.*?: +.*?:width +\\(\\S-+\\)"))
- (when (org-with-point-at
- (org-element-property :begin p)
- (re-search-forward re end t))
- (string-to-number (match-string 1))))))
- ;; Otherwise, fall-back to provided number.
- (car org-image-actual-width)))
+ (let ((width
+ (or
+ ;; First try to find a width among
+ ;; attributes associated to the paragraph
+ ;; containing link.
+ (pcase (org-element-lineage link '(paragraph))
+ (`nil nil)
+ (par (let* ((case-fold-search t)
+ (end (org-element-property :post-affiliated par))
+ (re "^[ \t]*#\\+attr_.*?: +.*?:width +\\(\\S-+\\)"))
+ (when (org-with-point-at
+ (org-element-property :begin par)
+ (re-search-forward re end t))
+ (string-to-number (match-string 1)))))))
+ ;; Otherwise, fall-back to provided number.
+ (car org-image-actual-width))))
+ (if (and (floatp width) (<= 0 width 2.0))
+ ;; A float in [0,2] should be interpereted as this portion of
+ ;; the text width in the window. This works well with cases like
+ ;; #+attr_latex: :width 0.X\{line,page,column,etc.}width,
+ ;; as the "0.X" is pulled out as a float. We use 2 as the upper
+ ;; bound as cases such as 1.2\linewidth are feasible.
+ (round (* width
+ (window-pixel-width)
+ (/ (or (and (bound-and-true-p visual-fill-column-mode)
+ (or visual-fill-column-width auto-fill-function))
+ (when auto-fill-function fill-column)
+ (window-text-width))
+ (float (window-total-width)))))
+ width))
((numberp org-image-actual-width)
org-image-actual-width)
(t nil)))
--
2.33.0
^ permalink raw reply related [relevance 63%]
* Re: [PATCH]
2021-09-26 11:51 54% [PATCH] Timothy
@ 2021-09-26 12:01 93% ` Timothy
2021-09-26 12:14 63% ` [PATCH] Timothy
1 sibling, 0 replies; 200+ results
From: Timothy @ 2021-09-26 12:01 UTC (permalink / raw)
To: Org Mode List
How on earth did I remember to start writing the subject, then switch to the
message, and forget to finish it... (sigh). Ooops.
--
Timothy
^ permalink raw reply [relevance 93%]
* [PATCH]
@ 2021-09-26 11:51 54% Timothy
2021-09-26 12:01 93% ` [PATCH] Timothy
2021-09-26 12:14 63% ` [PATCH] Timothy
0 siblings, 2 replies; 200+ results
From: Timothy @ 2021-09-26 11:51 UTC (permalink / raw)
To: Org Mode List
[-- Attachment #1.1: Type: text/plain, Size: 1370 bytes --]
Hi Everyone,
I’ve recently been wondering why it is that for sensibly sized images in a
LaTeX-export-oriented document I need to do both:
┌────
│ #+attr_org: :width 400
│ #+attr_latex: :width 0.4\linewidth
└────
When in HTML, just
┌────
│ #+attr_html: :width 400px
└────
is fine.
This has lead me to have a look at `org-display-inline-images', and I’ve realised
that the `#+attr_latex' width of `0.4\linewidth' is actually picked up, and
interpreted as a width of `0.4' pixels. I think it would make much more sense for
fractional values between zero and one to be interpreted as that portion of the
text width in the buffer. On second thoughts, given that the document width can
be slightly larger than the text width, perhaps an upper bound just a bit higher
— say 2, could be better.
I’ve prepared a patch which implements this logic, by converting extracted
widths that are:
⁃ floats, and
⁃ within the range [0,2]
and sizes them as that proportion of the text width in the buffer, which is
determined by checking
1. `visual-fill-column-width', when that package is installed and the mode active
2. `fill-column', when auto fill is active
3. `(window-text-width)', if neither of the above two cases hold
Please let me know what you think 🙂.
All the best,
Timothy
[-- Attachment #1.2: Type: text/html, Size: 6912 bytes --]
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-org-Display-proportional-image-widths.patch --]
[-- Type: text/x-patch, Size: 4258 bytes --]
From bc8aa862f513946599efe4a9bb420e54c504ab3b Mon Sep 17 00:00:00 2001
From: TEC <tec@tecosaur.com>
Date: Fri, 24 Sep 2021 01:39:31 +0800
Subject: [PATCH] org: Display proportional image widths
* lisp/org.el (org-display-inline-images): When the image width is given
as a float less than 2, interpret the value as that portion of the text
area width. This works well with cases such as "#+attr_latex: :width
0.6\linewidth" as this will now be interpreted as 60% of the text area
width. The upper bound is set to 2 not 1, as more than 100% of the text
width can be realistic, e.g. "1.2\linewidth" in LaTeX, but more than
200% seems unrealistic.
---
lisp/org.el | 47 +++++++++++++++++++++++++++++++----------------
1 file changed, 31 insertions(+), 16 deletions(-)
diff --git a/lisp/org.el b/lisp/org.el
index 66ca73d5e..ce2ac7404 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -16622,22 +16622,37 @@ (defun org-display-inline-images (&optional include-linked refresh beg end)
(cond
((eq org-image-actual-width t) nil)
((listp org-image-actual-width)
- (or
- ;; First try to find a width among
- ;; attributes associated to the paragraph
- ;; containing link.
- (pcase (org-element-lineage link '(paragraph))
- (`nil nil)
- (p
- (let* ((case-fold-search t)
- (end (org-element-property :post-affiliated p))
- (re "^[ \t]*#\\+attr_.*?: +.*?:width +\\(\\S-+\\)"))
- (when (org-with-point-at
- (org-element-property :begin p)
- (re-search-forward re end t))
- (string-to-number (match-string 1))))))
- ;; Otherwise, fall-back to provided number.
- (car org-image-actual-width)))
+ (let ((width
+ (or
+ ;; First try to find a width among
+ ;; attributes associated to the paragraph
+ ;; containing link.
+ (pcase (org-element-lineage link '(paragraph))
+ (`nil nil)
+ (par (let* ((case-fold-search t)
+ (end (org-element-property :post-affiliated par))
+ (re "^[ \t]*#\\+attr_.*?: +.*?:width +\\(\\S-+\\)"))
+ (when (org-with-point-at
+ (org-element-property :begin par)
+ (re-search-forward re end t))
+ (string-to-number (match-string 1)))))))
+ ;; Otherwise, fall-back to provided number.
+ (car org-image-actual-width))))
+ (when width
+ (if (and (floatp width) (<= 0 width 2.0))
+ ;; A float in [0,2] should be interpereted as this portion of
+ ;; the text width in the window. This works well with cases like
+ ;; #+attr_latex: :width 0.X\{line,page,column,etc.}width,
+ ;; as the "0.X" is pulled out as a float. We use 2 as the upper
+ ;; bound as cases such as 1.2\linewidth are feasible.
+ (round (* width
+ (window-pixel-width)
+ (/ (or (and (bound-and-true-p visual-fill-column-mode)
+ (or visual-fill-column-width auto-fill-function))
+ (when auto-fill-function fill-column)
+ (window-text-width))
+ (float (window-total-width)))))
+ width))))
((numberp org-image-actual-width)
org-image-actual-width)
(t nil)))
--
2.33.0
^ permalink raw reply related [relevance 54%]
* Re: [PATCH] Include support for evaluating julia code
@ 2021-09-25 14:13 93% ` Timothy
0 siblings, 0 replies; 200+ results
From: Timothy @ 2021-09-25 14:13 UTC (permalink / raw)
To: Bastien; +Cc: emacs-orgmode
[-- Attachment #1: Type: text/plain, Size: 675 bytes --]
Hi Bastien,
> We had previous discussions with Pedro on his contribution regarding
> ob-julia.el¹, I agreed he could be the maintainer once he signed the
> FSF copyright assignment, so I feel an obligation to apply his patch
> right now, but I’m sure Pedro, you and Nicolò can work together on
> the improved version.
As far as I’m concerned, the more the merrier 😀.
> I don’t know if Nicolò has signed the FSF copyright assignment but
> once he does, he can join the party too.
I’ve talked to Nicolò about this, and I don’t think he has yet, but he’s said he
knows what’s needed and it won’t be a problem.
All the best,
Timothy
^ permalink raw reply [relevance 93%]
* Re: [PATCH] Include support for evaluating julia code
@ 2021-09-24 20:04 93% ` Timothy
0 siblings, 1 reply; 200+ results
From: Timothy @ 2021-09-24 20:04 UTC (permalink / raw)
To: emacs-orgmode
[-- Attachment #1.1: Type: text/plain, Size: 522 bytes --]
Hi Pedro,
Thanks for your patch, it’s great to see the interest in Julia support and it’s
something that I absolutely think should be in org-core 🙂. However, ob-julia.el
was moved into org-contrib because it was not well maintained, and very buggy.
I’m actually currently working on a successor with Nicolò (see the linked repo)
in my free time, and intend to submit that to Org when I feel it is mature
enough. See <https://github.com/nico202/ob-julia/> for more information.
All the best,
Timothy
[-- Attachment #1.2: Type: text/html, Size: 4044 bytes --]
^ permalink raw reply [relevance 93%]
* Re: [PATCH] org-manual.org: Augment TODO keywords example
@ 2021-09-24 4:41 93% ` Timothy
0 siblings, 0 replies; 200+ results
From: Timothy @ 2021-09-24 4:41 UTC (permalink / raw)
To: emacs-orgmode
[-- Attachment #1: Type: text/plain, Size: 45 bytes --]
Marking as cancelled for updates.orgmode.org
^ permalink raw reply [relevance 93%]
* Re: [PATCH] org-manual.org: Augment TODO keywords example
@ 2021-09-24 4:39 93% ` Timothy
0 siblings, 0 replies; 200+ results
From: Timothy @ 2021-09-24 4:39 UTC (permalink / raw)
To: emacs-orgmode
[-- Attachment #1: Type: text/plain, Size: 45 bytes --]
Marking as cancelled for updates.orgmode.org
^ permalink raw reply [relevance 93%]
* Re: [patch suggestion] Mitigating the poor Emacs performance on huge org files: Do not use overlays for PROPERTY and LOGBOOK drawers
@ 2021-09-21 13:32 93% ` Timothy
0 siblings, 0 replies; 200+ results
From: Timothy @ 2021-09-21 13:32 UTC (permalink / raw)
To: Bastien
Cc: Karl Voit, Ihor Radchenko, emacs-orgmode, Nicolas Goaziou,
Christian Heinrich, Kyle Meyer
[-- Attachment #1: Type: text/plain, Size: 445 bytes --]
I’m suspect it too short notice for such a large change to make its way into Org
9.5, but Bastien’s release email is certainly a good prompt to bump this.
Bastien <bzg@gnu.org> writes:
> Thank you *very much* for this work and sorry for the slow reply.
>
> I urge everyone to test this change, as I’d like to include it in
> Org 9.5 if it’s ready.
>
> I will test this myself this week and report.
All the best,
Timothy
^ permalink raw reply [relevance 93%]
* Re: [PATCH] org-cite: Use citeproc-el to create CSL processor itemgetters
@ 2021-09-20 12:29 91% ` Timothy
0 siblings, 0 replies; 200+ results
From: Timothy @ 2021-09-20 12:29 UTC (permalink / raw)
To: András Simonyi; +Cc: emacs-orgmode
[-- Attachment #1: Type: text/plain, Size: 737 bytes --]
Hi András,
Great to see this patch from you 🙂.
> this is the first item in a series of oc-csl patches which I’ve
> accumulated and am planning to send this week. (My first attempt to
> send a patch, so please be patient and forgiving :-) )
This may be your first attempt sending a patch, but it all looks good to me.
Simply attaching a `.patch' file is all that’s needed, and you seem to be
following our commit message guidelines, which is good to see.
Regarding the content of this patch and the few you have planned that follow —
would it be fair to say that overall you’re trying to update `oc-csl' based on
changes you’ve made to `citeproc-el' since `oc-csl' was written?
All the best,
Timothy
^ permalink raw reply [relevance 91%]
* Re: [PATCH] ox-ascii.el: Fix justify when `indent-tabs-mode' is non-nil
@ 2021-09-19 17:02 93% ` Timothy
0 siblings, 0 replies; 200+ results
From: Timothy @ 2021-09-19 17:02 UTC (permalink / raw)
To: Morgan Willcock; +Cc: emacs-orgmode
[-- Attachment #1: Type: text/plain, Size: 938 bytes --]
Hi Morgan,
Thanks for clarifying this. That makes sense to me, and so I’ve just pushed your
patch as 3a77e59 🙂, with a slightly tweaked commit message. Thanks for going to
the effort of pinpointing and fixing this issue, and your patience in seeing
this accepted.
Morgan Willcock <mwillcock@precedence.co.uk> writes:
> It seems to default to spaces everywhere else. If you export an actual
> document through the ascii exporter instead of just a document header
> you will get a mix of tabs and spaces. This is how it was brought to my
> attention, I was distributing a file that was batch exported and someone
> pointed out that the indentation was inconsistent.
>
> If it is handled as an export preference or defaults to the global
> indentation preference then that would be fine but I don’t believe
> either of those are the case.
>
> Thanks for continuing to look,
> Morgan
All the best,
Timothy
^ permalink raw reply [relevance 93%]
* Re: [PATCH] manual: How to refer to tables in other files
@ 2021-09-19 13:36 93% ` Timothy
0 siblings, 0 replies; 200+ results
From: Timothy @ 2021-09-19 13:36 UTC (permalink / raw)
To: William Denton; +Cc: emacs-orgmode
[-- Attachment #1: Type: text/plain, Size: 543 bytes --]
Hi William,
Thanks for sending in this patch. Documentation improvements are always great to
see. I’ve just applied your patch with minor tweaks to the commit message, and
the “Nu HTML” bit removed as d700c03 🙂.
William Denton <wtd@pobox.com> writes:
> Attached is a very small update to the docs about how to refer to tables in
> other files. Probably there’s something wrong with the formatting, but git
> send-email didn’t work, and I hope the Changelog entry gets through.
>
> Bill
All the best,
Timothy
^ permalink raw reply [relevance 93%]
* Re: [PATCH] Add faces to improve contextuality of agenda views
@ 2021-09-19 13:23 93% ` Timothy
0 siblings, 0 replies; 200+ results
From: Timothy @ 2021-09-19 13:23 UTC (permalink / raw)
To: Protesilaos Stavrou; +Cc: emacs-orgmode, Gustavo Barros
[-- Attachment #1: Type: text/plain, Size: 321 bytes --]
Hi Protesilaos,
Thanks for sending this patch in, and sorry it’s taken a while for you to hear
anything back. I see the utility of org-imminent-deadline, but am fairly
indifferent about the rest.
Hopefully bumping this might prompt some others to give their thoughts on your
patch.
All the best,
Timothy
^ permalink raw reply [relevance 93%]
* Re: [PATCH] org-cite: define \citeprocitem for LaTeX export
2021-08-26 8:18 93% ` Timothy
@ 2021-09-19 13:19 93% ` Timothy
0 siblings, 0 replies; 200+ results
From: Timothy @ 2021-09-19 13:19 UTC (permalink / raw)
To: emacs-orgmode
[-- Attachment #1: Type: text/plain, Size: 109 bytes --]
Looks like I forgot to mark this patch as applied on updates.orgmode.org.
Let’s just quickly fix that…
^ permalink raw reply [relevance 93%]
* Re: [PATCH] ox-ascii.el: Fix justify when `indent-tabs-mode' is non-nil
2021-08-31 11:59 90% ` Timothy
@ 2021-09-19 13:13 92% ` Timothy
1 sibling, 1 reply; 200+ results
From: Timothy @ 2021-09-19 13:13 UTC (permalink / raw)
To: Morgan Willcock; +Cc: emacs-orgmode
[-- Attachment #1: Type: text/plain, Size: 646 bytes --]
Hi Morgan,
I’ve just taken a look at your patch (it `git am's just fine), since nobody else
seems to have had the time to look at your patch as of late. There’s one thing
which I now realise completely slipped by me last time — why are tabs bad?
Maybe I’m missing something obvious, but exporting with tabs and viewing/`cat'ing
the file everything looks fine to me in terms of alignment.
Morgan Willcock <mwillcock@precedence.co.uk> writes:
> I’ve attached a patch to fix an issue where tab characters are generated by
> the ASCII exporter when `indent-tabs-mode’ has its default value of t.
All the best,
Timothy
^ permalink raw reply [relevance 92%]
* Re: [PATCH] Fixed lstset where language= wipes out previous definitions
@ 2021-09-19 13:02 93% ` Timothy
0 siblings, 0 replies; 200+ results
From: Timothy @ 2021-09-19 13:02 UTC (permalink / raw)
To: Karl Stump; +Cc: emacs-orgmode
[-- Attachment #1: Type: text/plain, Size: 1426 bytes --]
Hi Karl,
Thanks for sending in this patch, and sorry it’s taken so long for someone to
get back to you. Would you mind explaining the issue here a bit more? I can’t
see at a glance how preceding definitions are wiped in the current
code.
Karl Stump <karlstump@gmail.com> writes:
> * ox-latex.el (org-latex-src-block): moved ((“language” ,lst-lang)) to the head of the list.
> This fixes wiping out preceding definitions given in `org-latex-listings-options’.
> TINYCHANGE
> —
> lisp/ox-latex.el | 4 ++–
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff –git a/lisp/ox-latex.el b/lisp/ox-latex.el
> index b9ecf070a..f956c851e 100644
> — a/lisp/ox-latex.el
> +++ b/lisp/ox-latex.el
> @@ -3075,13 +3075,13 @@ contextual information.“
> (concat
> (org-latex–make-option-string
> (append
> - lst-opt
> + `((”language“ ,lst-lang))
> + lst-opt
> (cond
> ((and (not float) (plist-member attributes :float)) nil)
> ((string= ”multicolumn“ float) ’((”float“ ”*“)))
> ((and float (not (assoc ”float“ lst-opt)))
> `((”float“ ,(plist-get info :latex-default-figure-position)))))
> - `((”language“ ,lst-lang))
> (if label
> `((”label“ ,(org-latex–label src-block info)))
> ’((”label“ ” “)))
All the best,
Timothy
^ permalink raw reply [relevance 93%]
* Re: [PATCH] Various minor docfixes found by checkdoc
@ 2021-09-19 13:00 93% ` Timothy
0 siblings, 0 replies; 200+ results
From: Timothy @ 2021-09-19 13:00 UTC (permalink / raw)
To: emacs-orgmode
[-- Attachment #1: Type: text/plain, Size: 66 bytes --]
Just marking as applied for <https://updates.orgmode.org/> 🙂.
^ permalink raw reply [relevance 93%]
* Re: [PATCH] ob-tangle.el: Fix error in org-tangle from org-src edit buffer
@ 2021-09-19 12:57 93% ` Timothy
0 siblings, 0 replies; 200+ results
From: Timothy @ 2021-09-19 12:57 UTC (permalink / raw)
To: markgdawson; +Cc: emacs-orgmode
Hi Mark,
Many thanks for not only tracking down this problem but making a fix and
submitting it 🙂. I've just pushed this as 986341b with minor tweaks to the
commit message.
Mark Dawson <markgdawson@gmail.com> writes:
> [PATCH] ob-tangle.el: Fix error in org-tangle from org-src edit
> buffer
>
> (org-babel-tangle) : Fix stringp error which happens when confirming
> successful tangle when `org-babel-tangle` is called from an org-src edit
> buffer.
>
> TINYCHANGE
> ---
> lisp/ob-tangle.el | 5 ++++-
> 1 file changed, 4 insertions(+), 1 deletion(-)
>
> diff --git a/lisp/ob-tangle.el b/lisp/ob-tangle.el
> index 2f60ef9a4..0768c8588 100644
> --- a/lisp/ob-tangle.el
> +++ b/lisp/ob-tangle.el
> @@ -281,7 +281,10 @@ matching a regular expression."
> (if (= block-counter 1) "" "s")
> (file-name-nondirectory
> (buffer-file-name
> - (or (buffer-base-buffer) (current-buffer)))))
> + (or (buffer-base-buffer)
> + (current-buffer)
> + (and (org-src-edit-buffer-p)
> + (org-src-source-buffer))))))
> ;; run `org-babel-post-tangle-hook' in all tangled files
> (when org-babel-post-tangle-hook
> (mapc
--
Timothy
^ permalink raw reply [relevance 93%]
* Re: [PATCH] minor typo fix in org-tutorials/org-protocol-custom-handler.org
@ 2021-09-19 12:42 93% ` Timothy
0 siblings, 0 replies; 200+ results
From: Timothy @ 2021-09-19 12:42 UTC (permalink / raw)
To: emacs-orgmode
[-- Attachment #1: Type: text/plain, Size: 43 bytes --]
Marking as applied on updates.orgmode.org.
^ permalink raw reply [relevance 93%]
* Re: [PATCH] Rename headline to heading
@ 2021-09-19 11:06 89% ` Timothy
1 sibling, 0 replies; 200+ results
From: Timothy @ 2021-09-19 11:06 UTC (permalink / raw)
To: André A. Gomes; +Cc: emacs-orgmode
[-- Attachment #1: Type: text/plain, Size: 776 bytes --]
Hi André,
Sorry that you haven’t heard anything in a while. I’ve been hoping that Bastien
or Nicolas might have been able to take a look at this and give their thoughts,
but unfortunately judging from their recent activity they both seem to be quite
busy as of late. I dream of the day when Org could actually employ a full-time
maintainer via opencollective (or similar).
In the meantime, I’ve flagged this message in my own mail client, and it appears
on <https://updates.orgmode.org/> so you can at least be sure that this won’t be
forgotten about.
> I’m still waiting for the FSF to send me back my form signed. I’ve sent
> it on the 31st of July.
Could you let us know if the FSF have got back to you on this?
All the best,
Timothy
^ permalink raw reply [relevance 89%]
* Re: [PATCH] Re: [BUG] Creating sparse tree with regexp property matches
@ 2021-09-17 10:17 85% ` Timothy
0 siblings, 0 replies; 200+ results
From: Timothy @ 2021-09-17 10:17 UTC (permalink / raw)
To: Daniel Fleischer; +Cc: emacs-orgmode, Cassio Koshikumo
[-- Attachment #1: Type: text/plain, Size: 854 bytes --]
Hi Daniel,
Thanks for bumping your patch, unfortunately many of us (people who can push to
Org) seem to be stretched a bit thin as of late. I’ve just gone over it, it
reads well IMO and I think looking at the non-trivial changes in your patch it’s
possible to charitably interpret this as <=15 non-trivial lines changed. I’ve
applied this as 6600dc09 on Org master with a tweaked commit message 🙂.
Documentation is vital to communicating what Org offers to users, so thanks
again for going to the effort to clear up a possible point of confusion. Should
you wish to make any further contributions (which would be great!) it would be
very helpful if you could get FSF assignment (see
<https://orgmode.org/contribute.html>), as we can’t accept more than 15 lines of
non-trivial lines as an FSF project.
All the best,
Timothy
^ permalink raw reply [relevance 85%]
* Re: [PATCH] Fix some typos
@ 2021-09-17 9:03 93% ` Timothy
0 siblings, 0 replies; 200+ results
From: Timothy @ 2021-09-17 9:03 UTC (permalink / raw)
To: Stefan Kangas; +Cc: emacs-orgmode
[-- Attachment #1: Type: text/plain, Size: 161 bytes --]
Hi Stefan,
Thanks again for going through our documentation and picking up these mistakes.
I’ve just applied this as 215d80d :)
All the best,
Timothy
^ permalink raw reply [relevance 93%]
* Re: [BUG?][PATCH] Should the `lexical-binding' variable be bound during src block with :lexical t? [9.4.6 (9.4.6-ga451f9 @ /home/n/.emacs.d/straight/build/org/)]
@ 2021-09-10 6:32 93% ` Timothy
0 siblings, 0 replies; 200+ results
From: Timothy @ 2021-09-10 6:32 UTC (permalink / raw)
To: No Wayman; +Cc: emacs-orgmode
[-- Attachment #1: Type: text/plain, Size: 363 bytes --]
Hi NoWayman,
> I ran into this with some code I’m writing which checks against
> `lexical-binding’.
> Should the following result in “lexical binding enabled” or
> “lexical binding disabled”?:
Can you think of any examples where this results in different behaviour (without
explicitly checking `lexical-binding')?
All the best,
Timothy
^ permalink raw reply [relevance 93%]
* Re: [PATCH] Re: New source block results option for attaching file to node
@ 2021-09-10 6:26 93% ` Timothy
0 siblings, 0 replies; 200+ results
From: Timothy @ 2021-09-10 6:26 UTC (permalink / raw)
To: Ryan Scott; +Cc: Greg Minshall, emacs-orgmode, Ihor Radchenko
[-- Attachment #1.1: Type: text/plain, Size: 234 bytes --]
Hi Ryan,
I’ve just had a glance, but this looks much better to me than what was proposed
earlier 👍. Hopefully we’ll be able to get some feedback on this from others,
and then see it merged 🙂.
All the best,
Timothy
[-- Attachment #1.2: Type: text/html, Size: 7242 bytes --]
^ permalink raw reply [relevance 93%]
* Re: [PATCH] ox-latex: Allow percent sign in 'src-block' caption
@ 2021-09-07 13:17 93% ` Timothy
0 siblings, 0 replies; 200+ results
From: Timothy @ 2021-09-07 13:17 UTC (permalink / raw)
To: Maxim Nikulin; +Cc: emacs-orgmode
[-- Attachment #1: Type: text/plain, Size: 734 bytes --]
Hi Maxim,
> I have decided that it is better to provide a partial fix than to leave
> the problem as is. This patch covers only plain verbatim environment,
> more advanced formatting using listings or minted should be addressed
> by another change (Anybody?). Do not close the bug after applying
> this patch.
>
> [2. text/x-patch; 0001-ox-latex-Allow-percent-sign-in-src-block-caption.patch]…
Thanks for the patch. At a glance it looks good, and it’s great to see you’ve
gone to the effort of writing some tests for it too! That’s something we should
probably do more of 😅. Hopefully someone else will get around to giving your
work a closer look and maybe merge it soon-ish :)
All the best,
Timothy
^ permalink raw reply [relevance 93%]
* Re: [patch] priorities range reversed
@ 2021-08-31 15:14 93% ` Timothy
0 siblings, 0 replies; 200+ results
From: Timothy @ 2021-08-31 15:14 UTC (permalink / raw)
To: Joe Corneli; +Cc: emacs-orgmode
[-- Attachment #1: Type: text/plain, Size: 1089 bytes --]
Hi Joe,
Thanks for looking into this and figuring out a patch. I’ve just taken a peek at
your patches, and I have two minor comments:
⁃ Why use saved-position instead of save-excursion
⁃ I’m think ascii versions of ② et. al would be preferable
Also, I notice that your patches are just diffs and don’t have a commit message.
Are you planning on writing them later?
Joe Corneli via “General discussions about Org-mode.” <emacs-orgmode@gnu.org> writes:
> Actually, there some bigger problems with the function as well…
>
> — It didn’t update the priority cookie properly when one had been set before
>
> * [#1] Exercise: update to [#2]
>
> — After fixing that, I noticed that the included save-excursion doesn’t work
> (<https://emacs.stackexchange.com/questions/7574/why-save-excursion-doesnt-save-point-position>)
>
> So, here’s a more comprehensive patch, including the previous changes
> (in order to support numeric priorities) and then adjusting the
> update/insert logic so that it makes more sense.
All the best,
Timothy
^ permalink raw reply [relevance 93%]
* Re: [PATCH] Fix match/maxlevel conflict in colview dynblock
@ 2021-08-31 14:33 93% ` Timothy
0 siblings, 0 replies; 200+ results
From: Timothy @ 2021-08-31 14:33 UTC (permalink / raw)
To: Nick Dokos; +Cc: emacs-orgmode
[-- Attachment #1: Type: text/plain, Size: 2522 bytes --]
Hi Nick,
Thanks for reporting this issue here, and providing a patch. Unfortunately the
“main maintainers” seem to be rather busy as of late, leaving you hanging for
quite a while. I’ve had a look at the issue and your patch, and it the issue
seems clear, and your patch small and straightforward enough that I feel
confident pushing it should be fine :) it’s now on master with a small tweak to
the commit message.
Thanks for your efforts.
> Specifying both `maxlevel’ and `match’ in a columnview dynamic block
> was broken: the `match’ argument is ignored in that case. See the link
> below for a (not so minimal) ECM.
>
> Reported-by: Pablo A Perez-Fernandez
> Link: <https://emacs.stackexchange.com/questions/66658/filter-columnview-dblock-on-properties-or-tags>
>
> –
> Nick
>
> “There are only two hard problems in computer science: cache
> invalidation, naming things, and off-by-one errors.” -Martin Fowler
>
> From 8bcff482e59c24758f87b9b5cdef3bc123dc12f8 Mon Sep 17 00:00:00 2001
> From: Nick Dokos <ndokos@gmail.com>
> Date: Sun, 11 Jul 2021 22:30:22 -0400
> Subject: [PATCH] Fix match/maxlevel conflict in colview dynblock
>
> * lisp/org-coplview.el (org-columns–capture-view): Combine the match
> and maxlevel arguments properly to construct the MATCH argument of
> `org-map-entries’.
>
> Specifying both `maxlevel’ and `match’ in a columnview dynamic block
> does not work: the `match’ argument is ignored in that case. See the
> link below for a (not so minimal) ECM.
>
> Reported-by: Pablo A Perez-Fernandez
> Link: <https://emacs.stackexchange.com/questions/66658/filter-columnview-dblock-on-properties-or-tags>
> —
> lisp/org-colview.el | 5 +++–
> 1 file changed, 3 insertions(+), 2 deletions(-)
>
> diff –git a/lisp/org-colview.el b/lisp/org-colview.el
> index 2e1c29a99..7144308ff 100644
> — a/lisp/org-colview.el
> +++ b/lisp/org-colview.el
> @@ -1398,8 +1398,9 @@ other rows. Each row is a list of fields, as strings, or
> (org-get-tags))))
> (push (cons (org-reduced-level (org-current-level)) (nreverse row))
> table)))))
> - (or (and maxlevel (format “LEVEL<=%d” maxlevel))
> - (and match match))
> + (if match
> + (concat match (and maxlevel (format “+LEVEL<=%d” maxlevel)))
> + (and maxlevel (format “LEVEL<=%d” maxlevel)))
> (and local ’tree)
> ’archive ’comment)
> (org-columns-quit)
All the best,
Timothy
^ permalink raw reply [relevance 93%]
* Re: [PATCH] Fix bug assuming canonical duration units in org-agenda-format-items
@ 2021-08-31 13:55 93% ` Timothy
0 siblings, 0 replies; 200+ results
From: Timothy @ 2021-08-31 13:55 UTC (permalink / raw)
To: Anders Johansson; +Cc: emacs-orgmode, Nicolas Goaziou
[-- Attachment #1: Type: text/plain, Size: 688 bytes --]
Hi Anders,
Did you have any thoughts on Nicolas’ comments?
Nicolas Goaziou <mail@nicolasgoaziou.fr> writes:
> Hello,
>
> Anders Johansson <mejlaandersj@gmail.com> writes:
>
>> org-duration-from-minutes was called with canonical = t, but without
>> providing a corresponding format only using the canonical units. This
>> broke if the user’s org-duration-format used other than the canonical
>> units.
>
> I think a proper fix would be to change `org-duration-from-minutes’ so
> it removes any unknown unit from what is provided from fmt or
> `org-duration-format’, and defaults to (special . h:mm) if nothing is
> left.
>
> WDYT?
All the best,
Timothy
^ permalink raw reply [relevance 93%]
* Re: [PATCH] ox-ascii.el: Fix justify when `indent-tabs-mode' is non-nil
@ 2021-08-31 12:54 93% ` Timothy
0 siblings, 0 replies; 200+ results
From: Timothy @ 2021-08-31 12:54 UTC (permalink / raw)
To: Morgan Willcock; +Cc: emacs-orgmode
[-- Attachment #1: Type: text/plain, Size: 348 bytes --]
Hi Morgan,
> Great! Thank you for taking a look.
No problem, thanks for making the patch :)
> I used `git send-email` which is listed as being OK on the website:
Huh, I guess it should be fine then. I’ve just never seen the commit message at
the top like that so I assumed you’d done it by hand. :shrug:
All the best,
Timothy
^ permalink raw reply [relevance 93%]
* Re: [PATCH] ox-ascii.el: Fix justify when `indent-tabs-mode' is non-nil
@ 2021-08-31 11:59 90% ` Timothy
2021-09-19 13:13 92% ` Timothy
1 sibling, 1 reply; 200+ results
From: Timothy @ 2021-08-31 11:59 UTC (permalink / raw)
To: Morgan Willcock; +Cc: emacs-orgmode
[-- Attachment #1: Type: text/plain, Size: 754 bytes --]
Hi Morgan,
> I’ve attached a patch to fix an issue where tab characters are generated by
> the ASCII exporter when `indent-tabs-mode’ has its default value of t.
Thanks for finding this bug, fixing it, and sending us it 🙂. I was able to
reproduce your test case with “emacs -Q” (thanks for that, by the way).
As you suspected, with the small number of changed lines, this would be fine to
accept without FSF assignment.
However, your “patch” seems to consist of a diff at the bottom of your email and
a commit message at the top?? It would be preferable if you could provide a
“proper” patch, that way you can get attribution for your help instead of just
someone committing it on your behalf.
All the best,
Timothy
^ permalink raw reply [relevance 90%]
* Re: [PATCH] Update some changed export keybindings [worg]
@ 2021-08-31 11:37 93% ` Timothy
0 siblings, 0 replies; 200+ results
From: Timothy @ 2021-08-31 11:37 UTC (permalink / raw)
To: Stefan Kangas; +Cc: emacs-orgmode
[-- Attachment #1: Type: text/plain, Size: 501 bytes --]
Hi Stefan,
Thanks for the patch. I’ve just applied it. I haven’t had a look at the other
“C-c C-e” keybindings, but I’m glad that you brought it up. Hopefully someone
else will take a look at some point.
> The attached patch fixes some incorrect keybindings in worg.
>
> I’d recommend that someone takes a look at all the “C-c C-e …”
> keybindings, as there are some that I was unsure about, and may still
> be incorrect even after this patch.
All the best,
Timothy
^ permalink raw reply [relevance 93%]
* Re: [PATCH] org-cite: prevent ' from being an active char in LaTeX export
2021-08-23 10:27 72% [PATCH] org-cite: prevent ' from being an active char in " Timothy
@ 2021-08-26 8:24 93% ` Timothy
0 siblings, 0 replies; 200+ results
From: Timothy @ 2021-08-26 8:24 UTC (permalink / raw)
To: emacs-orgmode
[-- Attachment #1: Type: text/plain, Size: 263 bytes --]
Heyo,
> This is a band-aid over the issue raised in
> <https://lists.gnu.org/archive/html/emacs-orgmode/2021-08/msg00342.html>.
As this actually fixes a real annoyance, and is a trivial change, I’m pushing
this as a3ba79cd3a.
All the best,
Timothy
^ permalink raw reply [relevance 93%]
* Re: [PATCH] org-cite: define \citeprocitem for LaTeX export
2021-08-23 10:23 75% [PATCH] org-cite: define \citeprocitem for LaTeX export Timothy
@ 2021-08-26 8:18 93% ` Timothy
2021-09-19 13:19 93% ` Timothy
0 siblings, 1 reply; 200+ results
From: Timothy @ 2021-08-26 8:18 UTC (permalink / raw)
To: emacs-orgmode
[-- Attachment #1: Type: text/plain, Size: 276 bytes --]
Heyo,
As it’s been a few days, given the prior consultation with citeproc-el, and that
this is a very small change, I’m pushing this as 818bec57eb. We can always
revert/patch over in case I’m walking on someone’s (nickolas’?) toes :)
All the best,
Timothy
^ permalink raw reply [relevance 93%]
* [PATCH] org-cite: prevent ' from being an active char in LaTeX export
@ 2021-08-23 10:27 72% Timothy
2021-08-26 8:24 93% ` Timothy
0 siblings, 1 reply; 200+ results
From: Timothy @ 2021-08-23 10:27 UTC (permalink / raw)
To: emacs-orgmode
[-- Attachment #1: Type: text/plain, Size: 750 bytes --]
Hi All,
This is a band-aid over the issue raised in
<https://lists.gnu.org/archive/html/emacs-orgmode/2021-08/msg00342.html>.
I’ve come across an issue with the `hanging’ package we’re currently using for
LaTeX exports — it also affects punctuation, and makes `,.’“`?!:;’ active
characters throughout the entire document. That means a LaTeX snippet like:
f’(x) Will now fail to compile ☹. See…
By just adding the [notquote] option, ’ is no longer an active char, and so
f’(x) no longer breaks documents. Long-term, I still think that getting rid of
all this active char stuff would be a good idea, by switching out hanging for
use of `\parshape' if possible.
All the best,
Timothy
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-oc-csl-Prevent-from-being-a-LaTeX-active-char.patch --]
[-- Type: text/x-patch, Size: 1358 bytes --]
From ad63eb8f4d7d02c9864d5caded0b4f2ee9f54133 Mon Sep 17 00:00:00 2001
From: TEC <tec@tecosaur.com>
Date: Mon, 23 Aug 2021 18:18:33 +0800
Subject: [PATCH] oc-csl: Prevent ' from being a LaTeX active char
* lisp/oc-csl.el (org-cite-csl-finalizer): The hanging LaTeX package
we're using also affects punctuation and makes `,.'"`?!:;' active
characters throughout the entire document. That means a LaTeX snippet
like \(f'(x)\) will now make the document fail to compile.
See <https://tex.stackexchange.com/questions/61732/hanging-package-chokes-on-apostrophes>
for more information. Adding the [notquote] option stops \(f'(x)\) from
being an issue.
In time it could be worth looking into replacing the hanging package
with some use of \parshape.
---
lisp/oc-csl.el | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/lisp/oc-csl.el b/lisp/oc-csl.el
index 617bddb7e..36a885641 100644
--- a/lisp/oc-csl.el
+++ b/lisp/oc-csl.el
@@ -595,7 +595,7 @@ (defun org-cite-csl-finalizer (output _keys _files _style _backend info)
(goto-char (match-beginning 0))
(let ((re (rx "\\usepackage" (opt "[" (*? nonl) "]") "{hanging}")))
(unless (re-search-backward re nil t)
- (insert "\\usepackage{hanging}\n"))))
+ (insert "\\usepackage[notquote]{hanging}\n"))))
(buffer-string))))
\f
--
2.32.0
^ permalink raw reply related [relevance 72%]
* [PATCH] org-cite: define \citeprocitem for LaTeX export
@ 2021-08-23 10:23 75% Timothy
2021-08-26 8:18 93% ` Timothy
0 siblings, 1 reply; 200+ results
From: Timothy @ 2021-08-23 10:23 UTC (permalink / raw)
To: emacs-orgmode
[-- Attachment #1.1: Type: text/plain, Size: 528 bytes --]
Hi All,
There’s been a discussion over at citeproc-el about how to make hyperref treat
its references the same way as bib(la)tex references, and to get this to work we
need to add a command definition to the preamble, `\citeprocitem'.
┌────
│ \makeatletter
│ \newcommand{\citeprocitem}[2]{\hyper@linkstart{cite}{citeproc_bib_item_#1}#2\hyper@linkend}
│ \makeatother
└────
See <https://github.com/andras-simonyi/citeproc-el/issues/34> for more information.
All the best,
*Timothy*
[-- Attachment #1.2: Type: text/html, Size: 4006 bytes --]
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0003-oc-csl-Define-citeprocitem-for-LaTeX-export.patch --]
[-- Type: text/x-patch, Size: 1409 bytes --]
From 0988d1c331b8872a4c4aa1b1ea40aa2f9f668d17 Mon Sep 17 00:00:00 2001
From: TEC <tec@tecosaur.com>
Date: Mon, 23 Aug 2021 18:14:05 +0800
Subject: [PATCH 3/4] oc-csl: Define \citeprocitem for LaTeX export
* lisp/oc-csl.el (org-cite-csl-finalizer): In order for
citeproc-generated references to be treated the same as bib(la)tex
references by hyperref, we need to make use of \hyper@linkstart.
However, this requires \makeatletter and \makeatother, which can only be
used in the preamble. To allow citeproc-el to use \hyper@linkstart, we
add a command definition in the preamble, \citeprocitem.
---
lisp/oc-csl.el | 2 ++
1 file changed, 2 insertions(+)
diff --git a/lisp/oc-csl.el b/lisp/oc-csl.el
index 0a057036e..617bddb7e 100644
--- a/lisp/oc-csl.el
+++ b/lisp/oc-csl.el
@@ -589,6 +589,8 @@ (defun org-cite-csl-finalizer (output _keys _files _style _backend info)
(with-temp-buffer
(save-excursion (insert output))
(when (search-forward "\\begin{document}" nil t)
+ ;; Ensure that \citeprocitem is defined for citeproc-el
+ (insert "\\makeatletter\n\\newcommand{\\citeprocitem}[2]{\\hyper@linkstart{cite}{citeproc_bib_item_#1}#2\\hyper@linkend}\n\\makeatother\n\n")
;; Ensure there is a \usepackage{hanging} somewhere or add one.
(goto-char (match-beginning 0))
(let ((re (rx "\\usepackage" (opt "[" (*? nonl) "]") "{hanging}")))
--
2.32.0
^ permalink raw reply related [relevance 75%]
* Re: [PATCH] org-agenda.el: Avoid dependency on subr-x
@ 2021-08-06 20:30 93% ` Timothy
0 siblings, 0 replies; 200+ results
From: Timothy @ 2021-08-06 20:30 UTC (permalink / raw)
To: Maxim Nikulin; +Cc: emacs-orgmode
[-- Attachment #1: Type: text/plain, Size: 778 bytes --]
Hi Maxim,
> Timothy, I have seen that discussion. For me it does not matter in which way
> org-agenda.el will be fixed: by adding (require ’subr-x) or by using string=
> instead of string-empty-p. Both variants work with Emacs-26.3. The point is that
> “make single” should work without warnings and in the case of mixed install
> users should not get confusing errors that resemble real issues.
>
> The only reason why I suggested namely to avoid string-empty-p is that
> compatibility with Emacs-24.3 is still declared in Org sources.
Ah, cool. I took your original email to indicate that this change was solely for
Emacs 24.3 comparability, but I now see you simply used that as a reason to
choose between two different fixes.
All the best,
Timothy
^ permalink raw reply [relevance 93%]
* Re: [PATCH] Fix regression in org-get-time-of-day introduced in aba1f2066
@ 2021-07-24 19:48 93% ` Timothy
0 siblings, 0 replies; 200+ results
From: Timothy @ 2021-07-24 19:48 UTC (permalink / raw)
To: emacs-orgmode
Marking as applied for updates.orgmode.org.
Nicolas Goaziou <mail@nicolasgoaziou.fr> writes:
> Thanks. I applied a slightly different fix.
--
Timothy
^ permalink raw reply [relevance 93%]
* Re: [PATCH] ob-core: tangle check library of babel after current buffer
@ 2021-07-24 19:41 93% ` Timothy
0 siblings, 0 replies; 200+ results
From: Timothy @ 2021-07-24 19:41 UTC (permalink / raw)
To: Tom Gillespie; +Cc: emacs-orgmode
Hi Tom,
Sorry that it's taken so long for someone to get to this. I've just
applied your patch to my local Org instance, and then tested the
described behaviour before and afterwards. I can confirm that the issue
reported exists, and that your patch fixes this.
In light of this and the two other positive reviews here, I feel it's
pretty safe, and so have applied this patch as f052acee5 :)
--
Timothy
Tom Gillespie <tgbugs@gmail.com> writes:
> Pinging on this to see if anyone can test it so that it can be merged.
> Tom
>
> On Wed, Jun 16, 2021 at 4:29 PM Tom Gillespie <tgbugs@gmail.com> wrote:
>>
>> Hi,
>> This is a patch that fixes tangling behavior when a block has been
>> ingested into the library of babel and then modified. Best!
>> Tom
--
Timothy
^ permalink raw reply [relevance 93%]
* Re: [PATCH] bad table formula recorded in some cases
@ 2021-07-21 15:07 93% ` Timothy
0 siblings, 0 replies; 200+ results
From: Timothy @ 2021-07-21 15:07 UTC (permalink / raw)
To: tbanelwebmin; +Cc: emacs-orgmode
Hi Thierry,
tbanelwebmin <tbanelwebmin@free.fr> writes:
> I don't know the intention. But the answer may lie in the comment 4
> lines above:
> ;; Don't overwrite TBLFM, we might use text properties to
> ;; store stuff.
>
> In this case, the intention would be to keep the original "#+TBLFM:"
> instead of inserting a fresh new one.
>
> But we are in the else branch of (if (looking-at ...)), which means
> there was no "#+TBLFM:". And no text properties to save. Therefore we
> may safely remove this (match-string 2).
Thank you for looking into this, I'm reassured by your inference that
this change is safe to make. I'm not really one of the main
contribution-acceptors/pushers though, so I'd rather leave this for
someone like Nicolas to sign off on.
Would you mind bumping this thread in a few weeks if nothing happens?
Hope that's not too much of an inconvenience,
Timothy.
> Le 21/07/2021 à 12:50, Timothy a écrit :
>> Hi Thierry,
>>
>> Thanks for this! Looking at the change you suggest, do you know why the
>> (match-string 2) bit might have been added in the first place? I'm just
>> wondering if there might be some edge-case adversely affected by this ---
>> hence trading one bug for another :P
>>
>> --
>> Timothy
>>
>> tbanelwebmin <tbanelwebmin@free.fr> writes:
>>
>>> Small bug, small fix.
>>>
>>> Suppose we have a table embedded in a begin-end block.
>>>
>>> #+begin: aaa :param value
>>> | a | b |
>>> | a | b |
>>> #+end:
>>>
>>> Suppose we want to add a formula, with C-c =
>>> We end up with an incorrect result:
>>>
>>> #+begin: aaa :param value
>>> | a | 33 |
>>> | a | b |
>>> :param value $2=33
>>> #+end:
>>>
>>> The fix: in org-table.el, line 2177, change
>>> (insert (or (match-string 2) "#+TBLFM:")))
>>> to
>>> (insert "#+TBLFM:"))
>>>
>>> Then we get the correct result:
>>>
>>> #+begin: aaa :param value
>>> | a | 33 |
>>> | a | b |
>>> #+TBLFM: $2=33
>>> #+end:
>>>
>>> Why? Because (match-string 2) is supposed to refer to the (looking-at)
>>> instruction 7 lines above. But (match-string 2) is in the else branch,
>>> which means that (looking-at) failed. Therefore (match-string 2) returns
>>> garbage.
>>>
>>> Thanks to Uwe Brauer for pointing to this bug.
^ permalink raw reply [relevance 93%]
* Re: [PATCH] bad table formula recorded in some cases
@ 2021-07-21 10:50 93% ` Timothy
0 siblings, 1 reply; 200+ results
From: Timothy @ 2021-07-21 10:50 UTC (permalink / raw)
To: tbanelwebmin; +Cc: emacs-orgmode
Hi Thierry,
Thanks for this! Looking at the change you suggest, do you know why the
(match-string 2) bit might have been added in the first place? I'm just
wondering if there might be some edge-case adversely affected by this ---
hence trading one bug for another :P
--
Timothy
tbanelwebmin <tbanelwebmin@free.fr> writes:
> Small bug, small fix.
>
> Suppose we have a table embedded in a begin-end block.
>
> #+begin: aaa :param value
> | a | b |
> | a | b |
> #+end:
>
> Suppose we want to add a formula, with C-c =
> We end up with an incorrect result:
>
> #+begin: aaa :param value
> | a | 33 |
> | a | b |
> :param value $2=33
> #+end:
>
> The fix: in org-table.el, line 2177, change
> (insert (or (match-string 2) "#+TBLFM:")))
> to
> (insert "#+TBLFM:"))
>
> Then we get the correct result:
>
> #+begin: aaa :param value
> | a | 33 |
> | a | b |
> #+TBLFM: $2=33
> #+end:
>
> Why? Because (match-string 2) is supposed to refer to the (looking-at)
> instruction 7 lines above. But (match-string 2) is in the else branch,
> which means that (looking-at) failed. Therefore (match-string 2) returns
> garbage.
>
> Thanks to Uwe Brauer for pointing to this bug.
^ permalink raw reply [relevance 93%]
* Re: [PATCH] be more cautious when setting csl etc dir location
2021-07-12 18:07 71% [PATCH] be more cautious when setting csl etc dir location Timothy
@ 2021-07-14 19:39 93% ` Timothy
0 siblings, 0 replies; 200+ results
From: Timothy @ 2021-07-14 19:39 UTC (permalink / raw)
To: org-mode-email
Applied.
This seems quite simple, so I've taken the liberty of applying the
patch. Please don't hesitate to revert it if something seems off.
--
Timothy <tecosaur@gmail.com> writes:
> Hello,
>
> It's come to my attention that the current value of
> org-cite-ctl--etc-dir is problematic for anyone managing Org with
> package.el or straight. This patch adds a check to see if the initial
> location actually exists, if it doesn't we try the expected location
> when using package.el/straight.
^ permalink raw reply [relevance 93%]
* [PATCH] be more cautious when setting csl etc dir location
@ 2021-07-12 18:07 71% Timothy
2021-07-14 19:39 93% ` Timothy
0 siblings, 1 reply; 200+ results
From: Timothy @ 2021-07-12 18:07 UTC (permalink / raw)
To: org-mode-email
[-- Attachment #1: Type: text/plain, Size: 311 bytes --]
Hello,
It's come to my attention that the current value of
org-cite-ctl--etc-dir is problematic for anyone managing Org with
package.el or straight. This patch adds a check to see if the initial
location actually exists, if it doesn't we try the expected location
when using package.el/straight.
--
Timothy
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-oc-csl-be-more-caution-about-the-csl-etc-location.patch --]
[-- Type: text/x-patch, Size: 1639 bytes --]
From 5e6700177f4ef59131c153d985b8eaeb3b303799 Mon Sep 17 00:00:00 2001
From: TEC <tec@tecosaur.com>
Date: Tue, 13 Jul 2021 02:00:38 +0800
Subject: [PATCH] oc-csl: be more caution about the csl etc location
* lisp/oc-csl.el (org-cite-ctl--etc-dir): The previous value of
`org-cite-ctl--etc-dir' is incorrect when using either package.el or
straight to manage Org. We can be a bit more considerate by just
checking if the initial location exists, and then trying the expected
location when using package.el/straight if it doesn't exist.
---
lisp/oc-csl.el | 11 ++++++++---
1 file changed, 8 insertions(+), 3 deletions(-)
diff --git a/lisp/oc-csl.el b/lisp/oc-csl.el
index a7a2a6042..5e0e27211 100644
--- a/lisp/oc-csl.el
+++ b/lisp/oc-csl.el
@@ -177,9 +177,14 @@ (defcustom org-cite-csl-latex-hanging-indent "1.5em"
\f
;;; Internal variables
(defconst org-cite-csl--etc-dir
- (expand-file-name
- (concat (file-name-directory (locate-library "oc"))
- "../etc/csl/"))
+ (let* ((oc-root (file-name-directory (locate-library "oc")))
+ (oc-etc-dir-1 (expand-file-name "../etc/csl/" oc-root)))
+ ;; package.el and straight will put all of org-mode/lisp/ in org-mode/.
+ ;; This will cause .. to resolve to the directory above Org.
+ ;; To make life easier for people using package.el or straight, we can
+ ;; check to see if ../etc/csl exists, and if it doesn't try ./etc/csl.
+ (if (file-exists-p oc-etc-dir-1) oc-etc-dir-1
+ (expand-file-name "etc/csl/" oc-root)))
"Directory \"etc/\" from repository.")
(defconst org-cite-csl--fallback-locales-dir org-cite-csl--etc-dir
--
2.32.0
^ permalink raw reply related [relevance 71%]
* Re: [PATCH] Change default latex compiler to latexmk
@ 2021-07-09 16:41 93% ` Timothy
0 siblings, 0 replies; 200+ results
From: Timothy @ 2021-07-09 16:41 UTC (permalink / raw)
To: Bastien; +Cc: org-mode-email, Bruce D'Arcus
Bastien <bzg@gnu.org> writes:
> You can consider this an explicit approval :) Even if we do something
> wrong, we can always discuss and revert it.
>
> Thanks!
Pushed :) For future reference, should I be less wary of pushing commits
I'm confident in and haven't had any negative feedback on?
--
Timothy
p.s. updates.orgmode.org is returning a 502 error again
^ permalink raw reply [relevance 93%]
* Re: [PATCH] Change default latex compiler to latexmk
@ 2021-07-09 14:25 93% ` Timothy
0 siblings, 1 reply; 200+ results
From: Timothy @ 2021-07-09 14:25 UTC (permalink / raw)
To: Bastien; +Cc: org-mode-email, Bruce D'Arcus
Bastien <bzg@gnu.org> writes:
> I let Timothy decide.
I consider this patch fit to merge. I'm just under the impression that
this I should only push files I'm listed as a maintainer for without
explicit approval.
--
Timothy
^ permalink raw reply [relevance 93%]
* Re: [PATCH] ob-R output file with graphics parameter
@ 2021-07-03 4:52 92% ` Timothy
0 siblings, 0 replies; 200+ results
From: Timothy @ 2021-07-03 4:52 UTC (permalink / raw)
To: Jack Kamm; +Cc: Colin Baxter, Berry, Charles, emacs-orgmode
Jack Kamm <jackkamm@gmail.com> writes:
> I think it would still make sense though, and would be beneficial beyond
> ob-R. According to [1], the "graphics" and "link" arguments don't do
> anything unless used with "file", so it would make sense for them to
> automatically add the "file" argument.
Mmmm, I think it would be good if we could make it so it's generally
less effort to create plots.
Would it be strange if running the code block with just
:output graphics
Automatically added "link" if *only* graphics is set, and generated a
file name if no :file is set?
I think it would be nice if I could declare a "figures directory"
(default to "/tmp" or "."?) for exactly this.
--
Timothy
^ permalink raw reply [relevance 92%]
* Re: [PATCH] Customizify org-babel-fortran-compiler
@ 2021-07-01 14:45 93% ` Timothy
0 siblings, 0 replies; 200+ results
From: Timothy @ 2021-07-01 14:45 UTC (permalink / raw)
To: emacs-orgmode
Marking as closed in favour of 2nd email.
^ permalink raw reply [relevance 93%]
* Re: [PATCH] Customizify org-babel-fortran-compiler
@ 2021-07-01 14:40 85% ` Timothy
0 siblings, 0 replies; 200+ results
From: Timothy @ 2021-07-01 14:40 UTC (permalink / raw)
To: Nico Sonack; +Cc: emacs-orgmode
Hi Nico,
Thanks for sending in the patch. Seeing it pointed out, this seems like
a pretty obvious omission. This looks like it should be pretty easy to
merge :)
Four minor niggles with your commit message:
+ Since `defvar' and `defcustom' are elisp symbols, they should be
quoted as such.
+ It's probably better to avoid shorthand like "X -> Y", and write out
"Change X to Y" instead.
+ You have included "lisp/" in the commit subject, which isn't needed.
Just "ob-fortran.el" or even "ob-fortran" is enough here.
+ Your commit subject goes over 50 chars, which is undesirable.
Here's what I'd recommend:
#+begin_example
ob-fortran: Use a defcustom for fortran compiler
* lisp/ob-fortran.el (org-babel-fortran-compiler): Change `defvar' to `defcustom'
so that the fortran compiler is customizable like almost all other org-babel
compilers.
#+end_example
This is rather minor though, I mention this mostly as a note for the
future :)
--
Timothy
Nico Sonack <nsonack@outlook.com> writes:
> Hey there,
>
> I've been using org-mode for quite a while already and am pretty
> happy with it!
>
> Today I noticed a minor oddity, that occured when I tried to run some
> Fortran code with org-babel: it failed with the compiler not being
> found. Looking at the custom variables of the org-babel group, I was
> unable to find a compiler option for Fortran. Thus, I quickly patched
> the ob-fortran.el and turned the defvar of
> `org-babel-fortran-compiler' into a defcustom such that it is a little
> more consistent with the rest of the org-babel languages.
>
> The patch is attached to this mail. Please let me know if I should
> correct anything.
>
> Nico
^ permalink raw reply [relevance 85%]
* Re: [patch] add :url and :doi optional entries for export to BiBTeX
@ 2021-07-01 14:23 93% ` Timothy
0 siblings, 0 replies; 200+ results
From: Timothy @ 2021-07-01 14:23 UTC (permalink / raw)
To: Eric S Fraga; +Cc: emacs-orgmode
Hi Eric,
I've not used Org for exporting to BibTeX, so I don't really know what
I'm on about, but is there any particular reason why only some entries
have :url ? Other than that, this seems like a fairly straightforward
patch.
--
Timothy
Eric S Fraga <e.fraga@ucl.ac.uk> writes:
> I introduced an error in the previous patch. Please use this one.
> Thank you,
> eric
^ permalink raw reply [relevance 93%]
* Re: [PATCH] Fix erroneous tangling of blocks
@ 2021-07-01 13:38 93% ` Timothy
0 siblings, 0 replies; 200+ results
From: Timothy @ 2021-07-01 13:38 UTC (permalink / raw)
To: Jacopo De Simoi; +Cc: emacs-orgmode
HI Jacopo,
I've just taken a look at your patch and it looks good :) glad to see
you've also followed the commit message format. I hope this gets merged
soon.
--
Timothy
p.s. Just a little note for the future: it's good if you have full
sentences in the description of the changes.
Jacopo De Simoi <jacopods@protonmail.com> writes:
> Dear All,
>
> Please find attached a patch (against master) which takes care of the
> following issue. Assume I have a block like this
>
> #+begin_src sh :tangle no
> This should not be tangled
> #+end_src
>
> Then the block is correctly ignored when tangling the whole file, but
> erroneously tangled (to a file named "no") when tangling is run with the
> universal argument (so that only the current block should be tangled)
>
> This happens because the check for the "no" option is not performed when
> tangling a single block. In the proposed patch I address this issue by
> checking for the "no" option in the function org-babel-effective-tangled-
> filename
^ permalink raw reply [relevance 93%]
* Re: [PATCH] Allow LaTeX reference command (\ref) to be customised
@ 2021-06-09 17:38 93% ` Timothy
0 siblings, 0 replies; 200+ results
From: Timothy @ 2021-06-09 17:38 UTC (permalink / raw)
To: Nicolas Goaziou; +Cc: org-mode-email
Nicolas Goaziou <mail@nicolasgoaziou.fr> writes:
> Sure, LGTM!
Cool :) Merged.
Now the only other LaTeX PR I may poke you about in the future is the
latexmk one :P
--
Timothy
^ permalink raw reply [relevance 93%]
* Re: [PATCH] Allow LaTeX reference command (\ref) to be customised
@ 2021-06-09 13:36 90% ` Timothy
0 siblings, 1 reply; 200+ results
From: Timothy @ 2021-06-09 13:36 UTC (permalink / raw)
To: Nicolas Goaziou; +Cc: org-mode-email
Nicolas Goaziou <mail@nicolasgoaziou.fr> writes:
> I agree there is no good reason to hard-code "\ref", but, off the top of
> my head, there may be a couple of things to consider:
>
> 1. There is still a dangling \ref in `org-latex-footnote-defined-format';
I noticed this, but looking at the usage I think the user would be
surprised if changing \ref for sections, figures etc. also changed how
footnotes looked.
> 2. This change is already somewhat trivial using a link filter:
>
> (defun my-ref-link-filter (s &rest _)
> (replace-regexp-in-string (rx string-start "\\ref") "\\foo" s nil t))
>
> (add-to-list 'org-export-filter-link-functions #'my-ref-link-filter)
As are many things :P but I think it's worth making some more obvious to
users, and IMO this is worth it.
> 3. \hyperref is still hard-coded in `org-latex-link'; your patch could
> look like a partial solution.
A reference with a named description does use hyperref, but I think
that would still be expected --- let me know if you think otherwise
though.
> Those are not strong objections, so if you think none of them is worth
> considering, then I'm fine with your patch.
If what I've said above makes sense, I think it would be good to merge 👍.
All the best,
Timothy.
^ permalink raw reply [relevance 90%]
* Re: [PATCH] Allow LaTeX reference command (\ref) to be customised
2021-06-06 18:19 61% [PATCH] Allow LaTeX reference command (\ref) to be customised Timothy
@ 2021-06-09 2:11 93% ` Timothy
0 siblings, 1 reply; 200+ results
From: Timothy @ 2021-06-09 2:11 UTC (permalink / raw)
To: Nicolas Goaziou; +Cc: org-mode-email
Hi Nicolas,
Since this is a fairly small thing and ox-latex seems to be your domain,
I'm wondering if you've had a chance to take a look yet? (just making
sure this hasn't slipped by, given your recent replies in other threads).
> Hi All,
>
> I've started doing some more cross-referencing in documents exported to
> LaTeX, and a hardcoded use of \ref has begun to stand out to me as a
> rather annoying thing. Hypperef provides \autoref for adding helpful
> prefixes (section, figure, etc.), and there are other packages which one
> may want to use to generate 'clever' references (like cleveref with
> \cref).
>
> As such, I think that the hardcoded \ref should actually be turned into
> a customisable format string, which is what the attached patch does.
--
Timothy
^ permalink raw reply [relevance 93%]
* [PATCH] Allow LaTeX reference command (\ref) to be customised
@ 2021-06-06 18:19 61% Timothy
2021-06-09 2:11 93% ` Timothy
0 siblings, 1 reply; 200+ results
From: Timothy @ 2021-06-06 18:19 UTC (permalink / raw)
To: org-mode-email
[-- Attachment #1: Type: text/plain, Size: 523 bytes --]
Hi All,
I've started doing some more cross-referencing in documents exported to
LaTeX, and a hardcoded use of \ref has begun to stand out to me as a
rather annoying thing. Hypperef provides \autoref for adding helpful
prefixes (section, figure, etc.), and there are other packages which one
may want to use to generate 'clever' references (like cleveref with
\cref).
As such, I think that the hardcoded \ref should actually be turned into
a customisable format string, which is what the attached patch does.
--
Timothy
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-ox-latex-Allow-reference-command-to-be-customised.patch --]
[-- Type: text/x-patch, Size: 2863 bytes --]
From db01398de3a29043dbb545ee66006b0b7c0f1368 Mon Sep 17 00:00:00 2001
From: TEC <tec@tecosaur.com>
Date: Mon, 7 Jun 2021 02:13:18 +0800
Subject: [PATCH] ox-latex: Allow reference command to be customised
* lisp/ox-latex.el (org-latex-reference-command): Create a new variable
so the user may modify the reference command used.
(org-latex-link): Make use of the new `org-latex-reference-command' when
generating references for labels without a description (previously using
\ref).
(org-latex-prefer-user-labels): Mention the new
`org-latex-reference-command' when describing the generated LaTeX
referencing labels.
---
lisp/ox-latex.el | 19 +++++++++++++++++--
1 file changed, 17 insertions(+), 2 deletions(-)
diff --git a/lisp/ox-latex.el b/lisp/ox-latex.el
index c761cfd7f..940800750 100644
--- a/lisp/ox-latex.el
+++ b/lisp/ox-latex.el
@@ -381,6 +381,9 @@ (defcustom org-latex-prefer-user-labels nil
This is section \\ref{sec:foo}.
And this is still section \\ref{sec:foo}.
+A non-default value of `org-latex-reference-command' will change the
+command (\\ref by default) used to create label references.
+
Note, however, that setting this variable introduces a limitation
on the possible values for CUSTOM_ID and NAME. When this
variable is non-nil, Org passes their value to \\label unchanged.
@@ -400,6 +403,18 @@ (defcustom org-latex-prefer-user-labels nil
:version "26.1"
:package-version '(Org . "8.3"))
+(defcustom org-latex-reference-command "\\ref{%s}"
+ "Format string that takes a reference to produce a LaTeX reference command.
+
+The reference is a label such as sec:intro. A format string of \"\\ref{%s}\"
+produces numbered references and will always work. It may be desirable to make
+use of a package such as hyperref or cleveref and then change the format string
+to \"\\autoref{%s}\" or \"\\cref{%s}\" for example."
+ :group 'org-export-latex
+ :type 'string
+ :version "28.1"
+ :package-version '(Org . "9.5"))
+
;;;; Preamble
(defcustom org-latex-default-class "article"
@@ -2608,7 +2623,7 @@ (defun org-latex-link (link desc info)
(let ((label (org-latex--label destination info t)))
(if (and (not desc)
(org-export-numbered-headline-p destination info))
- (format "\\ref{%s}" label)
+ (format org-latex-reference-command label)
(format "\\hyperref[%s]{%s}" label
(or desc
(org-export-data
@@ -2616,7 +2631,7 @@ (defun org-latex-link (link desc info)
;; Fuzzy link points to a target. Do as above.
(otherwise
(let ((ref (org-latex--label destination info t)))
- (if (not desc) (format "\\ref{%s}" ref)
+ (if (not desc) (format org-latex-reference-command ref)
(format "\\hyperref[%s]{%s}" ref desc)))))))
;; Coderef: replace link with the reference name or the
;; equivalent line number.
--
2.31.1
^ permalink raw reply related [relevance 61%]
* [PATCH] html export: remove W3C warning, improve accessibility
@ 2021-06-06 18:02 53% Timothy
0 siblings, 0 replies; 200+ results
From: Timothy @ 2021-06-06 18:02 UTC (permalink / raw)
To: org-mode-email
[-- Attachment #1: Type: text/plain, Size: 711 bytes --]
Hi All,
Following on from my comments /ages/ ago, I have done some more work to
improve the HTML export. I intend to push it if I don't hear any
complaints. Please let me know if anything looks dodgy, or if anything
should also be improved with this patch :)
This patch:
- Resolves a W3C warning about type="text/css" in <style>
- Removes a docstring reference to IE8- (urgh!)
- Adds some ARIA roles to improve accessibility (let me know if you spot
anything else that could benefit from them being added).
Running the default html export through the W3C validator with my
massive Org-based config now results in nothing other than complaints
about dodgy unicode characters (not Org's fault) :)
--
Timothy
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-ox-html-Resolve-W3C-warning-improve-a11y.patch --]
[-- Type: text/x-patch, Size: 4085 bytes --]
From 722d61e5cc49153428c0858ab83ee1db5ee5c1c6 Mon Sep 17 00:00:00 2001
From: TEC <tec@tecosaur.com>
Date: Mon, 7 Jun 2021 01:51:45 +0800
Subject: [PATCH] ox-html: Resolve W3C warning, improve a11y
* lisp/ox-html.el (org-html-style-default, org-html-head): Remove
unwarranted type="text/css" from <style> (W3C warning).
(org-html-html5-fancy): Remove note about IE8- from docstring.
(org-html-footnote-section, org-html-template, org-html-toc,
org-html-footnote-reference): Add some ARIA roles to improve
accessibility.
---
lisp/ox-html.el | 24 +++++++++---------------
1 file changed, 9 insertions(+), 15 deletions(-)
diff --git a/lisp/ox-html.el b/lisp/ox-html.el
index 8f8470bb9..bd6771a76 100644
--- a/lisp/ox-html.el
+++ b/lisp/ox-html.el
@@ -260,7 +260,7 @@ (defcustom org-html-scripts
:type 'string)
(defcustom org-html-style-default
- "<style type=\"text/css\">
+ "<style>
#content { max-width: 60em; margin: auto; }
.title { text-align: center;
margin-bottom: .2em; }
@@ -1060,13 +1060,7 @@ (defcustom org-html-doctype "xhtml-strict"
(defcustom org-html-html5-fancy nil
"Non-nil means using new HTML5 elements.
-This variable is ignored for anything other than HTML5 export.
-
-For compatibility with Internet Explorer, it's probably a good
-idea to download some form of the html5shiv (for instance
-https://code.google.com/p/html5shiv/) and add it to your
-HTML_HEAD_EXTRA, so that your pages don't break for users of IE
-versions 8 and below."
+This variable is ignored for anything other than HTML5 export."
:group 'org-export-html
:version "24.4"
:package-version '(Org . "8.0")
@@ -1472,7 +1466,7 @@ (defcustom org-html-head ""
For example, a valid value would be:
- <style type=\"text/css\">
+ <style>
p { font-weight: normal; color: gray; }
h1 { color: black; }
.title { text-align: center; }
@@ -1818,12 +1812,12 @@ (defun org-html-footnote-section (info)
(anchor (org-html--anchor
(format "fn.%d" n)
n
- (format " class=\"footnum\" href=\"#fnr.%d\"" n)
+ (format " class=\"footnum\" href=\"#fnr.%d\" role=\"doc-backlink\"" n)
info))
(contents (org-trim (org-export-data def info))))
(format "<div class=\"footdef\">%s %s</div>\n"
(format (plist-get info :html-footnote-format) anchor)
- (format "<div class=\"footpara\">%s</div>"
+ (format "<div class=\"footpara\" role=\"doc-footnote\">%s</div>"
(if (not inline?) contents
(format "<p class=\"footpara\">%s</p>"
contents))))))))
@@ -2120,7 +2114,7 @@ (defun org-html-template (contents info)
(if subtitle
(format
(if html5-fancy
- "<p class=\"subtitle\">%s</p>\n"
+ "<p class=\"subtitle\" role=\"doc-subtitle\">%s</p>\n"
(concat "\n" (org-html-close-tag "br" nil info) "\n"
"<span class=\"subtitle\">%s</span>\n"))
(org-export-data subtitle info))
@@ -2321,14 +2315,14 @@ (defun org-html-toc (depth info &optional scope)
(org-export-get-relative-level headline info)))
(org-export-collect-headlines info depth scope))))
(when toc-entries
- (let ((toc (concat "<div id=\"text-table-of-contents\">"
+ (let ((toc (concat "<div id=\"text-table-of-contents\" role=\"doc-toc\">"
(org-html--toc-text toc-entries)
"</div>\n")))
(if scope toc
(let ((outer-tag (if (org-html--html5-fancy-p info)
"nav"
"div")))
- (concat (format "<%s id=\"table-of-contents\">\n" outer-tag)
+ (concat (format "<%s id=\"table-of-contents\" role=\"doc-toc\">\n" outer-tag)
(let ((top-level (plist-get info :html-toplevel-hlevel)))
(format "<h%d>%s</h%d>\n"
top-level
@@ -2601,7 +2595,7 @@ (defun org-html-footnote-reference (footnote-reference _contents info)
(format
(plist-get info :html-footnote-format)
(org-html--anchor
- id n (format " class=\"footref\" href=\"#fn.%d\"" n) info)))))
+ id n (format " class=\"footref\" href=\"#fn.%d\" role=\"doc-backlink\"" n) info)))))
;;;; Headline
--
2.31.1
^ permalink raw reply related [relevance 53%]
* [PATCH] Change default latex compiler to latexmk
@ 2021-06-06 16:55 68% Timothy
0 siblings, 1 reply; 200+ results
From: Timothy @ 2021-06-06 16:55 UTC (permalink / raw)
To: org-mode-email
[-- Attachment #1: Type: text/plain, Size: 402 bytes --]
Hey all,
From the earlier discussion on this, I got feeling a consensus had
reached that this is a good idea, as long as we check that latexmk is
available first.
As such, here is a patch changing the default LaTeX compiler to latexmk
--- as long as it's available. For what it's worth I've been using this
exact command in my personal config for months now, and it's worked
excellently.
--
Timothy
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-ox-latex-Change-default-compiler-to-latexmk.patch --]
[-- Type: text/x-patch, Size: 2093 bytes --]
From 95806243e40d5f9f19a8db71e2b8b0cd0c5fdb68 Mon Sep 17 00:00:00 2001
From: TEC <tec@tecosaur.com>
Date: Mon, 7 Jun 2021 00:46:09 +0800
Subject: [PATCH] ox-latex: Change default compiler to latexmk
* lisp/ox-latex.el (org-latex-pdf-process): Check for the presence of
latexmk when setting the default, and use it when available. Fall back
to the current default. This is important for the incoming citation
support, as PDF generation will now need to involve bibliography
generation. By using latexmk this is taken care of for us. The -%latex
part of the command is slightly hacky, but allows latexmk to behave more
intelligently for non-pdflatex options. Note that latexmk also seems to
care about the order of the arguments.
---
lisp/ox-latex.el | 10 ++++++----
1 file changed, 6 insertions(+), 4 deletions(-)
diff --git a/lisp/ox-latex.el b/lisp/ox-latex.el
index 9724b0d87..c761cfd7f 100644
--- a/lisp/ox-latex.el
+++ b/lisp/ox-latex.el
@@ -1165,9 +1165,11 @@ (defcustom org-latex-bib-compiler "bibtex"
:package-version '(Org . "9.0"))
(defcustom org-latex-pdf-process
- '("%latex -interaction nonstopmode -output-directory %o %f"
- "%latex -interaction nonstopmode -output-directory %o %f"
- "%latex -interaction nonstopmode -output-directory %o %f")
+ (if (executable-find "latexmk")
+ '("latexmk -f -pdf -%latex -interaction=nonstopmode -output-directory=%o %f")
+ '("%latex -interaction nonstopmode -output-directory %o %f"
+ "%latex -interaction nonstopmode -output-directory %o %f"
+ "%latex -interaction nonstopmode -output-directory %o %f"))
"Commands to process a LaTeX file to a PDF file.
This is a list of strings, each of them will be given to the
@@ -1211,7 +1213,7 @@ (defcustom org-latex-pdf-process
(const :tag "texi2dvi"
("cd %o; LATEX=\"%latex\" texi2dvi -p -b -V %b.tex"))
(const :tag "latexmk"
- ("latexmk -g -pdf -pdflatex=\"%latex\" -outdir=%o %f"))
+ ("latexmk -f -pdf -%latex -interaction=nonstopmode -output-directory=%o %f"))
(function)))
(defcustom org-latex-logfiles-extensions
--
2.31.1
^ permalink raw reply related [relevance 68%]
* Re: [PATCH] Fontification for inline src blocks
@ 2021-05-18 13:34 80% ` Timothy
0 siblings, 0 replies; 200+ results
From: Timothy @ 2021-05-18 13:34 UTC (permalink / raw)
To: sebastien.miquel; +Cc: org-mode-email
[-- Attachment #1: Type: text/plain, Size: 969 bytes --]
Hi Sébastien, thanks for your comments.
Sébastien Miquel <sebastien.miquel@posteo.eu> writes:
> Hi Timothy,
>
> Thanks for your work. I hope this can be merged.
:)
> Here are a few comments.
>
> Doesn't this line in ~org-toggle-inline-results-display~ throw the
> configured delimiters away when called twice ?
> : (setq org-inline-src-prettify-results (not org-inline-src-prettify-results))
>
> I think the =org-block= face should only be applied to the actual
> code, note the =src_lang= part, nor the result. For normal src blocks,
> it is only used inside the block.
In src blocks, you have the org-block-begin-line face applied. This (in
any sensible theme) has the same background as org-block. For the sake
of visual consistency, I think we want to have this applied to the
src_lang and result parts too. However, the org-block-begin-line face
overly fades the text, and so I've combined the org-block face with
other faces.
[-- Attachment #2: inline-src-back.png --]
[-- Type: image/png, Size: 9480 bytes --]
[-- Attachment #3: Type: text/plain, Size: 2642 bytes --]
> The ~org-src-font-lock-fontify-block~ function could be modified to
> take an optional =inline= argument. When =t=, it should not set the
> =multiline= font property. Although this is very minor, it would allow
> one to easily advice this function to behave differently in inline src
> blocks. For example, to not use the =org-block= face in this case.
I don't see where the multiline property is currently set, would you mind
pointing it out to me?
> I think the default parenthesis pair around results are bad. I much
> preferred your original brackets. Yes, as Tom said, they look alien,
> but alien is appropriate for use of ~prettify-symbols~.
I'm going to be using the original symbols in my configuration anyway
because I think they're nicer, but clearly this is contentious. I'd want
to hear from more people on this.
> Since ~prettify-symbols~ seems to be raising some usability concerns,
> perhaps ~org-inline-src-prettify-results~ should default to ~nil~.
> It'd be unlike org to hide things from the user in the default
> configuration.
This seems somewhat sensible to me, but I must say that {{{results()}}}
is /ugly/ and I suspect that many users would like the effect, but a
minority will be aware of this option. Perhaps this is worth doing
anyway.
> As Tom points out, the two faces used (for the =src_= and bracket and
> the language part) should be customizable. The default value you chose
> are fine IMO. Perhaps the language one could also be used to highlight
> the language of normal src blocks, though It might be easier to use a
> single face.
So are you suggesting I do or don't create new faces for this?
> Timothy writes:
>>> P.S. Nitpick: You do not need to run fontification in while loops. Just
>>> fontifying next match before limit should be enough. Font-lock will call
>>> the function again if needed.
>> I'm guessing for this to work I'd need to return the final char
>> fortified? Or is the moving of point enough?
>>
>> Maybe related - I've noticed this doesn't seem to work with multiple
>> src_ blocks per line, might you have any insight here?
>
> You need only return =t= if some fontification has been done (and set
> point after the fontified part). If your function returns =t=, it will
> be called again.
>
> A case can be made for keeping the loop though. It works fine and is
> clearer since the aforementioned fontlock behaviour is poorly
> documented. Really, the only downside is the loss of consistency, since
> the function ~org-fontify-meta-lines-and-blocks-1~ doesn't loop.
Returning t works nicely, and now we can highlight more than one inline
src per line :)
--
Timothy
^ permalink raw reply [relevance 80%]
* Re: [PATCH] Fontification for inline src blocks
@ 2021-05-12 16:39 82% ` Timothy
0 siblings, 1 reply; 200+ results
From: Timothy @ 2021-05-12 16:39 UTC (permalink / raw)
To: Ihor Radchenko; +Cc: Tom Gillespie, org-mode-email
Thank you for the detailed feedback :)
Ihor Radchenko <yantar92@gmail.com> writes:
> Timothy <tecosaur@gmail.com> writes:
>
>>> I do not like abusing prettify-symbols-mode. What if it is not enabled?
If you know of another way of accomplishing text-replacement which
changes back when the cursor enters the region, please let me know.
>> Ah, it does it anyway at the moment.
>
> Hmm. You are right. You are calling compose-region directly. Note, that
> you do not add 'decompose-region function for automatic region
> destruction (see help:pretty-symbol-pattern-to-keyword).
Isn't the same effect achieved by the remove-list-of-text-properties call?
> If I understand correctly (I did not really install your patch), if you have
> composed region, disable font-lock, and try to edit the region, edits
> will be invisible. Or imagine setting org-inline-src-prettify-results to
> nil in already fontified buffer.
I just tried "setting org-inline-src-prettify-results to nil in already
fontified buffer." and the region just decomposed and stayed that way.
> Also, you may find help:font-lock-extra-managed-props useful. That way,
> you will not have to manually remove composition and other non-standard
> properties during fontification
Hmmm, from a look I can't tell exactly how these are "managed". Are they
just removed when a region is processed?
> why are you even removing 'face? It should be already done by font-lock).
I tried removing such calls, and everything still worked, so this is no
longer done.
>>> What will happen if user toggles prettify-symbols-mode in Org buffer?
>>
>> This seems to be toggled nicely by prettify-symbols-mode too.
>
> I would not expect it to. Why would prettify-symbols-mode interfere with
> Org mode native fontification if it is not strictly necessary?
Well, I guess this is a by-product of using prettify-symbols-start/end,
see my note at the start of this email about not being aware of anything else.
> P.S. Nitpick: You do not need to run fontification in while loops. Just
> fontifying next match before limit should be enough. Font-lock will call
> the function again if needed.
I'm guessing for this to work I'd need to return the final char
fortified? Or is the moving of point enough?
Maybe related - I've noticed this doesn't seem to work with multiple
src_ blocks per line, might you have any insight here?
Thanks,
Timothy
^ permalink raw reply [relevance 82%]
* Re: [PATCH] Fontification for inline src blocks
@ 2021-05-12 14:47 93% ` Timothy
0 siblings, 1 reply; 200+ results
From: Timothy @ 2021-05-12 14:47 UTC (permalink / raw)
To: Ihor Radchenko; +Cc: Tom Gillespie, org-mode-email
Thanks for your response.
Ihor Radchenko <yantar92@gmail.com> writes:
> I do not like abusing prettify-symbols-mode. What if it is not enabled?
Ah, it does it anyway at the moment.
> What will happen if user toggles prettify-symbols-mode in Org buffer?
This seems to be toggled nicely by prettify-symbols-mode too.
> Maybe better use something like org-entities?
I'm not sure if that would work, perhaps someone else knows otherwise.
--
Timothy
^ permalink raw reply [relevance 93%]
* Re: [PATCH] Fontification for inline src blocks
2021-05-03 3:29 43% ` Timothy
@ 2021-05-12 11:15 93% ` Timothy
0 siblings, 1 reply; 200+ results
From: Timothy @ 2021-05-12 11:15 UTC (permalink / raw)
To: Tom Gillespie; +Cc: org-mode-email
If anyone else is interested in this, it would be great to get your
thoughts.
I'd also appreciate it if a core maintainer might be able to find the
time to review the patch and let me know if it looks good.
Thanks,
Timothy.
--
> Tom Gillespie <tgbugs@gmail.com> writes:
>
>> 1. I think there needs to be a function to toggle
>> org-inline-src-prettify-results as there is e.g. for hyperlinks. I was
>> quite confused by the prettified results.
>
> Added org-toggle-inline-results-display.
>
>> 3. I'm not sure about the default choice for prettified delimiters. I
>> see there is already a way to customize the delimiters by providing a
>> cons. I think a default value of '("" . "") might be a better choice
>> since ⟨ and ⟩ being hardcoded seems like it introduces completely
>> alien characters. Going with empty strings also seems consistent with
>> the behavior for hyperlinks.
>
> Changed to your suggestion.
>
> Awaiting others' thoughts on 2. and 5.
^ permalink raw reply [relevance 93%]
* Re: [PATCH] Wrap LaTeX snippets in $$ with markdown export
@ 2021-05-09 20:12 93% ` Timothy
0 siblings, 0 replies; 200+ results
From: Timothy @ 2021-05-09 20:12 UTC (permalink / raw)
To: Nicolas Goaziou; +Cc: org-mode-email
Hi,
Nicolas Goaziou <mail@nicolasgoaziou.fr> writes:
>> I just thought there may be people who like me are interested in
>> <img>s for LaTeX in HTML, but not in Markdown.
>
> Fair enough. Let's push your last patch, then.
Going off this, I've taken this as assent and just pushed my patch in
its current form as 981f25031.
--
Timothy
^ permalink raw reply [relevance 93%]
* Re: [PATCH] Wrap LaTeX snippets in $$ with markdown export
@ 2021-05-04 13:31 88% ` Timothy
0 siblings, 1 reply; 200+ results
From: Timothy @ 2021-05-04 13:31 UTC (permalink / raw)
To: Nicolas Goaziou; +Cc: org-mode-email
Hello,
Nicolas Goaziou <mail@nicolasgoaziou.fr> writes:
>> Should one want to convert LaTeX images say to an SVG for HTML export, I
>> do not think one would want this behaviour to also apply to LaTeX being
>> exported to markdown.
>
> Why do you think so? This is consistent with everything else not
> supported by vanilla Markdown.
To speak personally, at the moment I use mathjax for HTML. I'm quite
content with the markdown output from this patch without what's
discussed below.
However, if/when I can get the SVG baseline to work with dvisvgm I plan
on switching to that for HTML files. However, I'd consider this
behaviour undesirable for markdown.
The main reason why I'm hesitant about including <img>s in Markdown, is
because unlike <table> etc. the output now relies on external files.
>> As such I see two 'sensible' paths forward: (1) just include LaTeX
>> verbatim when :with-latex is non-nil, or (2) introduce
>> `org-markdown-with-latex' which can be set to t/'verbatim or 'html.
>>
> Obeying to :with-latex property means "ox-md" is somehow actively
> handling LaTeX fragments, which was not the initial intent, IIUC. The
> first idea was to provide a sensible default for such objects, because
> we're outside the specification anyway. I'd rather not overdo it.
I'm happy to strip this out of the patch (there's always advice for my
own config...), I just thought there may be people who like me are
interested in <img>s for LaTeX in HTML, but not in Markdown.
--
Timothy
^ permalink raw reply [relevance 88%]
* Re: [PATCH] Wrap LaTeX snippets in $$ with markdown export
@ 2021-05-04 3:35 57% ` Timothy
0 siblings, 1 reply; 200+ results
From: Timothy @ 2021-05-04 3:35 UTC (permalink / raw)
To: Nicolas Goaziou; +Cc: org-mode-email
[-- Attachment #1: Type: text/plain, Size: 951 bytes --]
Hi Nicolas,
So, I've now fixed the handling of already-$-delaminated fragments, and
removed the $$ from around environments.
Sorry to complicate things, but, looking at what the HTML fallback
actually is, I've had some further thoughts. The HTML backend will
either leave the content as-is, run `org-latex-to-html-convert-command',
or run something from `org-preview-latex-process-alist' and include an
<img>.
Should one want to convert LaTeX images say to an SVG for HTML export, I
do not think one would want this behaviour to also apply to LaTeX being
exported to markdown.
As such I see two 'sensible' paths forward: (1) just include LaTeX
verbatim when :with-latex is non-nil, or (2) introduce
`org-markdown-with-latex' which can be set to t/'verbatim or 'html.
In the attached patch, I've taken the first approach. Let me know if
you'd like to take the second approach, or just inherit the HTML
behaviour for LaTeX after all.
--
Timothy
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-ox-md-Use-TeX-style-math-wrapping.patch --]
[-- Type: text/x-patch, Size: 3018 bytes --]
From a02dbcb21dddb6d9239d13308a78a45738d9b7e6 Mon Sep 17 00:00:00 2001
From: Timothy <tecosaur@gmail.com>
Date: Thu, 1 Apr 2021 00:41:29 +0800
Subject: [PATCH] ox-md: Use TeX-style $ math wrapping
* lisp/ox-md.el (org-md-latex-environment, org-md-latex-fragment):
These two new filters wrap LaTeX maths in $ / $$ TeX-style notation.
While ox-md endeavours to adhere to the original Markdown specification,
and not any particular variant, the original specification does not deal
with LaTeX fragments at all, and so this change does not reduce how
faithfully the original specification is followed.
There is a major upside to this though. Of the many Markdown variants
that have emerged, those that support LaTeX very often exclusively
support TeX style notation. This change thus improves the utility of
the Markdown export for many use cases, and deviates no more from the
original specification that the current method.
---
lisp/ox-md.el | 31 +++++++++++++++++++++++++++++++
1 file changed, 31 insertions(+)
diff --git a/lisp/ox-md.el b/lisp/ox-md.el
index b6b2c1728..1ae0cf2d9 100644
--- a/lisp/ox-md.el
+++ b/lisp/ox-md.el
@@ -100,6 +100,8 @@ (org-export-define-derived-backend 'md 'html
(italic . org-md-italic)
(item . org-md-item)
(keyword . org-md-keyword)
+ (latex-environment . org-md-latex-environment)
+ (latex-fragment . org-md-latex-fragment)
(line-break . org-md-line-break)
(link . org-md-link)
(node-property . org-md-node-property)
@@ -460,6 +462,35 @@ (defun org-md-keyword (keyword contents info)
(_ (org-export-with-backend 'html keyword contents info))))
+;;;; Latex Environment
+
+(defun org-md-latex-environment (latex-environment contents info)
+ "Transcode a LATEX-ENVIRONMENT object from Org to Markdown.
+CONTENTS is nil. INFO is a plist holding contextual information."
+ (when (plist-get info :with-latex)
+ (let ((latex-frag (org-remove-indentation
+ (org-element-property :value latex-environment)))
+ (label (org-html--reference latex-environment info t)))
+ (if (org-string-nw-p label)
+ (replace-regexp-in-string "\\`.*"
+ (format "\\&\n\\\\label{%s}" label)
+ latex-frag)
+ latex-frag))))
+
+;;;; Latex Fragment
+
+(defun org-md-latex-fragment (latex-fragment contents info)
+ "Transcode a LATEX-FRAGMENT object from Org to Markdown.
+CONTENTS is nil. INFO is a plist holding contextual information."
+ (when (plist-get info :with-latex)
+ (let ((frag (org-element-property :value latex-fragment)))
+ (cond
+ ((string-match-p "^\\\\(" frag)
+ (concat "$" (substring frag 2 -2) "$"))
+ ((string-match-p "^\\\\\\[" frag)
+ (concat "$$" (substring frag 2 -2) "$$"))
+ (t frag))))) ; either already $-deliminated or a macro
+
;;;; Line Break
(defun org-md-line-break (_line-break _contents _info)
--
2.31.1
^ permalink raw reply related [relevance 57%]
* Re: [PATCH] Wrap LaTeX snippets in $$ with markdown export
@ 2021-05-03 18:03 88% ` Timothy
0 siblings, 1 reply; 200+ results
From: Timothy @ 2021-05-03 18:03 UTC (permalink / raw)
To: Nicolas Goaziou; +Cc: org-mode-email
Nicolas Goaziou <mail@nicolasgoaziou.fr> writes:
> This sounds reasonable.
I'm glad to hear that!
>> +(defun org-md-latex-environment [...]
> Nitpick: I would use `format', also the final newline character is
> useless, since it will be removed later during the export process.
Actually, since writing this patch I'm not sure that $$-surrounding
\begin{}...\end{} environments is also a good idea. I'm inclined to
leave this out of the patch.
>> +;;;; Latex Fragment
>> +
>> +(defun org-md-latex-fragment (latex-fragment contents info)
>> + "Transcode a LATEX-FRAGMENT object from Org to Markdown.
>> +CONTENTS is nil. INFO is a plist holding contextual information."
>> + (when (plist-get info :with-latex)
>> + (let ((frag (org-html-latex-fragment contents info)))
>> + (cond
>> + ((string-match-p "^\\\\(" frag)
>> + (concat "$" (substring frag 2 -2) "$"))
>> + ((string-match-p "^\\\\\\[" frag)
>> + (concat "$$" (substring frag 2 -2) "$$"))
>> + (t (message "unrecognised fragment: %s" frag)
>> + frag)))))
>
> Nitpick: I suggest to use `rx' macro. It really makes the code base
> a better place.
I do rather like the `rx' macro, however I'm not sure that
(rx bol "\\(") is really an improvement over "^\\\\(" in this particular
case.
> You are missing some cases. The fragment could be $...$ or $$...$$
> already, so you can return it as-is without sending the message.
Ah yep, after getting your thoughts on this message I'll send a revised
patch with fixes this (along with any other changes).
> Otherwise, it is a macro. We can assume it lives outside math mode. So
> maybe the "Unrecognized fragment: %S" is in order in that situation. We
> could also let HTML export back-end deal with it. I don't know what is
> better.
I'm not sure what to do here either. Perhaps nothing/HTML backend?
Finally, I think if this case (lone macro) is handled, there aren't any
possible "Unrecognized fragment"s that could be passed, and so that
condition would no longer be necessary?
--
Timothy.
^ permalink raw reply [relevance 88%]
* Re: [PATCH] Fontification for inline src blocks
2021-05-02 21:03 87% ` Timothy
@ 2021-05-03 3:29 43% ` Timothy
2021-05-12 11:15 93% ` Timothy
1 sibling, 1 reply; 200+ results
From: Timothy @ 2021-05-03 3:29 UTC (permalink / raw)
To: Tom Gillespie; +Cc: org-mode-email
[-- Attachment #1: Type: text/plain, Size: 750 bytes --]
Tom Gillespie <tgbugs@gmail.com> writes:
> 1. I think there needs to be a function to toggle
> org-inline-src-prettify-results as there is e.g. for hyperlinks. I was
> quite confused by the prettified results.
Added org-toggle-inline-results-display.
> 3. I'm not sure about the default choice for prettified delimiters. I
> see there is already a way to customize the delimiters by providing a
> cons. I think a default value of '("" . "") might be a better choice
> since ⟨ and ⟩ being hardcoded seems like it introduces completely
> alien characters. Going with empty strings also seems consistent with
> the behavior for hyperlinks.
Changed to your suggestion.
Awaiting others' thoughts on 2. and 5.
--
Timothy
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-org-src-Implement-native-inline-src-fontification.patch --]
[-- Type: text/x-patch, Size: 7451 bytes --]
From 81c56a48ebe516890691420243efe966f3c50eef Mon Sep 17 00:00:00 2001
From: TEC <tec@tecosaur.com>
Date: Mon, 3 May 2021 11:16:17 +0800
Subject: [PATCH] org-src: Implement native inline src fontification
* lisp/org-src.el (org-fontify-inline-src-blocks,
org-fontify-inline-src-blocks-1): Create a function to search the buffer
up to a limit for inline src blocks. Light fontification is applied to
matched inline src blocks. When `org-src-fontify-natively' is
set, `org-src-font-lock-fontify-block' to the content.
(org-fontify-inline-src-results): Search for {{{results(...)}}}
constructs. Then when `org-inline-src-prettify-results` is non-nil,
mimic prettify-symbols and use `compose-region' to substitute visually
simpler elements for the wrapping around the value.
* lisp/org.el (org-set-font-lock-defaults): Add
`org-fontify-inline-src-blocks' to `org-font-lock-extra-keywords', which
is locally bound inside `org-set-font-lock-defaults'.
(org-inline-src-fontify-max-length, org-inline-src-prettify-results):
Create variables for use in the new inline src/result fontification
methods in org-src.el.
---
lisp/org-src.el | 79 +++++++++++++++++++++++++++++++++++++++++++++++++
lisp/org.el | 21 ++++++++++++-
2 files changed, 99 insertions(+), 1 deletion(-)
diff --git a/lisp/org-src.el b/lisp/org-src.el
index a694e5595..1d09f03a8 100644
--- a/lisp/org-src.el
+++ b/lisp/org-src.el
@@ -623,6 +623,85 @@ (defun org-src-font-lock-fontify-block (lang start end)
'(font-lock-fontified t fontified t font-lock-multiline t))
(set-buffer-modified-p modified)))))
+(defun org-fontify-inline-src-blocks (limit)
+ "Try to apply `org-fontify-inline-src-blocks-1'."
+ (condition-case nil
+ (org-fontify-inline-src-blocks-1 limit)
+ (error (message "Org mode fontification error in %S at %d"
+ (current-buffer)
+ (line-number-at-pos)))))
+
+(defun org-fontify-inline-src-blocks-1 (limit)
+ "Fontify inline src_LANG blocks, from `point' up to LIMIT."
+ (let ((case-fold-search t)
+ (initial-point (point)))
+ (while (re-search-forward "\\_<src_\\([^ \t\n[{]+\\)[{[]?" limit t) ; copied from `org-element-inline-src-block-parser'
+ (let ((beg (match-beginning 0))
+ (lang-beg (match-beginning 1))
+ (lang-end (match-end 1))
+ pt)
+ (remove-text-properties beg lang-end '(face nil))
+ (font-lock-append-text-property lang-beg lang-end 'face 'org-meta-line)
+ (font-lock-append-text-property beg lang-beg 'face 'shadow)
+ (font-lock-append-text-property beg lang-end 'face 'org-block)
+ (setq pt (goto-char lang-end))
+ ;; `org-element--parse-paired-brackets' doesn't take a limit, so to
+ ;; prevent it searching the entire rest of the buffer we temporarily
+ ;; narrow the active region.
+ (save-restriction
+ (narrow-to-region beg (min (point-max)
+ limit
+ (+ lang-end org-inline-src-fontify-max-length)))
+ (when (ignore-errors (org-element--parse-paired-brackets ?\[))
+ (remove-text-properties pt (point) '(face nil))
+ (font-lock-append-text-property pt (point) 'face 'org-block)
+ (setq pt (point)))
+ (when (ignore-errors (org-element--parse-paired-brackets ?\{))
+ (remove-text-properties pt (point) '(face nil))
+ (font-lock-append-text-property pt (1+ pt) 'face '(org-block shadow))
+ (unless (= (1+ pt) (1- (point)))
+ (if org-src-fontify-natively
+ (org-src-font-lock-fontify-block
+ (buffer-substring-no-properties lang-beg lang-end)
+ (1+ pt) (1- (point)))
+ (font-lock-append-text-property (1+ pt) (1- (point)) 'face 'org-block)))
+ (font-lock-append-text-property (1- (point)) (point)'face '(org-block shadow))
+ (setq pt (point))))
+ (when (and org-inline-src-prettify-results
+ (re-search-forward "\\= {{{results(" limit t))
+ (font-lock-append-text-property pt (1+ pt) 'face 'org-block)
+ (goto-char pt))))
+ (when org-inline-src-prettify-results
+ (goto-char initial-point)
+ (org-fontify-inline-src-results limit))))
+
+(defun org-fontify-inline-src-results (limit)
+ "Apply prettify-symbols modifications to inline results blocks.
+Performed according to `org-inline-src-prettify-results'."
+ (while (re-search-forward "{{{results(\\(.+?\\))}}}" limit t)
+ (remove-list-of-text-properties (match-beginning 0) (point)
+ '(composition
+ prettify-symbols-start
+ prettify-symbols-end))
+ (font-lock-append-text-property (match-beginning 0) (match-end 0)
+ 'face 'org-block)
+ (let ((start (match-beginning 0)) (end (match-beginning 1)))
+ (with-silent-modifications
+ (compose-region start end (if (eq org-inline-src-prettify-results t)
+ "(" (car org-inline-src-prettify-results)))
+ (add-text-properties start end `(prettify-symbols-start ,start prettify-symbols-end ,end))))
+ (let ((start (match-end 1)) (end (point)))
+ (with-silent-modifications
+ (compose-region start end (if (eq org-inline-src-prettify-results t)
+ ")" (cdr org-inline-src-prettify-results)))
+ (add-text-properties start end `(prettify-symbols-start ,start prettify-symbols-end ,end))))))
+
+(defun org-toggle-inline-results-display ()
+ "Toggle the literal or contracted display of inline src blocks results."
+ (interactive)
+ (setq org-inline-src-prettify-results (not org-inline-src-prettify-results))
+ (org-restart-font-lock))
+
\f
;;; Escape contents
diff --git a/lisp/org.el b/lisp/org.el
index 10eeae514..ab817a0a7 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -5239,6 +5239,23 @@ (defcustom org-allow-promoting-top-level-subtree nil
:version "24.1"
:group 'org-appearance)
+(defcustom org-inline-src-fontify-max-length 200
+ "Maximum content length of an inline src block that will be fontified.
+This is only relevant when `org-src-fontify-natively' is t."
+ :type 'integer
+ :package-version '(Org . "9.5")
+ :group 'org-appearance
+ :group 'org-babel)
+
+(defcustom org-inline-src-prettify-results t
+ "Whether to use (ab)use prettify-symbols-mode on {{{results(...)}}}.
+Either t or a cons cell of strings which are used as substitutions
+for the start and end of inline results, respectively."
+ :type '(choice boolean (cons string string))
+ :package-version '(Org . "9.5")
+ :group 'org-appearance
+ :group 'org-babel)
+
(defun org-fontify-meta-lines-and-blocks (limit)
(condition-case nil
(org-fontify-meta-lines-and-blocks-1 limit)
@@ -5739,7 +5756,9 @@ (defun org-set-font-lock-defaults ()
org-comment-string)
'(9 'org-special-keyword t))
;; Blocks and meta lines
- '(org-fontify-meta-lines-and-blocks))))
+ '(org-fontify-meta-lines-and-blocks)
+ ;; Inline src blocks
+ '(org-fontify-inline-src-blocks))))
(setq org-font-lock-extra-keywords (delq nil org-font-lock-extra-keywords))
(run-hooks 'org-font-lock-set-keywords-hook)
;; Now set the full font-lock-keywords
--
2.31.1
^ permalink raw reply related [relevance 43%]
* Re: [PATCH] Fontification for inline src blocks
@ 2021-05-02 21:03 87% ` Timothy
2021-05-03 3:29 43% ` Timothy
1 sibling, 0 replies; 200+ results
From: Timothy @ 2021-05-02 21:03 UTC (permalink / raw)
To: Tom Gillespie; +Cc: org-mode-email
Thanks for trying this!
Tom Gillespie <tgbugs@gmail.com> writes:
> Hi Timothy,
> It seems to work more or less as expected. A few comments below. Best,
> Tom
>
> 1. I think there needs to be a function to toggle
> org-inline-src-prettify-results as there is e.g. for hyperlinks. I was
> quite confused by the prettified results.
I see. I imagine the expected behaviour of such a function would be to
toggle org-inline-src-prettify-results and redisplay?
> 2. I'm also not sure that this approach to prettify is a good idea.
> There are issues with unexpected killing/yanking and basic navigation
> behavior of the prettified text which seem worse than the already
> troublesome issues with hyperlinks. I'm not sure we can do anything
> about this though?
If there is something that can be done, I'd love to hear about it. I'm
no aware of anything though.
> 3. I'm not sure about the default choice for prettified delimiters. I
> see there is already a way to customize the delimiters by providing a
> cons. I think a default value of '("" . "") might be a better choice
> since ⟨ and ⟩ being hardcoded seems like it introduces completely
> alien characters. Going with empty strings also seems consistent with
> the behavior for hyperlinks.
Hmmm, yes. Perhaps something else would make for a better default.
I'm open to suggestions on this, I just didn't personally like any of
the ASCII chars I tried when writing this.
> 4. There is an interaction with rainbow delimiters that there isn't an
> easy solution for. I wish there was a syntax type that was "this is a
> paren for electric pair mode but not for font locking."
This sounds like something worth being aware of, that nothing can really
(currently) be done about.
> 5. I'm not sure that the faces selected for src_ and lang are the
> right ones. Is there any issue with adding new faces specifically for
> those rather than reusing existing faces? I thought that matching the
> font locking of #+begin_src lines might make sense, but then I
> realized that that doesn't make sense because that is for blocks more
> generally.
I don't know if adding faces is a big deal or not, so I tried to pick
"sensible choices" from the current set. Further input on this would be
appreciated (particularly more people's thoughts).
--
Timothy
^ permalink raw reply [relevance 87%]
* Re: [PATCH] Wrap LaTeX snippets in $$ with markdown export
@ 2021-05-02 20:23 93% ` Timothy
2 siblings, 0 replies; 200+ results
From: Timothy @ 2021-05-02 20:23 UTC (permalink / raw)
To: Nicolas Goaziou, org-mode-email
Hello Nicolas,
In my plea for patch feedback email, Bastien said he'd like to leave
this patch to your discretion.
As such, it would be fantastic if you might be able to provide your
thoughts on this.
All the best,
Timothy.
^ permalink raw reply [relevance 93%]
* Re: [PATCH] Wrap LaTeX snippets in $$ with markdown export
@ 2021-05-02 20:20 93% ` Timothy
0 siblings, 0 replies; 200+ results
From: Timothy @ 2021-05-02 20:20 UTC (permalink / raw)
To: Berry, Charles; +Cc: org-mode-email
> Will this handle LaTeX macros[1] gracefully and other things intended as raw LaTeX?
> [1] https://pandoc.org/MANUAL.html#latex-macros
This only affects LaTeX fragments, and then it's just changing \(\) /
\[\] for $ / $$. I don't think this has any effect on your concerns.
--
Timothy
^ permalink raw reply [relevance 93%]
* Re: [PATCH] Fontification for inline src blocks
2021-04-28 7:14 88% ` Timothy
@ 2021-05-02 20:17 93% ` Timothy
0 siblings, 1 reply; 200+ results
From: Timothy @ 2021-05-02 20:17 UTC (permalink / raw)
To: org-mode-email
It would be good to hear if anyone has been able to test this, and if so
what your experience has been :)
--
Timothy
^ permalink raw reply [relevance 93%]
* Re: [PATCH] A proposal to add LaTeX attributes to verse blocks
[not found] ` <87tunlxws3.fsf@ucl.ac.uk>
@ 2021-05-02 11:31 92% ` Timothy
0 siblings, 0 replies; 200+ results
From: Timothy @ 2021-05-02 11:31 UTC (permalink / raw)
To: Eric S Fraga; +Cc: Bastien, Juan Manuel Macías, emacs-orgmode
Eric S Fraga <e.fraga@ucl.ac.uk> writes:
> Is the verse package loaded automatically already? I did not see any
> change in the patch to that aspect and when I export a simple test, the
> package is not loaded.
Wouldn't it be nice if there was something in-between loading the
kitchen sink and manually adding packages*... [ foreshadowing ;) ]
--
Timothy
* My prototype is now rather stable and I like the interface, I'm just
wondering if I should generalise it for arbitrary backends or keep it
as LaTeX-only, but don't let me take this thread on a tangent over
this. I just thought it was worth mentioning.
^ permalink raw reply [relevance 92%]
* Re: [PATCH] LaTeX export: arbitrary float environments
@ 2021-05-01 17:31 88% ` Timothy
0 siblings, 0 replies; 200+ results
From: Timothy @ 2021-05-01 17:31 UTC (permalink / raw)
To: Thomas S. Dye; +Cc: emacs-orgmode
Thomas S. Dye <tsd@tsdye.online> writes:
> Aloha Timothy,
:waves:
> Sorry for the clumsy patch, which I guess would also benefit from an addition to
> the manual, as well?
No problem, we all start somewhere :) (and I know I'm still making mistakes)
An update to the manual to describe the changed behaviour would be good.
If you'd like you could wait till a core maintainer says this looks good
before going to that effort, or you could add it in now so it's all in a
single patch --- as long as something happens.
> Larger question: do we really want to tinker with ob-latex in this way? Or,
> should changes like this patch follow a path indicated by Tim Cross and into
> their own package, say ob-latex-ex, which might someday replace ob-latex if it
> proved useful and stable?
I don't think LaTeX support is likely to leave Org any time soon, so at
least until a core maintainer tells you otherwise I'd be inclined to
proceed with your current patch.
If this was a huge/transformational change I may be more uncertain, but
this looks fairly simple to me at least.
--
Timothy
> All the best,
> Tom
>
> Timothy <tecosaur@gmail.com> writes:
>
>> Hi Thomas,
>>
>> On the surface, this looks reasonable to me :)
>>
>> Just commenting on some technicalities with the patch itself:
>> - In ORG-NEWS it would be good to wrap the content over multiple lines
>> instead of having a single 270 char line :)
>> - You seem to have an anomalous change to the ob-python :return entry
>> - I don't think your patch subject follows the convention for Org, it
>> should be:
>> "main file/feature: overall change summary"
>> so, something like
>> "ox-latex: allow for arbitrary float environments"
>> rather than
>> "LaTeX export: arbitrary float environments"
>>
>> Thanks for the patch :)
>>
>> Timothy
^ permalink raw reply [relevance 88%]
* Re: [PATCH] avoid loading major modes when exporting to file
@ 2021-05-01 17:26 84% ` Timothy
0 siblings, 0 replies; 200+ results
From: Timothy @ 2021-05-01 17:26 UTC (permalink / raw)
To: Bastien; +Cc: org-mode-email
Bastien <bzg@gnu.org> writes:
> This even be "auto-mode-alist" instead of "(auto-mode-alist nil)".
Ah, it can indeed.
> I'm still unsure the patch is correct: what if people *need* major
> mode initialization before any contents is exported to a file?
I haven't responded to this concern, because I haven't been able to
conceive of a single situation where loading the normal-mode for the
exported file could be desirable.
>> I think the commit description is pretty thorough, so give that a look.
>> TLDR; it makes `org-export-to-file' behave a bit more nicely.
>
> I find it useful to have a small description of the change and why it
> is needed in the body of the email, when a patch is attached.
I think I may have been become overly used to how convenient mu4e is for
showing patches inline 😅.
For the sake of anyone just looking at the Email body, here's what I
considered to be an informative commit message, subtly reworded:
Currently, when `org-export-to-file' is called it activated the major
mode for that file type based on `auto-mode-alist'. This can be mildly
annoying in various ways as loading the major mode:
1. makes the export take longer
2. can produce unwanted "noise" while initialising, namely warnings and
errors related to the mode itself
3. can produce spurious files like an .auctex-auto folder
By locally binding `auctex-auto' to nil all of these undesirable
behaviours can be avoided.
--
Timothy
^ permalink raw reply [relevance 84%]
* Re: [PATCH] Babel: remove LaTeX environment -type #+results
@ 2021-05-01 11:44 93% ` Timothy
0 siblings, 0 replies; 200+ results
From: Timothy @ 2021-05-01 11:44 UTC (permalink / raw)
To: Bastien; +Cc: org-mode-email
Bastien <bzg@gnu.org> writes:
> Applied in master as commit b90b850ae.
>
> Can you add a etc/ORG-NEWS entry for this?
Great! News entry added.
--
Timothy
^ permalink raw reply [relevance 93%]
* Re: [PATCH] LaTeX export: arbitrary float environments
@ 2021-05-01 11:08 91% ` Timothy
0 siblings, 1 reply; 200+ results
From: Timothy @ 2021-05-01 11:08 UTC (permalink / raw)
To: Thomas S. Dye; +Cc: emacs-orgmode
Hi Thomas,
On the surface, this looks reasonable to me :)
Just commenting on some technicalities with the patch itself:
- In ORG-NEWS it would be good to wrap the content over multiple lines
instead of having a single 270 char line :)
- You seem to have an anomalous change to the ob-python :return entry
- I don't think your patch subject follows the convention for Org, it
should be:
"main file/feature: overall change summary"
so, something like
"ox-latex: allow for arbitrary float environments"
rather than
"LaTeX export: arbitrary float environments"
Thanks for the patch :)
Timothy
^ permalink raw reply [relevance 91%]
* Re: [PATCH] A proposal to add LaTeX attributes to verse blocks
@ 2021-05-01 10:58 93% ` Timothy
1 sibling, 0 replies; 200+ results
From: Timothy @ 2021-05-01 10:58 UTC (permalink / raw)
To: Juan Manuel Macías; +Cc: orgmode
Hi Juan,
Sorry it's still taking a while for your patch to be looked at.
Assuming it does get merged, it would be good to check if you'd be
willing to write a manual entry to accompany this (in a separate patch
works).
Thanks again for the patch,
Timothy.
Juan Manuel Macías <maciaschain@posteo.net> writes:
^ permalink raw reply [relevance 93%]
* Re: [PATCH] org-src.el Do not ask to revert unmodified buffers
@ 2021-05-01 10:55 93% ` Timothy
0 siblings, 0 replies; 200+ results
From: Timothy @ 2021-05-01 10:55 UTC (permalink / raw)
To: pillule; +Cc: Kyle Meyer, emacs-orgmode
Hi pillule, should we consider this patch cancelled?
pillule <pillule@riseup.net> writes:
> You are right I clearly missed org-src-ask-before-returning-to-edit-buffer
> Don't know how . . .
>
> Sorry for the noise.
^ permalink raw reply [relevance 93%]
* Re: [PATCH] Have C-c C-c recognise #+plot lines
@ 2021-04-30 12:16 91% ` Timothy
0 siblings, 0 replies; 200+ results
From: Timothy @ 2021-04-30 12:16 UTC (permalink / raw)
To: Eric S Fraga; +Cc: Bastien, emacs-orgmode@gnu.org
Eric S Fraga <e.fraga@ucl.ac.uk> writes:
> I have updated org. Problem persists.
>
> Attached is a full backtrace after hitting C-u C-c C-c on a table. The
> document itself has 2 headings and a small table.
>
> I unfortunately cannot spend more time on this at the moment as I have a
> presentation to make this afternoon and it's not quite ready...
Thank you for taking the time to check this in what sounds like a busy
day, and the backtrace. It's much appreciated :)
It seems like for you (org-element-property :post-affiliated context)
was unexpectedly nil. (or 0 ...) would be a quick-fix, but I find it odd
that this is a issue, and am yet to be able to reproduce this myself.
Is anybody else willing to try this and weigh in?
--
Timothy
p.s. Good luck with the presentation!
^ permalink raw reply [relevance 91%]
* Re: [PATCH] Have C-c C-c recognise #+plot lines
@ 2021-04-30 8:52 93% ` Timothy
0 siblings, 1 reply; 200+ results
From: Timothy @ 2021-04-30 8:52 UTC (permalink / raw)
To: Bastien; +Cc: emacs-orgmode@gnu.org, Eric S Fraga
Bastien <bzg@gnu.org> writes:
> Eric S Fraga <e.fraga@ucl.ac.uk> writes:
>
>> Further on this, I don't have time to debug right now but the patch
>> seems to have broken org table recalculation, specifically C-u C-c C-c
>> on a table.
>
> Thanks for reporting - Tim can you double-check this?
I checked the docs for `org-table-recalculate' and based on manually
calling it compared the behaviour to C-u C-c C-c on a table and noticed
no difference, but I'm not familiar with the intended functionality so
an example from Eric (or someone else) of what should happen would be
very helpful.
--
Timothy
^ permalink raw reply [relevance 93%]
* Re: [PATCH] Have C-c C-c recognise #+plot lines
2021-04-26 17:17 64% ` Timothy
2021-04-28 18:04 93% ` Timothy
@ 2021-04-30 7:06 93% ` Timothy
1 sibling, 0 replies; 200+ results
From: Timothy @ 2021-04-30 7:06 UTC (permalink / raw)
To: Eric S Fraga; +Cc: emacs-orgmode@gnu.org
Now that Eric and I have both tested this, and Nicolas' comments have
been taken into account, it would be great if a core maintainer could
consider applying this patch :)
--
Timothy
p.s. I'm specifically making a new reply to the version of the patch
that should be looked at, in the hope that this might help with clarity
when there are 4 different patches in this thread.
^ permalink raw reply [relevance 93%]
* Re: [PATCH] Have C-c C-c recognise #+plot lines
2021-04-26 17:17 64% ` Timothy
@ 2021-04-28 18:04 93% ` Timothy
2021-04-30 7:06 93% ` Timothy
1 sibling, 1 reply; 200+ results
From: Timothy @ 2021-04-28 18:04 UTC (permalink / raw)
To: Eric S Fraga; +Cc: emacs-orgmode@gnu.org
Hi Eric,
Have you had a chance to test this out?
--
Timothy
^ permalink raw reply [relevance 93%]
* [PATCH] fix point position shifting in some org-src instances
@ 2021-04-28 10:33 63% Timothy
0 siblings, 0 replies; 200+ results
From: Timothy @ 2021-04-28 10:33 UTC (permalink / raw)
To: org-mode-email
[-- Attachment #1: Type: text/plain, Size: 1047 bytes --]
Hi All,
I've noticed for a while that if you have a block with
overlays/invisible characters that editing it with `org-edit-special'
moves the point around.
For example, with Org pretty entities enabled, and █ indicating the
cursor, if I call org-edit-special on a LaTeX fragment like:
\( \alpha +█\beta \)
which is displayed as \( α +█β \)
The point is moved on creation of the org-src buffer
\( \alpha + \beta █\)
Then if I move it back to after the "+", on calling `org-edit-src-exit'
the point is moved to
\(█ \alpha + \beta \)
In the original buffer.
This may seem quite minor, but if you're editing a lot of LaTeX
fragments having the point constantly jumping around can be quite a
pain.
After investigating this, I tried shifting org-src--{goto-}coordinates
to a point-based approach from a column-based approach, and it seems to
have fixed the problem.
I have tested a few other situations (e.g. LaTeX environments, example
blocks, src blocks), and it seems to work well.
--
Timothy
[-- Attachment #2: 0001-org-src-Use-point-instead-of-column-for-coords.patch --]
[-- Type: text/x-patch, Size: 1882 bytes --]
From 8e8faf389d6d5c0769b5f95775ec7883820b10b3 Mon Sep 17 00:00:00 2001
From: TEC <tec@tecosaur.com>
Date: Wed, 28 Apr 2021 18:17:00 +0800
Subject: [PATCH] org-src: Use point instead of column for coords
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
* lisp/org-src.el (org-src--coordinates, org-src--goto-coordinates):
Using a column-based approach fails to account for invisible regions
or display overlays that change the number of columns: for example,
showing a LaTeX \alpha as α. In src edits which involve such
structures, this causes the point to be shifted undesirably.
By using a point-based approach this issue does not occur.
---
lisp/org-src.el | 9 ++++-----
1 file changed, 4 insertions(+), 5 deletions(-)
diff --git a/lisp/org-src.el b/lisp/org-src.el
index cabedecb6..a694e5595 100644
--- a/lisp/org-src.el
+++ b/lisp/org-src.el
@@ -327,8 +327,7 @@ (defun org-src--coordinates (pos beg end)
(cons (count-lines beg (line-beginning-position))
;; Column is relative to the end of line to avoid problems of
;; comma escaping or colons appended in front of the line.
- (- (current-column)
- (progn (end-of-line) (current-column)))))))
+ (- (point) (min end (line-end-position)))))))
(defun org-src--goto-coordinates (coord beg end)
"Move to coordinates COORD relatively to BEG and END.
@@ -341,9 +340,9 @@ (defun org-src--goto-coordinates (coord beg end)
(org-with-wide-buffer
(goto-char beg)
(forward-line (car coord))
- (end-of-line)
- (org-move-to-column (max (+ (current-column) (cdr coord)) 0))
- (point)))))
+ (max (point)
+ (+ (min end (line-end-position))
+ (cdr coord)))))))
(defun org-src--contents-area (datum)
"Return contents boundaries of DATUM.
--
2.31.1
^ permalink raw reply related [relevance 63%]
* Re: [PATCH] Add font-lock rule for inline export snippets
@ 2021-04-28 7:23 93% ` Timothy
0 siblings, 0 replies; 200+ results
From: Timothy @ 2021-04-28 7:23 UTC (permalink / raw)
To: org-mode-email
Timothy <tecosaur@gmail.com> writes:
> Hello,
>
> The latest in my visually-oriented (mostly) short patch series, adding
> basic fontification to inline export snippets --- @@comment:these things@@.
>
> I think fontification for stuff like this is nice because it visually
> indicates to the user that they've written out an Org construct, and
> haven't just mis-remembered / imagined some syntax.
>
> In future this could be extended to use native fontification for
> recognised export formats (like src blocks do), but I think this is a
> nice improvement over nothing.
This addition to the font-lock regexps is quite simple, and doesn't
contain anything fancy/expensive (like backtracking), so I don't expect
there to be any performance concerns --- but it would be good to hear
from others :)
I considered limiting this to no-newlines, but
https://orgmode.org/worg/dev/org-syntax.html says anything other than @@
is allowed.
--
Timothy
^ permalink raw reply [relevance 93%]
* Re: [PATCH] Fontification for inline src blocks
@ 2021-04-28 7:14 88% ` Timothy
2021-05-02 20:17 93% ` Timothy
2021-11-21 14:09 49% ` Timothy
2 siblings, 1 reply; 200+ results
From: Timothy @ 2021-04-28 7:14 UTC (permalink / raw)
To: org-mode-email
Timothy <tecosaur@gmail.com> writes:
> Hi All,
>
> I've been using inline src blocks a fair bit more recently, and I've
> thought it's a pity how bad they look as they are currently without
> fontification. A little digging into Org internals and font-lock later
> and we have this patch. I could speak about what's been done, but I
> think a screenshot does a much better comparison.
>
> For more details, see the attached patch.
Since this affects font-lock, display performance is obviously a key
concern, and so I have two things to note on that front:
1. I have been using this patch for over a month at this point,
frequently in a ~10k line Org file (my Emacs config), and there has
been no noticeable performance degradation
2. The most expensive part of this is the native syntax highlighting,
which is only used when `org-src-fontify-natively' is t, and the
second most expensive part (results formatting) is only performed
when `org-inline-src-prettify-results' (a new variable) is t.
In brief: I don't anticipate any significant performance implications of
this patch, though of course second opinions would be great :)
--
Timothy
^ permalink raw reply [relevance 88%]
* Re: [PATCH]
@ 2021-04-28 3:53 91% ` Timothy
0 siblings, 0 replies; 200+ results
From: Timothy @ 2021-04-28 3:53 UTC (permalink / raw)
To: Bastien; +Cc: org-mode-email
Bastien <bzg@gnu.org> writes:
> Feel free to install changes when they have reached consensus,
> or to ask for decisions when not.
Thanks for the reply Bastien, would you mind elaborating on this a bit
more? I'm comfortable with the idea of what I can do with org-plot.el as
the maintainer (directly push, but field patches to the ML for
non-trivial changes), but as a non-core-contributor I didn't think I
could push my own patches for other things.
Also, with the batch of patches I sent a plea about recently, how would
you recommend I proceed with that? There doesn't seem to be any
consensus or decision despite prompting.
Thanks,
Timothy
^ permalink raw reply [relevance 91%]
* Re: [PATCH] ox-md.el export code blocks using grave accents.
@ 2021-04-27 10:18 92% ` Timothy
0 siblings, 0 replies; 200+ results
From: Timothy @ 2021-04-27 10:18 UTC (permalink / raw)
To: Bruce D'Arcus; +Cc: Tim Cross, emacs-orgmode
Bruce D'Arcus <bdarcus@gmail.com> writes:
> On Sat, Jan 30, 2021, 6:29 PM Tim Cross <theophilusx@gmail.com> wrote:
>
>> There are no precise standards for markdown, but org states in the
>> manual that the version of markdown it supports is that defined at
>> http://daringfireball.net/projects/markdown
>
> Perhaps at some point it would make sense to change to this, which is
> much more precisely specified:
>
> https://commonmark.org/
The only change I'd think would be worthwhile, is to complicate ox-md by
introducing the concept of styles/presets.
Even just commonmark has multiple ways you can do things (backticks and
spaces for code), and I'd think supporting a set like: Gruber's
original, commonmark, and GFM would make sense.
Alternatively, we can leave that to other backends like ox-gfm.
Basically: markdown is a mess and I'm not sure what would be a good
course of action.
--
Timothy
^ permalink raw reply [relevance 92%]
* Re: [PATCH] Have C-c C-c recognise #+plot lines
2021-04-26 17:13 64% ` Timothy
@ 2021-04-26 17:17 64% ` Timothy
2021-04-28 18:04 93% ` Timothy
2021-04-30 7:06 93% ` Timothy
0 siblings, 2 replies; 200+ results
From: Timothy @ 2021-04-26 17:17 UTC (permalink / raw)
To: Eric S Fraga; +Cc: emacs-orgmode@gnu.org
[-- Attachment #1: Type: text/plain, Size: 82 bytes --]
... I didn't regenerate the patch after amending the commit.
:big sigh: Take 4
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-org-Enable-plotting-with-C-c-C-c.patch --]
[-- Type: text/x-patch, Size: 3030 bytes --]
From 4e5fcb4726711ff356656cb6fccf6e341656443d Mon Sep 17 00:00:00 2001
From: TEC <tec@tecosaur.com>
Date: Tue, 27 Apr 2021 00:05:37 +0800
Subject: [PATCH] org: Enable plotting with C-c C-c
* lisp/org.el (org-ctrl-c-ctrl-c): When at a table, check if the current
line starts with "#+plot", and if so call `org-plot/gnuplot'.
As I think 4-deep nested if statements are bad for readability, I
refactored the nested if statements to use `cond' while I was at it.
---
lisp/org.el | 41 +++++++++++++++++++++++------------------
1 file changed, 23 insertions(+), 18 deletions(-)
diff --git a/lisp/org.el b/lisp/org.el
index 3f9c9a284..94ef9660d 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -17693,24 +17693,29 @@ (defun org-ctrl-c-ctrl-c (&optional arg)
;; send the table if necessary. If the table has
;; a `table.el' type, just give up. At a table row or cell,
;; maybe recalculate line but always align table.
- (if (eq (org-element-property :type context) 'table.el)
- (message "%s" (substitute-command-keys "\\<org-mode-map>\
-Use `\\[org-edit-special]' to edit table.el tables"))
- (if (or (eq type 'table)
- ;; Check if point is at a TBLFM line.
- (and (eq type 'table-row)
- (= (point) (org-element-property :end context))))
- (save-excursion
- (if (org-at-TBLFM-p)
- (progn (require 'org-table)
- (org-table-calc-current-TBLFM))
- (goto-char (org-element-property :contents-begin context))
- (org-call-with-arg 'org-table-recalculate (or arg t))
- (orgtbl-send-table 'maybe)))
- (org-table-maybe-eval-formula)
- (cond (arg (call-interactively #'org-table-recalculate))
- ((org-table-maybe-recalculate-line))
- (t (org-table-align))))))
+ (cond
+ ((and (< (point) (org-element-property :post-affiliated context))
+ (org-match-line "[ \t]*#\\+plot:"))
+ (org-plot/gnuplot))
+ ((eq (org-element-property :type context) 'table.el)
+ (message "%s" (substitute-command-keys "\\<org-mode-map>\
+Use `\\[org-edit-special]' to edit table.el tables")))
+ ((or (eq type 'table)
+ ;; Check if point is at a TBLFM line.
+ (and (eq type 'table-row)
+ (= (point) (org-element-property :end context))))
+ (save-excursion
+ (if (org-at-TBLFM-p)
+ (progn (require 'org-table)
+ (org-table-calc-current-TBLFM))
+ (goto-char (org-element-property :contents-begin context))
+ (org-call-with-arg 'org-table-recalculate (or arg t))
+ (orgtbl-send-table 'maybe))))
+ (t
+ (org-table-maybe-eval-formula)
+ (cond (arg (call-interactively #'org-table-recalculate))
+ ((org-table-maybe-recalculate-line))
+ (t (org-table-align))))))
((or `timestamp (and `planning (guard (org-at-timestamp-p 'lax))))
(org-timestamp-change 0 'day))
((and `nil (guard (org-at-heading-p)))
--
2.31.1
[-- Attachment #3: Type: text/plain, Size: 31 bytes --]
Sorry for the noise,
Timothy
^ permalink raw reply related [relevance 64%]
* Re: [PATCH] Have C-c C-c recognise #+plot lines
2021-04-26 17:11 63% ` Timothy
@ 2021-04-26 17:13 64% ` Timothy
2021-04-26 17:17 64% ` Timothy
0 siblings, 1 reply; 200+ results
From: Timothy @ 2021-04-26 17:13 UTC (permalink / raw)
To: Eric S Fraga; +Cc: emacs-orgmode@gnu.org
[-- Attachment #1: Type: text/plain, Size: 242 bytes --]
Timothy <tecosaur@gmail.com> writes:
> Since you don't seem to have pushed yet, here's an updated patch that
> takes into account Nicolas' comments.
... and that patch didn't take into account the need to escape "+" in
the regex.
Take 3.
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-org-Enable-plotting-with-C-c-C-c.patch --]
[-- Type: text/x-patch, Size: 3030 bytes --]
From 4e5fcb4726711ff356656cb6fccf6e341656443d Mon Sep 17 00:00:00 2001
From: TEC <tec@tecosaur.com>
Date: Tue, 27 Apr 2021 00:05:37 +0800
Subject: [PATCH] org: Enable plotting with C-c C-c
* lisp/org.el (org-ctrl-c-ctrl-c): When at a table, check if the current
line starts with "#+plot", and if so call `org-plot/gnuplot'.
As I think 4-deep nested if statements are bad for readability, I
refactored the nested if statements to use `cond' while I was at it.
---
lisp/org.el | 41 +++++++++++++++++++++++------------------
1 file changed, 23 insertions(+), 18 deletions(-)
diff --git a/lisp/org.el b/lisp/org.el
index 3f9c9a284..94ef9660d 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -17693,24 +17693,29 @@ (defun org-ctrl-c-ctrl-c (&optional arg)
;; send the table if necessary. If the table has
;; a `table.el' type, just give up. At a table row or cell,
;; maybe recalculate line but always align table.
- (if (eq (org-element-property :type context) 'table.el)
- (message "%s" (substitute-command-keys "\\<org-mode-map>\
-Use `\\[org-edit-special]' to edit table.el tables"))
- (if (or (eq type 'table)
- ;; Check if point is at a TBLFM line.
- (and (eq type 'table-row)
- (= (point) (org-element-property :end context))))
- (save-excursion
- (if (org-at-TBLFM-p)
- (progn (require 'org-table)
- (org-table-calc-current-TBLFM))
- (goto-char (org-element-property :contents-begin context))
- (org-call-with-arg 'org-table-recalculate (or arg t))
- (orgtbl-send-table 'maybe)))
- (org-table-maybe-eval-formula)
- (cond (arg (call-interactively #'org-table-recalculate))
- ((org-table-maybe-recalculate-line))
- (t (org-table-align))))))
+ (cond
+ ((and (< (point) (org-element-property :post-affiliated context))
+ (org-match-line "[ \t]*#\\+plot:"))
+ (org-plot/gnuplot))
+ ((eq (org-element-property :type context) 'table.el)
+ (message "%s" (substitute-command-keys "\\<org-mode-map>\
+Use `\\[org-edit-special]' to edit table.el tables")))
+ ((or (eq type 'table)
+ ;; Check if point is at a TBLFM line.
+ (and (eq type 'table-row)
+ (= (point) (org-element-property :end context))))
+ (save-excursion
+ (if (org-at-TBLFM-p)
+ (progn (require 'org-table)
+ (org-table-calc-current-TBLFM))
+ (goto-char (org-element-property :contents-begin context))
+ (org-call-with-arg 'org-table-recalculate (or arg t))
+ (orgtbl-send-table 'maybe))))
+ (t
+ (org-table-maybe-eval-formula)
+ (cond (arg (call-interactively #'org-table-recalculate))
+ ((org-table-maybe-recalculate-line))
+ (t (org-table-align))))))
((or `timestamp (and `planning (guard (org-at-timestamp-p 'lax))))
(org-timestamp-change 0 'day))
((and `nil (guard (org-at-heading-p)))
--
2.31.1
^ permalink raw reply related [relevance 64%]
* Re: [PATCH] Have C-c C-c recognise #+plot lines
@ 2021-04-26 17:11 63% ` Timothy
2021-04-26 17:13 64% ` Timothy
0 siblings, 1 reply; 200+ results
From: Timothy @ 2021-04-26 17:11 UTC (permalink / raw)
To: Eric S Fraga; +Cc: emacs-orgmode@gnu.org
[-- Attachment #1: Type: text/plain, Size: 111 bytes --]
Since you don't seem to have pushed yet, here's an updated patche that
takes into account Nicolas' comments.
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-org-Enable-plotting-with-C-c-C-c.patch --]
[-- Type: text/x-patch, Size: 3028 bytes --]
From 04270b64315fed399748509f1c09428557b7742d Mon Sep 17 00:00:00 2001
From: TEC <tec@tecosaur.com>
Date: Tue, 27 Apr 2021 00:05:37 +0800
Subject: [PATCH] org: Enable plotting with C-c C-c
* lisp/org.el (org-ctrl-c-ctrl-c): When at a table, check if the current
line starts with "#+plot", and if so call `org-plot/gnuplot'.
As I think 4-deep nested if statements are bad for readability, I
refactored the nested if statements to use `cond' while I was at it.
---
lisp/org.el | 41 +++++++++++++++++++++++------------------
1 file changed, 23 insertions(+), 18 deletions(-)
diff --git a/lisp/org.el b/lisp/org.el
index 3f9c9a284..c4e2e132f 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -17693,24 +17693,29 @@ (defun org-ctrl-c-ctrl-c (&optional arg)
;; send the table if necessary. If the table has
;; a `table.el' type, just give up. At a table row or cell,
;; maybe recalculate line but always align table.
- (if (eq (org-element-property :type context) 'table.el)
- (message "%s" (substitute-command-keys "\\<org-mode-map>\
-Use `\\[org-edit-special]' to edit table.el tables"))
- (if (or (eq type 'table)
- ;; Check if point is at a TBLFM line.
- (and (eq type 'table-row)
- (= (point) (org-element-property :end context))))
- (save-excursion
- (if (org-at-TBLFM-p)
- (progn (require 'org-table)
- (org-table-calc-current-TBLFM))
- (goto-char (org-element-property :contents-begin context))
- (org-call-with-arg 'org-table-recalculate (or arg t))
- (orgtbl-send-table 'maybe)))
- (org-table-maybe-eval-formula)
- (cond (arg (call-interactively #'org-table-recalculate))
- ((org-table-maybe-recalculate-line))
- (t (org-table-align))))))
+ (cond
+ ((and (< (point) (org-element-property :post-affiliated context))
+ (org-match-line "[ \t]*#+plot:"))
+ (org-plot/gnuplot))
+ ((eq (org-element-property :type context) 'table.el)
+ (message "%s" (substitute-command-keys "\\<org-mode-map>\
+Use `\\[org-edit-special]' to edit table.el tables")))
+ ((or (eq type 'table)
+ ;; Check if point is at a TBLFM line.
+ (and (eq type 'table-row)
+ (= (point) (org-element-property :end context))))
+ (save-excursion
+ (if (org-at-TBLFM-p)
+ (progn (require 'org-table)
+ (org-table-calc-current-TBLFM))
+ (goto-char (org-element-property :contents-begin context))
+ (org-call-with-arg 'org-table-recalculate (or arg t))
+ (orgtbl-send-table 'maybe))))
+ (t
+ (org-table-maybe-eval-formula)
+ (cond (arg (call-interactively #'org-table-recalculate))
+ ((org-table-maybe-recalculate-line))
+ (t (org-table-align))))))
((or `timestamp (and `planning (guard (org-at-timestamp-p 'lax))))
(org-timestamp-change 0 'day))
((and `nil (guard (org-at-heading-p)))
--
2.31.1
[-- Attachment #3: Type: text/plain, Size: 579 bytes --]
Eric S Fraga <e.fraga@ucl.ac.uk> writes:
> On Monday, 26 Apr 2021 at 16:24, Timothy wrote:
>> A while ago Eric raised two nice suggestions. (2) has just been
>> implemented as Bastien reminded me that I can now just push straight to
>> Org for org-plot.el without going through a patch-review process.
>>
>> This patch resolves (1).
>
> Timothy,
>
> I've updated org and applied the patch. Both aspects seem to work just
> fine. I haven't done much testing, however, as it's beer time... I'll
> update tomorrow should I run into any strange behaviour.
>
> thank you,
> eric
^ permalink raw reply related [relevance 63%]
* [PATCH] Have C-c C-c recognise #+plot lines
@ 2021-04-26 16:24 63% ` Timothy
[not found] ` <88f6c54a01f345d785492c4d5b3b82d3@VI1PR0102MB3327.eurprd01.prod.exchangelabs.com>
1 sibling, 0 replies; 200+ results
From: Timothy @ 2021-04-26 16:24 UTC (permalink / raw)
To: emacs-orgmode
[-- Attachment #1: Type: text/plain, Size: 617 bytes --]
A while ago Eric raised two nice suggestions. (2) has just been
implemented as Bastien reminded me that I can now just push straight to
Org for org-plot.el without going through a patch-review process.
This patch resolves (1).
Eric S Fraga <e.fraga@ucl.ac.uk> writes:
> 1. it would be consistent and useful if "C-c C-c" executed
> org-plot/gnuplot when on such a #+PLOT line.
>
> 2. why does point move to the next line when I do execute the command?
> This is somewhat annoying when playing around with the settings. It
> would be nice to have point remain where it is.
>
> Thank you all!
--
Timothy
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-org-Enable-plotting-with-C-c-C-c.patch --]
[-- Type: text/x-patch, Size: 2964 bytes --]
From fccd5f2c66fe8342da2a8eb405240f5247958597 Mon Sep 17 00:00:00 2001
From: TEC <tec@tecosaur.com>
Date: Tue, 27 Apr 2021 00:05:37 +0800
Subject: [PATCH] org: Enable plotting with C-c C-c
* lisp/org.el (org-ctrl-c-ctrl-c): When at a table, check if the current
line starts with "#+plot", and if so call `org-plot/gnuplot'.
As I think 4-deep nested if statements are bad for readability, I
refactored the nested if statements to use `cond' while I was at it.
---
lisp/org.el | 40 ++++++++++++++++++++++------------------
1 file changed, 22 insertions(+), 18 deletions(-)
diff --git a/lisp/org.el b/lisp/org.el
index 3f9c9a284..950509bfd 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -17693,24 +17693,28 @@ (defun org-ctrl-c-ctrl-c (&optional arg)
;; send the table if necessary. If the table has
;; a `table.el' type, just give up. At a table row or cell,
;; maybe recalculate line but always align table.
- (if (eq (org-element-property :type context) 'table.el)
- (message "%s" (substitute-command-keys "\\<org-mode-map>\
-Use `\\[org-edit-special]' to edit table.el tables"))
- (if (or (eq type 'table)
- ;; Check if point is at a TBLFM line.
- (and (eq type 'table-row)
- (= (point) (org-element-property :end context))))
- (save-excursion
- (if (org-at-TBLFM-p)
- (progn (require 'org-table)
- (org-table-calc-current-TBLFM))
- (goto-char (org-element-property :contents-begin context))
- (org-call-with-arg 'org-table-recalculate (or arg t))
- (orgtbl-send-table 'maybe)))
- (org-table-maybe-eval-formula)
- (cond (arg (call-interactively #'org-table-recalculate))
- ((org-table-maybe-recalculate-line))
- (t (org-table-align))))))
+ (cond
+ ((string-match-p "#\\+plot" (thing-at-point 'line t))
+ (org-plot/gnuplot))
+ ((eq (org-element-property :type context) 'table.el)
+ (message "%s" (substitute-command-keys "\\<org-mode-map>\
+Use `\\[org-edit-special]' to edit table.el tables")))
+ ((or (eq type 'table)
+ ;; Check if point is at a TBLFM line.
+ (and (eq type 'table-row)
+ (= (point) (org-element-property :end context))))
+ (save-excursion
+ (if (org-at-TBLFM-p)
+ (progn (require 'org-table)
+ (org-table-calc-current-TBLFM))
+ (goto-char (org-element-property :contents-begin context))
+ (org-call-with-arg 'org-table-recalculate (or arg t))
+ (orgtbl-send-table 'maybe))))
+ (t
+ (org-table-maybe-eval-formula)
+ (cond (arg (call-interactively #'org-table-recalculate))
+ ((org-table-maybe-recalculate-line))
+ (t (org-table-align))))))
((or `timestamp (and `planning (guard (org-at-timestamp-p 'lax))))
(org-timestamp-change 0 'day))
((and `nil (guard (org-at-heading-p)))
--
2.31.1
^ permalink raw reply related [relevance 63%]
* Re: [PATCH] Refresh inline plotted images
@ 2021-04-26 14:54 93% ` Timothy
0 siblings, 0 replies; 200+ results
From: Timothy @ 2021-04-26 14:54 UTC (permalink / raw)
To: org-mode-email
Applied in dadbd025f.*
Timothy <tecosaur@gmail.com> writes:
> Hi All,
>
> This patch improves the result of running org-plot in the following
> situation
>
> #+plot: ... file:"somefile.png"
>
> [[file:somefile.png]]
>
> Previously, when somefile.png is re-plotted the [[file:]] inline image
> did not refresh. With this patch, after plotting, overlays of the
> replotted image are refreshed.
* As Bastien pointed out to me, I /am/ the org-plot maintainer...
^ permalink raw reply [relevance 93%]
* Re: [PATCH] Babel: remove LaTeX environment -type #+results
@ 2021-04-25 18:09 92% ` Timothy
0 siblings, 0 replies; 200+ results
From: Timothy @ 2021-04-25 18:09 UTC (permalink / raw)
To: Greg Minshall; +Cc: org-mode-email
Greg Minshall <minshall@umich.edu> writes:
> Timothy,
>
> interesting. would this show up in #+RESULTS blocks? in (heaven
> forbid!) #+BEGIN_SRC blocks?
>
> cheers, Greg
The screenshot where it shows up is from the following Org buffer
(manually constructed for the example):
#+begin_src julia
[1 2; 3 4]
#+end_src
#+RESULTS:
\begin{equation}
\left[
\begin{array}{cc}
1 & 2 \\
3 & 4 \\
\end{array}
\right]
\end{equation}
#+begin_src julia
using Symbolics
@variables t
2^sin(t) + cos(t)/t
#+end_src
#+RESULTS:
\begin{equation}
\frac{\cos\left( t \right)}{t} + 2^{\sin\left( t \right)}
\end{equation}
The rendering is just done by `org-latex-preview'.
Hope that clears things up.
--
Timothy
^ permalink raw reply [relevance 92%]
* [PATCH] Babel: remove LaTeX environment -type #+results
@ 2021-04-25 9:06 74% Timothy
0 siblings, 2 replies; 200+ results
From: Timothy @ 2021-04-25 9:06 UTC (permalink / raw)
To: org-mode-email
[-- Attachment #1: Type: text/plain, Size: 343 bytes --]
Hi All,
I think there's potential for some really nice experiences leveraging
Org's latex rendering in combination with some languages' symbolic maths
ability.
This is /very nearly/ already supported, `org-babel-result-end' just
needs to be tweaked to also remove LaTeX environment -type #+results.
This is what I'd like to make possible:
[-- Attachment #2: julia-org-inline-maths.png --]
[-- Type: image/png, Size: 22821 bytes --]
[-- Attachment #3: Type: text/plain, Size: 13 bytes --]
--
Timothy
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #4: 0001-ob-core-Remove-LaTeX-environment-results-type.patch --]
[-- Type: text/x-patch, Size: 1618 bytes --]
From e7e7eb698883348eeb404c0bc58ed7aed52344c4 Mon Sep 17 00:00:00 2001
From: TEC <tec@tecosaur.com>
Date: Sun, 25 Apr 2021 16:51:15 +0800
Subject: [PATCH] ob-core: Remove LaTeX environment #+results type
* lisp/ob-core.el (org-babel-result-end): By adding latex-enviroment to
the possible results types, a much richer experience is possible for
backends that can produce LaTeX-formatted maths as their results (for
example: Calc, Julia with Latexify, Python with SymPy, Octave with
symbolic). This is superior to a LaTeX export block as LaTeX
environments can be (1) rendered inline, and (2) better used in
non-LaTeX export formats (e.g. HTML with MathJax). Without this,
backends can output a LaTeX environment, but new results will be added
in front instead of replacing the environment.
---
lisp/ob-core.el | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/lisp/ob-core.el b/lisp/ob-core.el
index 2e78ac3e6..12f67a8e2 100644
--- a/lisp/ob-core.el
+++ b/lisp/ob-core.el
@@ -2559,8 +2559,9 @@ (defun org-babel-result-end ()
(let ((element (org-element-at-point)))
(if (memq (org-element-type element)
;; Possible results types.
- '(drawer example-block export-block fixed-width item
- plain-list special-block src-block table))
+ '(drawer example-block export-block fixed-width
+ special-block src-block item plain-list table
+ latex-environment))
(save-excursion
(goto-char (min (point-max) ;for narrowed buffers
(org-element-property :end element)))
--
2.31.1
^ permalink raw reply related [relevance 74%]
* Re: [PATCH] Add org-meta*-final-hook
@ 2021-04-25 6:31 91% ` Timothy
0 siblings, 0 replies; 200+ results
From: Timothy @ 2021-04-25 6:31 UTC (permalink / raw)
To: Jay Bosamiya; +Cc: emacs-orgmode
Hi Jay,
Apologies for how incredibly long it's taken for someone to reply to
your email. It looks like this is your first contribution, so please
don't think this is the norm 😅, you just seemed to slip through the
cracks.
Jay Bosamiya <jaybosamiya@gmail.com> writes:
> Similar to org-shiftup-final-hook, org-shiftdown-final-hook, etc, I have
> added org-metaup-final-hook, org-metadown-final-hook, etc. Please see
> attached patch.
This seems consistent with what we already have, and so a good addition 👍.
> Please do let me know if any changes are required.
It looks like you have >15 lines changed here, so this is not eligible
to be a TINYCHANGE, i.e. we require FSF assignment
(see: https://orgmode.org/contribute.html#copyright) if you haven't got
this already.
--
Timothy
^ permalink raw reply [relevance 91%]
* Re: [PATCH] Async session eval (2nd attempt)
@ 2021-04-25 6:26 89% ` Timothy
0 siblings, 0 replies; 200+ results
From: Timothy @ 2021-04-25 6:26 UTC (permalink / raw)
To: Kyle Meyer; +Cc: Jack Kamm, emacs-orgmode
Hi Jack, Kyle,
This is moving at a glacial pace, but I'd love to see this merged ---
there's clearly a lot of interest in this from the community if not
within this mailing list (ob-async which is more limited has 250 stars
on GitHub).
Jack, do you think you might be able to make these tweaks so I can
implore the maintainers to "just merge this"? :P
Kyle, if Jack doesn't get back to us do you think we could just make
those changes and merge the patch as-is at some point? Or merge it and
then add a commit making these fixes?
--
Timothy.
Kyle Meyer <kyle@kyleam.com> writes:
> Jack Kamm writes:
>
>> I also have an async implementation for ob-R that's ready after this is
>> merged :)
>
> It's a bit disappointing that only one babel user has tested this out
> and provided feedback, but please feel free to merge this whenever you
> think it's ready.
>
> I'm very happy to leave the babel details to you, but here are minor
> comments from a quick read-through looking for things that will likely
> be changed/cleaned up (either in the Org repo or the Emacs repo) if left
> as is.
>
>> Subject: [PATCH] ob-comint.el, ob-python.el: Async session evaluation
> [...]
>> +;; Async evaluation
>
> For a heading comment, please use at least three semicolons.
>
> (info "(elisp)Comment Tips")
>
>> +
>> +(defvar-local org-babel-comint-async-indicator nil
>> + "Regular expression that `org-babel-comint-async-filter' scans for.
>> +It should have 2 parenthesized expressions,
>> +e.g. \"org_babel_async_\\(start\\|end\\|file\\)_\\(.*\\)\". The
>> +first parenthesized expression determines whether the token is
>> +delimiting a result block, or whether the result is in a file. If
>> +delimiting a block, the second expression gives a UUID for the
>> +location to insert the result. Otherwise, the result is in a tmp
>> +file, and the second expression gives the file name.")
>> +
>> +(defvar-local org-babel-comint-async-buffers nil
>> + "List of org-mode buffers to check for Babel async output results.")
>
> s/org-mode/Org mode/ here and other spots, following
> doc/Documentation_Standards.org and tree-wide cleanups like de24694f0
> (Turn org-mode into Org or Org mode, 2016-08-23).
>
> Also, you're missing two spaces between some sentences.
>
>> +(defmacro org-babel-comint-async-delete-dangling-and-eval
>> + (session-buffer &rest body)
>> + "Remove dangling text in SESSION-BUFFER and evaluate BODY.
>> +This is analogous to `org-babel-comint-with-output', but meant
>> +for asynchronous output, and much shorter because inserting the
>> +result is delegated to `org-babel-comint-async-filter'."
>> + (declare (indent 1))
>> + `(org-babel-comint-in-buffer ,session-buffer
>> + (goto-char (process-mark (get-buffer-process (current-buffer))))
>> + (delete-region (point) (point-max))
>> + ,@body))
>> +(def-edebug-spec org-babel-comint-async-with-output (sexp body))
>
> Please move this edebug spec to the `declare' form (see 7dd1cfb6c,
> 2021-02-12).
>
>> diff --git a/testing/lisp/test-ob-python.el b/testing/lisp/test-ob-python.el
>> index a2cc7b79c..0267678cd 100644
>> --- a/testing/lisp/test-ob-python.el
>> +++ b/testing/lisp/test-ob-python.el
>> @@ -207,6 +207,67 @@ (ert-deftest test-ob-python/session-value-sleep ()
>> #+end_src"
>> (org-babel-execute-src-block)))))
>>
>> +(ert-deftest test-ob-python/async-simple-session-output ()
>> + (let ((org-babel-temporary-directory "/tmp")
>
> Prefer `temporary-file-directory' to hard coding "/tmp".
>
> Thanks.
^ permalink raw reply [relevance 89%]
* Re: [final patch] Re: add new link type "contact:" for org-contacts.el
@ 2021-04-25 3:59 93% ` Timothy
0 siblings, 0 replies; 200+ results
From: Timothy @ 2021-04-25 3:59 UTC (permalink / raw)
To: emacs-orgmode
I'm afraid it looks like I either made a typo while doing this, or
something odd happened. Regardless it didn't work correctly.
Take 2, sorry for the noise --- but at least the patch section on
updates.orgmode.org should be more useful now as it only shows pending
patches again.
Timothy <tecosaur@gmail.com> writes:
> This was not marked as applied on updates.orgmode.org.
> Doing so with the X-Woof-Patch header.
>
> Bastien <bzg@gnu.org> writes:
>
>> Of course, done (c822c80ef).
>>
>> Sorry I forgot about this patch, and thanks for your reply.
^ permalink raw reply [relevance 93%]
* Re: [PATCH 0/1] Add option to delay fontification of source blocks
@ 2021-04-25 3:49 93% ` Timothy
0 siblings, 0 replies; 200+ results
From: Timothy @ 2021-04-25 3:49 UTC (permalink / raw)
To: emacs-orgmode
Marking as closed on updates.orgmode.org via the X-Woof-Patch header.
Leo Okawa Ericson <leo@relevant-information.com> writes:
> I can't think of a reason either (now that I know that jit-lock exists)
> so I will retract my patch.
^ permalink raw reply [relevance 93%]
Results 1-200 of ~300 next (older) | reverse | options above
-- pct% links below jump to the message on this page, permalinks otherwise --
2020-04-24 6:55 [patch suggestion] Mitigating the poor Emacs performance on huge org files: Do not use overlays for PROPERTY and LOGBOOK drawers Ihor Radchenko
2020-05-17 15:00 ` Ihor Radchenko
2020-05-17 15:40 ` Ihor Radchenko
2020-05-18 14:35 ` Nicolas Goaziou
2020-05-18 16:52 ` Ihor Radchenko
2020-05-19 13:07 ` Nicolas Goaziou
2020-05-23 13:52 ` Ihor Radchenko
2020-05-26 8:33 ` Nicolas Goaziou
2020-06-02 9:21 ` Ihor Radchenko
2020-06-05 7:26 ` Nicolas Goaziou
2020-06-05 8:18 ` Ihor Radchenko
2020-06-05 13:50 ` Nicolas Goaziou
2020-06-08 5:05 ` Ihor Radchenko
2020-06-10 17:14 ` Nicolas Goaziou
2020-08-11 6:45 ` Ihor Radchenko
2020-08-11 23:07 ` Kyle Meyer
2020-08-12 6:29 ` Ihor Radchenko
2020-09-20 5:53 ` Ihor Radchenko
2020-12-04 5:58 ` Ihor Radchenko
2021-03-21 9:09 ` Ihor Radchenko
2021-05-03 17:28 ` Bastien
2021-09-21 13:32 93% ` Timothy
2020-09-28 22:37 [PATCH] Add org-meta*-final-hook Jay Bosamiya
2021-04-25 6:31 91% ` Timothy
2020-10-25 18:54 [PATCH] Async session eval (2nd attempt) Jack Kamm
2021-01-03 8:51 ` TEC
2021-02-28 22:23 ` Jack Kamm
2021-03-04 5:13 ` Kyle Meyer
2021-04-25 6:26 89% ` Timothy
2020-10-30 7:35 [PATCH] add new link type "contact:" for org-contacts.el stardiviner
2020-10-30 7:44 ` stardiviner
2020-11-09 0:24 ` stardiviner
2020-11-09 6:14 ` Jean Louis
2020-11-10 1:15 ` [UPDATED PATCH] " stardiviner
2020-11-11 8:37 ` Bastien
2020-11-11 12:04 ` stardiviner
2020-11-11 13:57 ` More on design of org-contacts.el - " Jean Louis
2020-11-16 9:26 ` stardiviner
2020-12-14 6:06 ` Bastien
2020-12-15 8:53 ` [final patch] " stardiviner
2020-12-15 9:56 ` Bastien
2020-12-15 14:13 ` stardiviner
2020-12-15 14:27 ` Bastien
2021-04-25 3:31 ` Timothy
2021-04-25 3:59 93% ` Timothy
2020-12-17 17:23 [PATCH] A proposal to add LaTeX attributes to verse blocks Juan Manuel Macías
2021-01-03 10:25 ` TEC
2021-01-03 13:07 ` Juan Manuel Macías
2021-01-03 13:08 ` TEC
2021-01-07 18:52 ` Juan Manuel Macías
2021-05-01 10:58 ` Bastien
[not found] ` <87tunlxws3.fsf@ucl.ac.uk>
2021-05-02 11:31 92% ` Timothy
2021-05-01 10:58 93% ` Timothy
2021-01-20 10:46 [PATCH] TEC
2021-04-28 3:38 ` [PATCH] Bastien
2021-04-28 3:53 91% ` [PATCH] Timothy
2021-01-30 21:57 [PATCH] ox-md.el export code blocks using grave accents Rodrigo Morales
2021-01-30 22:51 ` Tim Cross
2021-04-27 10:03 ` Bruce D'Arcus
2021-04-27 10:18 92% ` Timothy
2021-03-08 22:57 [PATCH] org-src.el Do not ask to revert unmodified buffers pillule
2021-03-21 20:33 ` Kyle Meyer
2021-03-26 3:10 ` pillule
2021-05-01 10:55 93% ` Timothy
2021-03-25 11:58 org-plot/gnuplot: question and feature suggestions Eric S Fraga
2021-04-26 16:24 63% ` [PATCH] Have C-c C-c recognise #+plot lines Timothy
[not found] ` <88f6c54a01f345d785492c4d5b3b82d3@VI1PR0102MB3327.eurprd01.prod.exchangelabs.com>
2021-04-26 17:05 ` Eric S Fraga
2021-04-26 17:11 63% ` Timothy
2021-04-26 17:13 64% ` Timothy
2021-04-26 17:17 64% ` Timothy
2021-04-28 18:04 93% ` Timothy
2021-04-30 8:17 ` Eric S Fraga
2021-04-30 8:22 ` Bastien
2021-04-30 8:52 93% ` Timothy
2021-04-30 10:59 ` Eric S Fraga
2021-04-30 12:16 91% ` Timothy
2021-04-30 7:06 93% ` Timothy
2021-03-25 18:25 [PATCH 0/1] Add option to delay fontification of source blocks leo
2021-04-25 3:49 93% ` Timothy
2021-03-31 15:00 [PATCH] Fontification for inline src blocks Timothy
2021-04-28 7:14 88% ` Timothy
2021-05-02 20:17 93% ` Timothy
2021-05-02 20:57 ` Tom Gillespie
2021-05-02 21:03 87% ` Timothy
2021-05-03 3:29 43% ` Timothy
2021-05-12 11:15 93% ` Timothy
2021-05-12 14:24 ` Ihor Radchenko
2021-05-12 14:47 93% ` Timothy
2021-05-12 15:53 ` Ihor Radchenko
2021-05-12 16:39 82% ` Timothy
2021-05-18 12:06 ` Sébastien Miquel
2021-05-18 13:34 80% ` Timothy
2021-10-03 7:14 ` Ihor Radchenko
2021-10-03 7:16 93% ` Timothy
2021-10-03 9:09 ` Ihor Radchenko
2021-10-03 9:22 83% ` Timothy
2021-11-21 14:09 49% ` Timothy
2021-11-22 11:52 45% ` Timothy
2021-11-22 12:23 ` Ihor Radchenko
2021-11-22 13:43 44% ` Timothy
2021-11-22 14:35 ` Ihor Radchenko
2021-11-22 14:37 93% ` Timothy
2021-11-23 13:30 ` Ihor Radchenko
2021-11-29 19:21 49% ` Timothy
2021-11-30 11:44 93% ` Timothy
2021-11-30 12:45 ` Sébastien Miquel
2021-11-30 12:46 93% ` Timothy
2021-12-02 12:53 ` Eric S Fraga
2021-12-02 13:57 91% ` Faces for inline src blocks (was: [PATCH] Fontification for inline src blocks) Timothy
2021-03-31 15:25 [PATCH] avoid loading major modes when exporting to file Timothy
2021-05-01 16:52 ` Bastien
2021-05-01 17:26 84% ` Timothy
2021-03-31 15:57 [PATCH] Add font-lock rule for inline export snippets Timothy
2021-04-28 7:23 93% ` Timothy
2021-03-31 16:41 [PATCH] Wrap LaTeX snippets in $$ with markdown export Timothy
2021-03-31 20:59 ` Berry, Charles via General discussions about Org-mode.
2021-05-02 20:20 93% ` Timothy
2021-05-02 20:23 93% ` Timothy
2021-05-03 16:13 ` Nicolas Goaziou
2021-05-03 18:03 88% ` Timothy
2021-05-03 22:54 ` Nicolas Goaziou
2021-05-04 3:35 57% ` Timothy
2021-05-04 13:03 ` Nicolas Goaziou
2021-05-04 13:31 88% ` Timothy
2021-05-06 21:56 ` Nicolas Goaziou
2021-05-09 20:12 93% ` Timothy
2021-04-04 18:46 [PATCH] LaTeX export: arbitrary float environments Thomas S. Dye
2021-05-01 11:08 91% ` Timothy
2021-05-01 17:20 ` Thomas S. Dye
2021-05-01 17:31 88% ` Timothy
2021-04-24 4:59 [PATCH] Refresh inline plotted images Timothy
2021-04-26 14:54 93% ` Timothy
2021-04-25 9:06 74% [PATCH] Babel: remove LaTeX environment -type #+results Timothy
2021-04-25 13:44 ` Greg Minshall
2021-04-25 18:09 92% ` Timothy
2021-05-01 11:03 ` Bastien
2021-05-01 11:44 93% ` Timothy
2021-04-28 10:33 63% [PATCH] fix point position shifting in some org-src instances Timothy
2021-05-28 22:40 [PATCH] Fixed lstset where language= wipes out previous definitions Karl Stump
2021-09-19 13:02 93% ` Timothy
2021-06-03 21:58 [PATCH] Add faces to improve contextuality of agenda views Protesilaos Stavrou
2021-09-19 13:23 93% ` Timothy
2021-06-06 16:55 68% [PATCH] Change default latex compiler to latexmk Timothy
2021-06-29 14:32 ` Bruce D'Arcus
2021-06-30 10:48 ` Bastien
2021-06-30 11:14 ` Bruce D'Arcus
2021-07-09 12:30 ` Bruce D'Arcus
2021-07-09 14:17 ` Bastien
2021-07-09 14:25 93% ` Timothy
2021-07-09 15:03 ` Bastien
2021-07-09 16:41 93% ` Timothy
2021-06-06 18:02 53% [PATCH] html export: remove W3C warning, improve accessibility Timothy
2021-06-06 18:19 61% [PATCH] Allow LaTeX reference command (\ref) to be customised Timothy
2021-06-09 2:11 93% ` Timothy
2021-06-09 11:52 ` Nicolas Goaziou
2021-06-09 13:36 90% ` Timothy
2021-06-09 15:08 ` Nicolas Goaziou
2021-06-09 17:38 93% ` Timothy
2021-06-16 23:29 [PATCH] ob-core: tangle check library of babel after current buffer Tom Gillespie
2021-07-17 17:42 ` Tom Gillespie
2021-07-24 19:41 93% ` Timothy
2021-06-20 9:17 [PATCH] Fix regression in org-get-time-of-day introduced in aba1f2066 Ihor Radchenko
2021-06-20 16:09 ` Nicolas Goaziou
2021-07-24 19:48 93% ` Timothy
2021-06-23 22:50 [PATCH] ob-R output file with graphics parameter Jeremie Juste
2021-06-24 9:21 ` Colin Baxter
2021-06-27 17:12 ` Jack Kamm
2021-06-28 21:54 ` Jeremie Juste
2021-07-03 4:21 ` Jack Kamm
2021-07-03 4:52 92% ` Timothy
2021-06-28 9:34 [PATCH] Customizify org-babel-fortran-compiler Nico Sonack
2021-07-01 14:45 93% ` Timothy
2021-06-28 10:21 Nico Sonack
2021-07-01 14:40 85% ` Timothy
2021-06-28 12:42 [patch] add :url and :doi optional entries for export to BiBTeX Eric S Fraga
2021-06-28 12:59 ` Eric S Fraga
2021-07-01 14:23 93% ` Timothy
2021-07-01 3:50 [PATCH] Fix erroneous tangling of blocks Jacopo De Simoi
2021-07-01 13:38 93% ` Timothy
2021-07-08 16:04 [PATCH] bad table formula recorded in some cases tbanelwebmin
2021-07-21 10:50 93% ` Timothy
2021-07-21 14:25 ` tbanelwebmin
2021-07-21 15:07 93% ` Timothy
2021-07-12 3:51 [PATCH] Fix match/maxlevel conflict in colview dynblock Nick Dokos
2021-08-31 14:33 93% ` Timothy
2021-07-12 18:07 71% [PATCH] be more cautious when setting csl etc dir location Timothy
2021-07-14 19:39 93% ` Timothy
2021-07-15 2:33 [PATCH] manual: How to refer to tables in other files William Denton
2021-09-19 13:36 93% ` Timothy
2021-07-30 15:00 Bug: Percentage in caption (even escaped) does not work in LaTeX export Charest, Luc
2021-09-03 12:17 ` Maxim Nikulin
2021-09-07 12:21 ` [PATCH] ox-latex: Allow percent sign in 'src-block' caption Maxim Nikulin
2021-09-07 13:17 93% ` Timothy
2021-07-30 15:24 Bug: org-agenda-highlight-todo: Symbol’s function definition is void: string-empty-p [9.4.6 (9.4.6-11-g1ee52c-elpa @ /home/vmg/.emacs.d/elpa/org-20210726/)] Вячеслав Гришин
2021-08-04 15:20 ` [PATCH] org-agenda.el: Avoid dependency on subr-x Maxim Nikulin
2021-08-05 12:59 ` Timothy
2021-08-06 17:10 ` Maxim Nikulin
2021-08-06 20:30 93% ` Timothy
2021-08-02 15:45 [PATCH] minor typo fix in org-tutorials/org-protocol-custom-handler.org Atlas Cove
2021-08-14 23:25 ` Tim Cross
2021-08-15 2:24 ` Eric Abrahamsen
2021-09-19 12:42 93% ` Timothy
2021-08-05 12:12 [PATCH] Rename headline to heading André A. Gomes
2021-09-19 11:06 89% ` Timothy
2021-09-26 9:27 ` Bastien
2021-09-30 12:21 ` André A. Gomes
2021-10-01 8:38 ` Bastien
2021-10-15 8:52 ` André A. Gomes
2021-10-15 9:56 93% ` Timothy
2021-08-09 13:06 [patch] priorities range reversed Joe Corneli via General discussions about Org-mode.
2021-08-09 13:51 ` Joe Corneli via General discussions about Org-mode.
2021-08-31 15:14 93% ` Timothy
2021-08-09 14:41 [PATCH] Fix bug assuming canonical duration units in org-agenda-format-items Anders Johansson
2021-08-11 9:39 ` Nicolas Goaziou
2021-08-31 13:55 93% ` Timothy
2021-08-17 23:07 [PATCH] ox-ascii.el: Fix justify when `indent-tabs-mode' is non-nil Morgan Willcock
2021-08-31 11:59 90% ` Timothy
2021-08-31 12:42 ` Morgan Willcock
2021-08-31 12:54 93% ` Timothy
2021-09-19 13:13 92% ` Timothy
2021-09-19 15:30 ` Morgan Willcock
2021-09-19 17:02 93% ` Timothy
2021-08-23 10:23 75% [PATCH] org-cite: define \citeprocitem for LaTeX export Timothy
2021-08-26 8:18 93% ` Timothy
2021-09-19 13:19 93% ` Timothy
2021-08-23 10:27 72% [PATCH] org-cite: prevent ' from being an active char in " Timothy
2021-08-26 8:24 93% ` Timothy
2021-08-24 11:02 [PATCH] Update some changed export keybindings [worg] Stefan Kangas
2021-08-31 11:37 93% ` Timothy
2021-08-25 20:12 [BUG] Creating sparse tree with regexp property matches Cassio Koshikumo
2021-08-25 21:03 ` Daniel Fleischer
2021-08-25 22:30 ` Cassio Koshikumo
2021-08-31 11:27 ` Timothy
2021-08-31 12:28 ` Daniel Fleischer
2021-08-31 12:56 ` Timothy
2021-08-31 20:31 ` Daniel Fleischer
2021-09-01 10:28 ` Timothy
2021-09-01 11:32 ` Daniel Fleischer
2021-09-02 6:35 ` [PATCH] " Daniel Fleischer
2021-09-16 15:01 ` Daniel Fleischer
2021-09-17 10:17 85% ` Timothy
2021-09-02 4:47 Bug: org-agenda-sort-notime-is-late is not correctly handled by timestamp comparison [9.4.6 (9.4.6-12-gdcc3a8-elpaplus @ /Users/charlestam/.emacs.d/elpa/org-plus-contrib-20210830/)] Charles Tam
2021-12-30 9:20 76% ` [PATCH] " Timothy
2021-09-02 13:44 [PATCH] Re: New source block results option for attaching file to node Greg Minshall
2021-09-03 3:10 ` Ihor Radchenko
2021-09-03 3:28 ` Ryan Scott
2021-09-05 13:22 ` Ihor Radchenko
2021-09-05 13:56 ` Ryan Scott
2021-09-10 1:04 ` Ryan Scott
2021-09-10 6:26 93% ` Timothy
2021-09-09 22:58 [BUG?][PATCH] Should the `lexical-binding' variable be bound during src block with :lexical t? [9.4.6 (9.4.6-ga451f9 @ /home/n/.emacs.d/straight/build/org/)] No Wayman
2021-09-10 6:32 93% ` Timothy
2021-09-11 7:05 [PATCH] ob-tangle.el: Fix error in org-tangle from org-src edit buffer Mark Dawson
2021-09-19 12:57 93% ` Timothy
2021-09-16 10:34 [PATCH] Various minor docfixes found by checkdoc Stefan Kangas
2021-09-16 19:30 ` Marco Wahl
2021-09-19 13:00 93% ` Timothy
2021-09-16 21:40 [PATCH] Fix some typos Stefan Kangas
2021-09-17 9:03 93% ` Timothy
2021-09-20 11:56 [PATCH] org-cite: Use citeproc-el to create CSL processor itemgetters András Simonyi
2021-09-20 12:29 91% ` Timothy
2021-09-24 0:03 [PATCH] org-manual.org: Augment TODO keywords example Thomas S. Dye
2021-09-24 4:39 93% ` Timothy
2021-09-24 0:06 Thomas S. Dye
2021-09-24 4:41 93% ` Timothy
2021-09-24 19:56 [PATCH] Include support for evaluating julia code Pedro Bruel
2021-09-24 20:04 93% ` Timothy
2021-09-25 14:06 ` Bastien
2021-09-25 14:13 93% ` Timothy
2021-09-26 11:51 54% [PATCH] Timothy
2021-09-26 12:01 93% ` [PATCH] Timothy
2021-09-26 12:14 63% ` [PATCH] Timothy
2021-09-27 8:19 ` [PATCH] Bastien
2021-09-27 10:35 38% ` [PATCH] Timothy
2021-09-27 11:45 ` [PATCH] Bastien
2021-09-27 12:20 93% ` [PATCH] Timothy
2021-09-27 15:26 ` [PATCH] Bastien
2021-09-27 15:36 93% ` [PATCH] Timothy
2021-09-27 17:44 ` [PATCH] Bastien
2021-09-27 17:52 93% ` [PATCH] Timothy
2021-09-27 19:45 ` [PATCH] Bastien
2021-09-28 15:31 ` [PATCH] Bastien Guerry
2021-09-28 15:50 93% ` [PATCH] Timothy
2021-09-26 15:03 [PATCH] ob-svgbob: New babel backend for SVGBob Steven vanZyl
2021-09-26 20:33 ` Bastien
2021-09-26 20:35 89% ` Timothy
2021-09-28 14:54 [PATCH] Treat :tangle-mode as an octal value not integer Jeremy Cowgar
2021-09-29 13:48 87% ` Timothy
2021-09-29 14:26 ` tomas
2021-09-29 14:58 78% ` Timothy
2021-09-29 15:13 ` Jeremy Cowgar
2021-09-30 18:13 93% ` Timothy
2021-09-29 17:18 ` Greg Minshall
2021-11-18 12:04 93% ` Timothy
2021-09-28 14:58 64% [PATCH] (minor) Use lower case keywords in ox-org Timothy
2021-09-29 13:33 71% [PATCH] Prevent displayed images from being re-scaled Timothy
2021-10-02 20:30 93% ` Timothy
2021-10-25 13:49 93% ` Timothy
2021-10-03 4:57 ` Bastien
2021-10-03 5:45 93% ` Timothy
2021-09-30 17:20 66% [PATCH] Don't fill displayed equations Timothy
2021-09-30 17:44 74% ` Timothy
2021-09-30 18:51 ` Nicolas Goaziou
2021-09-30 18:54 93% ` Timothy
2021-09-30 19:02 ` Nicolas Goaziou
2021-09-30 19:28 93% ` Timothy
2021-09-30 20:45 63% ` Timothy
2021-09-30 22:55 ` Nicolas Goaziou
2021-10-01 7:38 ` Stefan Nobis
2021-10-01 20:41 ` Nicolas Goaziou
2021-10-02 10:04 ` Eric S Fraga
2021-10-02 10:18 83% ` Timothy
2021-10-02 11:24 ` Eric S Fraga
2021-10-02 14:21 ` Max Nikulin
2021-10-02 17:51 ` Tom Gillespie
2021-10-02 18:28 93% ` Timothy
2021-10-01 7:43 69% ` Timothy
2021-10-02 11:06 ` Nicolas Goaziou
2021-10-02 11:24 93% ` Timothy
2021-10-03 8:49 ` Ihor Radchenko
2021-10-03 8:50 93% ` Timothy
2021-10-03 9:13 ` Ihor Radchenko
2021-10-03 9:14 93% ` Timothy
2021-10-03 9:41 ` Ihor Radchenko
2021-10-03 9:42 93% ` Timothy
2021-10-04 6:05 83% ` Timothy
2021-10-04 7:11 ` Tom Gillespie
2021-10-04 7:15 93% ` Timothy
2021-09-30 18:14 52% [PATCH] Accept more :tangle-mode specification forms Timothy
2021-10-01 1:24 ` Tom Gillespie
2021-10-01 6:59 71% ` Timothy
2021-10-01 8:00 ` Stefan Nobis
2021-10-01 10:05 ` Eric S Fraga
2021-10-01 10:29 ` tomas
2021-10-01 18:04 ` Tom Gillespie
2021-10-01 18:14 82% ` Timothy
2021-10-05 14:45 93% ` Timothy
2021-10-05 15:54 ` unknown@email.com
2021-10-05 16:13 93% ` Timothy
2021-11-18 10:20 93% ` Timothy
2021-11-18 17:22 87% ` Timothy
2021-11-19 16:31 ` Tim Cross
2021-11-20 8:08 60% ` Timothy
2021-11-20 12:25 ` tomas
2021-11-20 14:50 93% ` Timothy
2021-11-21 4:08 ` Greg Minshall
2021-11-21 4:27 93% ` Timothy
2021-11-20 19:49 ` Tim Cross
2021-11-21 4:02 67% ` Timothy
2021-11-21 13:51 ` Tim Cross
2021-11-21 14:33 64% ` Timothy
2021-11-29 18:57 91% ` Timothy
2021-10-05 22:37 [PATCH] ob-R async evaluation Jeremie Juste
2021-11-18 10:36 93% ` Timothy
2021-10-13 22:14 [PATCH] org-manual.org: org-cite additions Bruce D'Arcus
2021-11-18 8:08 93% ` Timothy
2021-10-23 12:18 [PATCH] org.el (org-display-inline-image--width): Small fix Sébastien Miquel
2021-11-03 16:25 ` Nicolas Goaziou
2021-11-18 12:06 93% ` Timothy
2021-10-24 17:20 [patch] Fix link to Library of Babel Thomas S. Dye
2021-11-21 7:04 93% ` Dodgy Worg publishing? (was: [patch] Fix link to Library of Babel) Timothy
2021-10-28 15:24 [PATCH] org-src: Reset buffer-modified-p after fontifying Clément Pit-Claudel
2021-11-21 6:58 93% ` Timothy
[not found] <388850760.3644614.1634354740816.ref@mail.yahoo.com>
2021-10-16 3:25 ` Subject: [PATCH] Fix DISPLAY error on exporting org with plantuml to html Sun Lin
2021-11-18 7:38 92% ` Timothy
2021-11-18 7:47 ` Sun Lin
2021-11-30 1:41 ` Sun Lin
2021-11-30 4:18 90% ` Timothy
2021-11-21 18:41 [PATCH] Fix window width when line numbers present Matt Huszagh
2021-11-21 19:14 92% ` Timothy
2021-11-21 21:08 ` Nicolas Goaziou
2021-11-21 21:14 ` Matt Huszagh
2021-11-21 21:16 ` Bastien
2021-11-21 21:22 ` Matt Huszagh
2021-11-22 5:14 ` Bastien
2021-11-22 5:31 93% ` Timothy
2021-11-22 5:44 ` Bastien
2021-11-22 5:51 90% ` Supported Emacs version (was: [PATCH] Fix window width when line numbers present) Timothy
2021-11-22 3:16 93% ` [PATCH] Fix window width when line numbers present Timothy
2021-11-21 19:19 93% ` Timothy
2021-11-21 19:08 [PATCH] Fix regex for determining image width from attribute Matt Huszagh
2021-11-21 19:20 81% ` Timothy
2021-11-21 19:51 ` Matt Huszagh
2021-11-22 8:29 91% ` Timothy
2021-11-22 16:11 ` Matt Huszagh
2021-11-22 17:54 93% ` Timothy
2021-11-22 20:53 ` Matt Huszagh
2021-11-23 5:14 93% ` Timothy
2021-11-23 5:38 ` Matt Huszagh
2021-11-23 5:39 93% ` Timothy
2021-11-23 7:46 ` Matt Huszagh
2021-11-23 16:44 ` Max Nikulin
2021-11-24 1:57 ` Matt Huszagh
2021-11-24 14:48 ` Max Nikulin
2021-11-24 15:59 ` Matt Huszagh
2021-11-24 17:00 ` Max Nikulin
2021-11-25 16:43 ` Max Nikulin
2021-11-29 0:23 ` Matt Huszagh
2021-11-29 5:13 93% ` Timothy
2021-12-01 3:24 ` Matt Huszagh
2021-12-01 4:54 72% ` Timothy
2021-11-22 18:37 [PATCH] ob-shell-test, test-ob-shell and introduction Matt
2021-11-22 18:43 89% ` Timothy
2021-11-24 18:48 ` Matt
2021-12-02 9:39 93% ` Timothy
2021-11-24 16:11 [PATCH] Fix ob-plantuml over TRAMP Guillaume Buisson (gbuisson)
2021-12-02 9:43 93% ` Timothy
2021-11-28 15:59 [patch] fix ox-latex async export bug Rasmus
2021-11-28 19:52 ` Nicolas Goaziou
2021-11-28 22:54 ` Tim Cross
2021-11-29 5:15 93% ` Timothy
2021-12-30 4:05 [PATCH] Fix caption format for custom latex src block Matt Huszagh
2022-06-14 3:51 ` Ihor Radchenko
2022-06-28 4:07 ` Matt Huszagh
2022-06-29 2:24 ` Ihor Radchenko
2022-06-29 15:20 93% ` Timothy
2022-06-29 15:26 89% ` Timothy
2022-01-24 16:42 [PATCH] Add support for $…$ latex fragments followed by a dash Sébastien Miquel
2022-01-25 7:56 ` Eric S Fraga
2022-01-26 17:15 ` Rudolf Adamkovič
2022-01-27 8:28 ` Ihor Radchenko
2022-01-27 19:15 ` Tim Cross
2022-01-28 14:37 ` Max Nikulin
2022-01-28 16:37 90% ` Timothy
2022-01-29 16:00 53% [PATCH] Remote link localisation, i.e. exporting remote images Timothy
2022-01-31 11:40 93% ` Timothy
2022-05-04 15:59 12% [PATCH] New LaTeX code export option: engraved Timothy
2022-05-05 7:52 ` Daniel Fleischer
2022-05-05 16:09 93% ` Timothy
2022-05-06 2:35 ` Ihor Radchenko
2022-05-06 11:23 86% ` Timothy
2022-05-05 8:48 ` Ihor Radchenko
2022-05-05 15:17 12% ` Timothy
2022-05-05 16:13 25% ` Timothy
2022-05-07 5:16 ` Ihor Radchenko
2022-05-07 6:57 7% ` Timothy
2022-05-07 10:40 8% ` Timothy
2022-05-07 11:33 ` Daniel Fleischer
2022-05-08 14:30 6% ` [PATCH] (v2) " Timothy
2022-05-09 6:20 ` Ihor Radchenko
2022-05-09 12:57 81% ` Timothy
2022-05-11 16:05 5% ` [PATCH] (v3) " Timothy
2022-05-12 16:40 ` Daniel Fleischer
2022-05-12 16:44 93% ` Timothy
2022-05-09 19:19 ` [PATCH] " Sébastien Miquel
2022-05-10 1:13 93% ` Timothy
2022-05-10 16:10 93% ` Timothy
2022-06-05 14:32 43% [PATCH] Support #+include-ing URLs Timothy
2022-06-05 15:01 ` Max Nikulin
2022-06-07 10:09 ` Fraga, Eric
2022-06-07 11:27 91% ` Timothy
2022-06-12 9:52 93% ` Timothy
2022-06-12 14:43 37% [PATCH] New remote resource download policy Timothy
2022-06-14 9:40 ` Robert Pluim
2022-06-22 9:58 93% ` Timothy
2022-06-15 12:35 ` Max Nikulin
2022-06-22 10:01 85% ` Timothy
2022-06-22 16:55 ` Max Nikulin
2022-06-29 15:27 93% ` Timothy
2022-06-30 16:57 ` Max Nikulin
2022-07-16 9:47 92% ` Timothy
2022-06-27 12:08 [PATCH] Improve look of agenda on graphical displays Stefan Kangas
2022-06-29 9:19 ` Ihor Radchenko
2022-06-29 10:20 ` Stefan Kangas
2022-06-29 12:46 ` [STYLE] :version tags in defcustom definitions (was: [PATCH] Improve look of agenda on graphical displays) Ihor Radchenko
2022-06-29 12:55 ` Stefan Kangas
2022-06-29 14:07 93% ` Timothy
2022-07-08 12:17 LaTeX export: when is it more useful to use LuaTeX instead of pdfTeX? Juan Manuel Macías
2022-07-08 18:49 ` Thomas S. Dye
2022-07-09 2:23 ` Max Nikulin
2022-07-09 10:42 ` Juan Manuel Macías
2022-07-09 12:15 ` Max Nikulin
2022-07-09 14:58 ` Juan Manuel Macías
[not found] ` <b58ee3cc-c58c-b627-9cc5-51993020db2c@gmail.com>
2022-07-09 20:22 ` Juan Manuel Macías
2022-07-10 20:23 ` [possible patch] Basic fontspec code for LuaLaTeX and XelaTeX (was "LaTeX export: when is it more useful...") Juan Manuel Macías
2022-07-11 2:19 ` Ihor Radchenko
2022-07-11 14:19 76% ` Timothy
2022-07-11 15:00 ` Juan Manuel Macías
2022-07-11 17:45 85% ` fontsets (was: [possible patch] Basic fontspec code for LuaLaTeX and XelaTeX (was "LaTeX export: when is it more useful...")) Timothy
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).