From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp1 ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms11 with LMTPS id 4OFoAgiqZl8mCgAA0tVLHw (envelope-from ) for ; Sun, 20 Sep 2020 01:02:00 +0000 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp1 with LMTPS id GMnkOQeqZl96ZwAAbx9fmQ (envelope-from ) for ; Sun, 20 Sep 2020 01:01:59 +0000 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 6B5109402B6 for ; Sun, 20 Sep 2020 01:01:59 +0000 (UTC) Received: from localhost ([::1]:54100 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kJnjo-0005K4-QO for larch@yhetil.org; Sat, 19 Sep 2020 21:01:56 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:48974) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kJnjN-0005Js-M5 for emacs-orgmode@gnu.org; Sat, 19 Sep 2020 21:01:29 -0400 Received: from mail-pg1-x52d.google.com ([2607:f8b0:4864:20::52d]:45144) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kJnjL-0008T6-Jz for emacs-orgmode@gnu.org; Sat, 19 Sep 2020 21:01:29 -0400 Received: by mail-pg1-x52d.google.com with SMTP id 67so5819043pgd.12 for ; Sat, 19 Sep 2020 18:01:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:user-agent:message-id:mime-version; bh=87QWpbq2pEpMeXSpkJhyvSrB3sIuQ2fN9c7Md37oUVc=; b=uUtDHmfysGSrbHU21Ovd0mrzeVn8DVmTUEIqQKj1JWLqi7EM3lUcfnyGVwAhm7H5SA PHDdfYyyCOIU6ulP9RvGXngcAYAsuPASSo+jF4JiLoK4WRmaSF/EYv1pSihcZgupyYZ3 sNOYQHXPf9C9v0fRVdDbDtB0Z1zDOTxZH8M24dygt7hxo6WfHusXCRbSvEvdjh+eZmK+ DV3Lmxp8+ZLdjxwEVl7iaRjK4tvm4D1o5ZX58uPZvduCE3rVFZauk9ngcRtngZHRPth5 7YLgCfR9WN6e/5d8UzlxkgQ/8oZfUDv3AFL+OYULcaE5ZFgZEzt4KJfe/rmQ9IBfH/xy tiaA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:user-agent:message-id :mime-version; bh=87QWpbq2pEpMeXSpkJhyvSrB3sIuQ2fN9c7Md37oUVc=; b=FipwXa8z3A/O5OMFCw47PkBtfP+PekP4S58YB0eeJ0qQ3fmM5LcJ3N+c//WEdMg7S5 dRJ+BSmK57sAsUl5+q8slaKS/TlwUvGkuW+DchNoF3HntAsoJ3bMTPDvkFT71hH2kRBD FR2R//v05zJV5cjfDRSInleS5xk3S1kqlfjK/VsJ50fLXAlU3GusF49up8UHonmpvVZ5 ZcRqZTl/JXjVD3Bfw0DHMv+BldNVEz4eFSJNllRbgtabJD/wu8dQ40XSiyIzRqoCLN5x sithAyiI4PQrwzdmtetikGAa+3xD5TU0SKiNho3dmfGF31rz1OgMjYCwzN60LmOsEiLJ NZEg== X-Gm-Message-State: AOAM530mWF0YgECEy0zaKSZLfVk9AyyW1NfNwQ4fdedd9uRgUIu6G3Fd ljKVcG9OdEOR+8Dj1BxuKwn7i72Mwaw= X-Google-Smtp-Source: ABdhPJwFO87k26ppn2AGdzTQV9PhPMwg72hAJVqXufyrJJpT0O92ipIu0a3IpIBPQU6jnELLkv8lgg== X-Received: by 2002:a62:86c3:0:b029:14e:e050:289 with SMTP id x186-20020a6286c30000b029014ee0500289mr4815503pfd.50.1600563685316; Sat, 19 Sep 2020 18:01:25 -0700 (PDT) Received: from flare-121 (c-67-160-68-187.hsd1.wa.comcast.net. [67.160.68.187]) by smtp.gmail.com with ESMTPSA id x20sm7834460pfr.190.2020.09.19.18.01.23 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sat, 19 Sep 2020 18:01:24 -0700 (PDT) From: flare To: emacs-orgmode@gnu.org Subject: [PATCH] org-preview-latex-fragment dvipng fix for packages in org-latex-packages-alist breaking 'latex' command Date: Sat, 19 Sep 2020 17:29:16 -0700 User-agent: mu4e 1.4.5; emacs 26.3 Message-ID: <87bli1gt25.fsf@gmail.com> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Received-SPF: pass client-ip=2607:f8b0:4864:20::52d; envelope-from=gabrielxaviersmith@gmail.com; helo=mail-pg1-x52d.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. X-Spam_score_int: -11 X-Spam_score: -1.2 X-Spam_bar: - X-Spam_report: (-1.2 / 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, HTML_MESSAGE=0.001, MIME_HTML_ONLY=0.1, MPART_ALT_DIFF=0.79, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-orgmode@gnu.org X-Mailman-Version: 2.1.23 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-Scanner: scn0 Authentication-Results: aspmx1.migadu.com; dkim=pass header.d=gmail.com header.s=20161025 header.b=uUtDHmfy; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (aspmx1.migadu.com: domain of emacs-orgmode-bounces@gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=emacs-orgmode-bounces@gnu.org X-Spam-Score: 1.49 X-TUID: PcMNvQuzQYxp --=-=-= Content-Type: multipart/alternative; boundary="==-=-=" --==-=-= Content-Type: text/html Content-Disposition: inline

