From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp1 ([2001:41d0:2:bcc0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms0.migadu.com with LMTPS id 2NdcAp1IxWALKwEAgWs5BA (envelope-from ) for ; Sun, 13 Jun 2021 01:51:57 +0200 Received: from aspmx1.migadu.com ([2001:41d0:2:bcc0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp1 with LMTPS id yEuFOZxIxWBSGwAAbx9fmQ (envelope-from ) for ; Sat, 12 Jun 2021 23:51:56 +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 41521229B8 for ; Sun, 13 Jun 2021 01:51:56 +0200 (CEST) Received: from localhost ([::1]:33328 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lsDPt-0000yK-Ux for larch@yhetil.org; Sat, 12 Jun 2021 19:51:54 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:46982) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lsDPS-0000yB-JD for emacs-orgmode@gnu.org; Sat, 12 Jun 2021 19:51:26 -0400 Received: from mout01.posteo.de ([185.67.36.65]:42273) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lsDPQ-00061u-8d for emacs-orgmode@gnu.org; Sat, 12 Jun 2021 19:51:26 -0400 Received: from submission (posteo.de [89.146.220.130]) by mout01.posteo.de (Postfix) with ESMTPS id 6C09D240026 for ; Sun, 13 Jun 2021 01:51:20 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=posteo.net; s=2017; t=1623541880; bh=+hJS4eJRGVrapzkX6EuQaHIgvnMHcuL+gYgq1TOyLVk=; h=From:To:Subject:Date:From; b=UN5oK6TFDK9q7st6bBXgB9YkF2Msr8SpLwcI0N1Se5INMIyUNjIFfjvpuRuKUv0UW p/SAbMZVpZJIGi2QwddgGb+JYJr7Ui5r+9Y6goLRECaJNZSFUCT3iBwJP5R1bbZwnD V93OPE/Vkrw2o2qWitJHmkiDNcVAnmKXLw2hovyeNmg6pPhA8CJqISxY9ViBgsj6D9 CJuk8pa+EA49A0NElEDvtW7WJCZCuVr8mTQMVhCwpm7tdzF0d9ANebhL30IFKcCkZB SuFm2IPB26cOUL9kYDVSU7eL3K6SfJy20jSGFznjKCU8C4jpTEet2DP9UdN929Fc67 VeXHOX4Hl0NUw== Received: from customer (localhost [127.0.0.1]) by submission (posteo.de) with ESMTPSA id 4G2ZHC60zZz9rxM for ; Sun, 13 Jun 2021 01:51:19 +0200 (CEST) From: =?utf-8?Q?Juan_Manuel_Mac=C3=ADas?= To: orgmode Subject: [tip] LaTeX preview of a region Date: Sat, 12 Jun 2021 23:51:18 +0000 Message-ID: <87h7i2ej61.fsf@posteo.net> MIME-Version: 1.0 Content-Type: text/plain Received-SPF: pass client-ip=185.67.36.65; envelope-from=maciaschain@posteo.net; helo=mout01.posteo.de X-Spam_score_int: -26 X-Spam_score: -2.7 X-Spam_bar: -- X-Spam_report: (-2.7 / 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, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, URIBL_SBL_A=0.1 autolearn=ham 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-Migadu-Flow: FLOW_IN ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1623541916; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type:list-id:list-help:list-unsubscribe: list-subscribe:list-post:dkim-signature; bh=aDUDUn1MH3VJO85pCBl4PYx3ZYIp3dB5HcpBk9V5R3w=; b=jcpjsVj4xu9ke8qLmY+26qObob9yOESILq+mBi7SODe0WgKB4V6hfJQqEaOMwYvmYLonJ4 T8qj4DdqjWuG/YxZWPgftUO+A+JlfuP9tDSw13sQs0ggWqYACLp7vLZugF3uPSYmk+VEy1 3G3m8yhGrrtSUbtsDnbpaxq47MUDd17u695XKUkbmdHKHtAK66dCV/t3txiq/M3Ox10hPt o5r28T+/ksJTUtDxG55z6WO2e+3/Lfob9ZpgjglMKgjMV6s9zxGD/0Iih998BcWFuAD5Fy ZzmJetfHSsjyeHOowNI6KBKCA/c3uFq44CGc+7UxqwDR+Vzwlc1diJfMH2tvCw== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1623541916; a=rsa-sha256; cv=none; b=s0d8S2+ZQAMSE9jq/cLQ6cNOymgZ+Ant/rZd1qaN2Ecs79tUCA42FpLoN91SOrQitgu6q6 bjowGG9vDSr6NJqIVcGjK0n9dM4dYWXfSdR3vZubjfVDvQ34SvES5XGTFnmhlXLm2TjibH 2bkDM8taAuT2hHM+oOlV5DqFIUAAq3x6/XIY+0CFkonnKUxbTWt2Nnzofee7BGO1RJBWk8 CNUoQ8G4imxE6NHfqPesM0PE3pdL2Q4pwp6QzeDO3KzXGUNiYcY4SuFAi1Y7awfqP89oCH SowVXkl9cGYlWCPoqqfsQwOcCLxsqLhSL7dKUfsauzDbOxvO0dvDOTDUzK/Ekw== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=pass header.d=posteo.net header.s=2017 header.b=UN5oK6TF; dmarc=pass (policy=none) header.from=posteo.net; 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-Migadu-Spam-Score: -1.13 Authentication-Results: aspmx1.migadu.com; dkim=pass header.d=posteo.net header.s=2017 header.b=UN5oK6TF; dmarc=pass (policy=none) header.from=posteo.net; 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-Migadu-Queue-Id: 41521229B8 X-Spam-Score: -1.13 X-Migadu-Scanner: scn1.migadu.com X-TUID: 5G04cDwhmXT6 Hi all, When typesetting a long book, I often need to fine tune many paragraphs (typographically speaking). So I've write this code to avoid compiling the whole document every time. The idea is activate a preview of any region of the document, compiled with all the local configuration (export filters, setup file, export options, etc.). In other words, the preview *must be identical* to the compiled/exported pdf. Although it is for a particular use case, I share it here in case it is useful to someone. My intention is to give these four variables a local value for each document or major project. But this would be the default value: #+begin_src emacs-lisp (setq my-prev/preamble "preamble.tex" my-prev/env-begin "@@latex:\\begin{dummy}@@" my-prev/env-end "@@latex:\\end{dummy}@@" my-prev/conf "#+OPTIONS: ':t\n #+LANGUAGE: es\n" #+SETUPFILE: normal.setup\n #+INCLUDE: export-filters\n") #+end_src The first variable makes sense because I always use a separate file as a preamble for large projects. The second and third variables correspond to the environment to enclose the preview (by default, a `dummmy' environment: `\newenvironment*{dummy}{}{}'). And the fourth is the configuration to export the preview. And these two functions enable or disable the preview on a region (here a sample video: https://lunotipia.juanmanuelmacias.com/images/latex-preview.mp4): #+begin_src emacs-lisp (defun my-org-latex-prev-region () (interactive) (let* ((frag (save-restriction (narrow-to-region (region-beginning) (region-end)) (buffer-string))) (my-prev/preamble-l (buffer-local-value 'my-prev/preamble (current-buffer))) (my-prev/env-begin-l (buffer-local-value 'my-prev/env-begin (current-buffer))) (my-prev/env-end-l (buffer-local-value 'my-prev/env-end (current-buffer))) (my-prev/conf-l (buffer-local-value 'my-prev/conf (current-buffer))) (org-preview-latex-default-process 'luamagick) (org-format-latex-header (concat (with-temp-buffer (insert-file-contents my-prev/preamble-l) (buffer-string)) "\n" "\\pagestyle{empty}")) (prev (with-temp-buffer (insert (concat my-prev/conf-l "\n\n" my-prev/env-begin-l "\n\n" frag "\n\n" my-prev/env-end-l)) (mark-whole-buffer) (org-latex-convert-region-to-latex) (org-latex-preview) (goto-char (point-min)) (overlay-get (car (overlays-at (point))) 'display)))) (let* ((ov (make-overlay (region-beginning) (region-end)))) (overlay-put ov 'overlay-latex-prev t) (overlay-put ov 'display prev)))) (defun my-org-latex-remove-prev-region () (interactive) (remove-overlays nil nil 'overlay-latex-prev t)) #+end_src Best regards, Juan Manuel