Function: org-latex-src-block--engraved

org-latex-src-block--engraved is a byte-compiled function defined in ox-latex.el.gz.

Signature

(org-latex-src-block--engraved &key SRC-BLOCK INFO LANG CAPTION CAPTION-ABOVE-P NUM-START RETAIN-LABELS ATTRIBUTES FLOAT &allow-other-keys)

Documentation

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.

Source Code

;; Defined in /usr/src/emacs/lisp/org/ox-latex.el.gz
(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'."
  (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
           ((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)
            (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)))
            (append
             (when (and num-start (not (assoc "linenos" engraved-options)))
               `(("linenos")
                 ("firstnumber" ,(number-to-string (1+ num-start)))))
             (and local-options `((,local-options))))))
         (engraved-theme (plist-get attributes :engraved-theme))
         (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
          (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))))