Abstract

This is a fix for a problem regarding the org-preview-latex-fragment
function and its associated org-preview-latex-process-alist item
'dvipng,' which is broken by imported packages from
org-latex-packages-alist which are incompatible with the 'latex'
command

Context

Relevant Org-LaTex Configurations

org-latex-packages-alist

;;Latex export commands
;;(add-to-list 'org-latex-packages-alist '("" "minted"))
(add-to-list 'org-latex-packages-alist '("margin=1in" "geometry"))
(add-to-list 'org-latex-packages-alist '("" "fancyhdr"))
(add-to-list 'org-latex-packages-alist '("" "ltablex"))
(add-to-list 'org-latex-packages-alist '("" "fontspec" t ("xelatex")))
(add-to-list 'org-latex-packages-alist '("" "xcolor"))
(add-to-list 'org-latex-packages-alist '("" "multicol"))
(add-to-list 'org-latex-packages-alist '("" "xeCJK"))

LaTex Compiler

(setq org-latex-compiler "xelatex")

Overridding Keybind

This keybind is defined in the org-mode startup hook

(local-set-key (kbd "C-c C-x C-l") 'org-latex-preview-fix)

org-preview-latex Variables

(setq org-preview-latex-default-process 'dvipng)
(setq org-preview-latex-process-alist
      '(
       (dvipng
        :programs ("latex" "dvipng")
        :description "dvi > png"
        :message "you need to install the programs: latex and dvipng."
        :image-input-type "dvi"
        :image-output-type "png"
        :image-size-adjust (1.0 . 1.0)
        :latex-compiler ("latex -interaction nonstopmode -output-directory %o %f")
        :image-converter ("dvipng -D %D -T tight -o %O %f")
        )
       )
      )

Body

The alternatives to the dvipng option in the
org-preview-latex-process-alist provided less than satisfactory
results, leaving excessive whitespace within the linked image
containing mathematics. So I wanted to pursue using dvipdf.

However, dvipng does not support PDF nor XDV which are the two
formats the my LaTex compiler outputs (xelatex). So I am forced to
use the 'latex' and 'dvipng' commands within the dvipng item of the
org-preview-latex-process-alist.

This is where my fix starts to come in. When org mode does the small
export of the latex fragment it would include the contents of
org-latex-packages-alist in the LaTex headers. Some packages (namely
'fontspec,' used for xelatex) would lead to a failure to create the
dvi file when the .tex file was compiled with the necessary
'latex' command.

To alleviate this problem I designed this wrapper function which
sets org-latex-packages-alist to nil just before executing the
org-latex-preview function.

;;Latex Preview Helper Function
(defun org-latex-preview-fix (&optional ARG)
  "A wrapper function that stops org-preview from including
  packages that break latex"
  (interactive nil)
  (let ((org-latex-packages-alist . nil))
    (org-latex-preview ARG)
    )
  )

Now I can preview LaTex fragments without having org-mode yell at
more and not work.

Considerations

This fix is not perfect. For if you are using the xelatex compiler
and you wish to use dvipng (which in my opinion is the only option
in regard to inline maths, because of the 'tight' capabilities) with
maths that include Japanese, Chinese or other Unicode characters
requiring the 'fontspec' package, you will not be able to create
fragments.

This specific Issue however is on the conversion application side
however and from this point of view seems unfixable from org-mode's
standpoint.

Salutations

Either way, here is a relatively okay fix for a problem that I
encountered in my daily work.

Cheers!

Gabriel S. X. Smith

--==-=-=-- --=-=-=--