From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp11.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms5.migadu.com with LMTPS id 4Bb3FrT6c2K+ywAAbAwnHQ (envelope-from ) for ; Thu, 05 May 2022 18:26:28 +0200 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp11.migadu.com with LMTPS id iDLZFrT6c2JL+wAA9RJhRA (envelope-from ) for ; Thu, 05 May 2022 18:26:28 +0200 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id ECCA1104C4 for ; Thu, 5 May 2022 18:26:27 +0200 (CEST) Received: from localhost ([::1]:37412 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nmeJ8-0007og-4j for larch@yhetil.org; Thu, 05 May 2022 12:26:26 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:35760) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nme81-0004sD-VQ for emacs-orgmode@gnu.org; Thu, 05 May 2022 12:14:58 -0400 Received: from mail-pf1-x431.google.com ([2607:f8b0:4864:20::431]:38758) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nme7z-0004Nq-3c for emacs-orgmode@gnu.org; Thu, 05 May 2022 12:14:57 -0400 Received: by mail-pf1-x431.google.com with SMTP id g8so4013586pfh.5 for ; Thu, 05 May 2022 09:14:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:references:user-agent:in-reply-to :message-id:mime-version; bh=TsR5XDCa7bziVPRYtgZgAhm1awr+SvR5+6+mwP9zvvE=; b=hLo5iWsfcs7Rh0spzbpvny2++WW/Xs8KwRy5wrZCF6W3/aLDFr57ielK6cHTAsK6Ee rre4zvRFrYZ5Uwe4OgVBbDd1Sovb7Hmys8Gb4zUPedRIWzSFC/RSRYhm7AL7ewIcPe/N tX7eFAkeqjGNniqYZTS62LbKDhOjBdkdedn6MwRr2Xgfc1sAjDr7v3FiuqxFe6NQiqjy 8N0lQ6BQKugLJcEFjXoZHHcl+6K3rOoUDr3uKP3htDN5aUOZQEElYSYF537NRByGnat6 UG64pI5zu16XJiGVN+xBkOGuLUPcO5eMXo3bj9KbtQNdyZZpqXqowTxVLNXYpbjmjGGe XFqQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:references:user-agent :in-reply-to:message-id:mime-version; bh=TsR5XDCa7bziVPRYtgZgAhm1awr+SvR5+6+mwP9zvvE=; b=2uluqPxGUHZDtnI9qqPSeTaCR7y9xpr0k1RPexZD1sIpSMNb8GksClljosD/491Ay3 awRHaEHWxQiBHhuB8LlWLuKeQygvniJdCmfFqY87ELZe0C8Eh1jRtOi/5MMsS/huBM68 AQSX7v0Y0LmOZCV4Me+xJniWulJy2lhuazODSYLbU5zpSNYXTglNTy5WV5lKcNcBBwEG DoGGKVKoRAbdJQTlC3CC9W+ON/ncNGvNGVS7ysrv5TfaCE4CH/Sg8mKTZ6AcXJYuwUjF qvgsYybaeHKio1tDhAwZbvLajZhqVpOR93yLgM4kkhVqgp9LMHGZMJequEFAKU7hp7nk JW3A== X-Gm-Message-State: AOAM532Z6sKm8hW3ou29uy6FXhCJTFkdmOuW4BfcB05uA5U4tk1CyZSb gJ8LL1oymxpkbnmxRVH9M6c7xg12Pxw= X-Google-Smtp-Source: ABdhPJyTEarxULlW+DJhiRhAYYztl4vgEwh5bK5IMXx7gtgnMFiXtsnq9t9KH4GcJqSBb9dFs0/0FQ== X-Received: by 2002:a62:5ec6:0:b0:510:71a1:f2f6 with SMTP id s189-20020a625ec6000000b0051071a1f2f6mr1732149pfb.69.1651767294204; Thu, 05 May 2022 09:14:54 -0700 (PDT) Received: from localhost (61-245-128-160.3df580.per.nbn.aussiebb.net. [61.245.128.160]) by smtp.gmail.com with ESMTPSA id l10-20020a17090a598a00b001dc99c4a74esm3759886pji.28.2022.05.05.09.14.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 May 2022 09:14:53 -0700 (PDT) From: Timothy To: Ihor Radchenko Cc: emacs-orgmode@gnu.org, Daniel Fleischer , Nicolas Goaziou Subject: Re: [PATCH] New LaTeX code export option: engraved Date: Fri, 06 May 2022 00:13:56 +0800 References: <87wnf1z1w8.fsf@gmail.com> <87sfpogyag.fsf@localhost> <87v8ukyo94.fsf@gmail.com> User-agent: mu4e 1.6.10; emacs 28.0.92 In-reply-to: <87v8ukyo94.fsf@gmail.com> Message-ID: <87sfpoyn0l.fsf@gmail.com> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Received-SPF: pass client-ip=2607:f8b0:4864:20::431; envelope-from=tecosaur@gmail.com; helo=mail-pf1-x431.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-orgmode@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+larch=yhetil.org@gnu.org Sender: "Emacs-orgmode" X-Migadu-Flow: FLOW_IN X-Migadu-To: larch@yhetil.org X-Migadu-Country: US ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1651767988; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:in-reply-to:in-reply-to: references:references:list-id:list-help:list-unsubscribe: list-subscribe:list-post:dkim-signature; bh=4FFwDvUkXAz6IZA+QIy5Ih2KJUl4x2woGA4EPtCFqeo=; b=pi68dXWM3g4T2rgfWI2/d0TY26QN9ysvzAa50frU/ZRc0pJiTXWQFLyBeJsKCNQeQFkndD DZfxbQctXcfsZN0eAeLXxLdjjRwT2JeJEUIMAl7i0xM119obGDvUZip+5Q8el5nJ6jbMGS 4YyuJJ5rt3lN6e6KKlZc6XO2/GGw/Wzwiei1ZCEi0aUIQ8KZ510sHPAVEyUCKQCaF5hkaS 6yp3PRq0cqJ1prNxmNvmnUBmBiS2blg/+Q8rFBYdg/4Qvyd60NUVUVgDBm75OHa8+LE/rn fd0kgDuUkrMr5ZKnZ3iAvf9FfWaq9YnM9OGe0Q0b6A5VtSNnwR2eRBiuAanR+g== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1651767988; a=rsa-sha256; cv=none; b=a+A7Hcj3VyfTkV1h2dh+NEcMJai/XjOv/yD/7d8Q5LqfzkpzZuHXpQFzZm40s8r20wemxt xgTRw1Qz+Krk+uJqqXTGWyh8RLVC5jcObtwGGsF02ka0Md8vQOsxyVqE86yoNfKT8VKaly pWlJL9INydAjUNotH1htqliGGDqyJg2PKqP9rtH4wAXfwGlRrwpUO/aydnrmUPzEPS7Yjv ifwuXf/SxizYvdxuxcfmwks7fbuIoOaRsaex4g3sS/TpwLevLA0RxNwoXvWltK7c+noo3L hokXucPCiqeAxZtaIETFbxXeeg+Mc4Kp0CEB46U7591KYV4cxnfPvfFDn3/ONg== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=fail ("body hash did not verify") header.d=gmail.com header.s=20210112 header.b=hLo5iWsf; dmarc=fail reason="SPF not aligned (relaxed)" header.from=gmail.com (policy=none); spf=pass (aspmx1.migadu.com: domain of "emacs-orgmode-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="emacs-orgmode-bounces+larch=yhetil.org@gnu.org" X-Migadu-Spam-Score: 5.71 Authentication-Results: aspmx1.migadu.com; dkim=fail ("body hash did not verify") header.d=gmail.com header.s=20210112 header.b=hLo5iWsf; dmarc=fail reason="SPF not aligned (relaxed)" header.from=gmail.com (policy=none); spf=pass (aspmx1.migadu.com: domain of "emacs-orgmode-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="emacs-orgmode-bounces+larch=yhetil.org@gnu.org" X-Migadu-Queue-Id: ECCA1104C4 X-Spam-Score: 5.71 X-Migadu-Scanner: scn0.migadu.com X-TUID: AH5DQ9Kgt0O2 --=-=-= Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable > [5. text/x-patch; 0004-ox-latex-Introduce-engraved-code-highlighting.patc= h]=E2=80=A6 Ooops, I had some ucommited changes. The correct version is attached. Timothy --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=0001-ox-latex-Introduce-engraved-code-highlighting.patch >From b66c291b1f0d1419742449bcde42bf0c4d620c23 Mon Sep 17 00:00:00 2001 From: TEC 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") ;;; 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 + ... + #+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 --=-=-=--