From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp12.migadu.com ([2001:41d0:403:4789::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms9.migadu.com with LMTPS id MPa2J8aD1mR7TQEASxT56A (envelope-from ) for ; Fri, 11 Aug 2023 20:53:58 +0200 Received: from aspmx1.migadu.com ([2001:41d0:403:4789::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp12.migadu.com with LMTPS id QNysJ8aD1mTFOgAAauVa8A (envelope-from ) for ; Fri, 11 Aug 2023 20:53:58 +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 454585A73A for ; Fri, 11 Aug 2023 20:53:58 +0200 (CEST) Authentication-Results: aspmx1.migadu.com; dkim=pass header.d=posteo.net header.s=2017 header.b=WSHlEAet; 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"; dmarc=pass (policy=none) header.from=posteo.net ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1691780038; 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=+aokqvoUhyKRPQyYO3rLR9/MmmTfnkOHtyzY2zZh5dM=; b=eE7vYm3qrAgno4jMBGHzbMeu8Z21b8LTIMcANvS9Yj7k5nUQ4T0bndvDpQY4f7e2Xp3pRh hOcPXUAHu4lbIT2imhcFbbV5y7i+GhZzmG1QhCZpVbyLDnwN1y7bAebRuBAOppjCDwjU6n DJcffSq+HsBK26ibg+bdp0HdcWAmKGaW41MiYh2wfsDJBIelCKMkOcQpmQmDnTNctZW1eG b43DxfQQHE32Sf6eAeyMOSH2MkC5z0ISRni2DWqh3GYu1HAohBvfe65siY6K9SeEX4KDBM SGDme356EqWwBKFPS26tRRlbxvIzpf8sGSvykPKqd72d1eef6naf0z89TJFWHA== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=pass header.d=posteo.net header.s=2017 header.b=WSHlEAet; 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"; dmarc=pass (policy=none) header.from=posteo.net ARC-Seal: i=1; s=key1; d=yhetil.org; t=1691780038; a=rsa-sha256; cv=none; b=EVeVNhDQfvaU+e/HRY/pSwoYbyyKJ+rTqp2CS9pyVncB5L2QOrNWX/E9b2dFvjW+bgr0Os dx7ZrKzVeSdTOS6M/8eTFj8Yq26MQWk+0OzgzlrGih867rCrlBJ3TJiiNxVpQXMzRba359 6d4c2ZR2Hpc71seVrtcKnWE8NtwXD2hVaDWgpKyP/5x+T+RI+z9/RMbjWiH/3I989GBvr2 zImxnjm9NCd5RheLmMzlv59PzQjQPX69x6UjpTx5kxtMZxzTHljC/+/dol84rMvSUOW9iI 8gZ29zkQJWBbN35rBvamsGePrOz9Qyx3jinzFc8+CbhqgtHgNuDFr0qtmVh+Dg== Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qUXFs-0004cV-Dd; Fri, 11 Aug 2023 14:53:00 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qUXFo-0004bu-AY for emacs-orgmode@gnu.org; Fri, 11 Aug 2023 14:52:56 -0400 Received: from mout01.posteo.de ([185.67.36.65]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qUXFk-0000ee-13 for emacs-orgmode@gnu.org; Fri, 11 Aug 2023 14:52:54 -0400 Received: from submission (posteo.de [185.67.36.169]) by mout01.posteo.de (Postfix) with ESMTPS id EF7E6240027 for ; Fri, 11 Aug 2023 20:52:48 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=posteo.net; s=2017; t=1691779969; bh=313YhP7xgAmboTFKOH9Dy/jLZnedvLBm53qX1FpM3sY=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version:From; b=WSHlEAetgVUs6pa3IIwW527GUCCddGKCd/YWjwXKt6xQiZnNbURslwz1gCx7QlEwS +xAx9GZm6DHQxtpUyvjgKvhnIFyycZ1kkUAM00Cu+S9ksJ0kFmd9NX8BH9oDcCbHgY hnypTzpzmJWlhZOvE1STolfwH243zG3mlXzDWZVvTOSSKg5hHO/ein/L6Zg1Za8HdV 2n94cvnWLaEgd+8AmxkGfOxjhy27mqqM4WNfKX8nWRejHVr7HFkf+TGdJs7wJJO0AN JQwYiMGDrBMozdNuQRJba4hNuWl1yj085pi2F6OQhb7IO+poxhpUfvFXO5Mxw9S/0Q N0QCuQgyUC7TQ== Received: from customer (localhost [127.0.0.1]) by submission (posteo.de) with ESMTPSA id 4RMtG83MCLz6tw4; Fri, 11 Aug 2023 20:52:48 +0200 (CEST) From: =?utf-8?Q?Juan_Manuel_Mac=C3=ADas?= To: Ihor Radchenko Cc: orgmode Subject: Re: [patch] ox-latex.el: fix blank lines behavior in verse block In-Reply-To: <874jl5526t.fsf@localhost> (Ihor Radchenko's message of "Fri, 11 Aug 2023 10:00:10 +0000") References: <87tttcml75.fsf@posteo.net> <87edkf6px1.fsf@localhost> <87350ug413.fsf@posteo.net> <87o7jgejhl.fsf@localhost> <87pm3wfvzx.fsf@posteo.net> <87il9nb62q.fsf@localhost> <871qgbb2q6.fsf@posteo.net> <874jl5526t.fsf@localhost> Date: Fri, 11 Aug 2023 18:52:46 +0000 Message-ID: <87ttt59zsx.fsf@posteo.net> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Received-SPF: pass client-ip=185.67.36.65; envelope-from=maciaschain@posteo.net; helo=mout01.posteo.de X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 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_MED=-2.3, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 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-bounces+larch=yhetil.org@gnu.org X-Migadu-Flow: FLOW_IN X-Migadu-Country: US X-Migadu-Queue-Id: 454585A73A X-Migadu-Scanner: mx1.migadu.com X-Spam-Score: -9.87 X-Migadu-Spam-Score: -9.87 X-TUID: yHFWBPsUslm2 --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Ihor Radchenko writes: > Juan Manuel Mac=C3=ADas writes: > >> ... In any case, the fact that the verse block can also be used to >> literally export line breaks and horizontal/vertical spaces is >> interesting. Something occurred to me that I don't know if it's a bit >> foolhardy: how about a LaTeX attribute ':literal t'? If used, it would >> not export to a verse environment (specialized in poetry) but to normal >> text, without environment, but with line breaks and horizontal and >> vertical spacing preserved... wdyt? > > If one uses verse blocks to export to multiple backends, your suggestion > sounds reasonable. That way, export results will look closer across > different export backends. How about this (pre-)patch? With the `:literal' attr., the content of the block is exported "as is", with all manual formatting preserved. I have made some modifications in the horizontal and vertical spaces (in case :literal is used), because the em does not seem the correct length to me. The em equals the font size in points, and, vertically, it would not equal a blank line (line spacing is usually 120% of the em), so it's safest to use \baselineskip. Thus, \vspace*{\baselineskip} is identical to leaving an empty line. As for the horizontal space, the em is greater than the normal space. The closest thing would be to use \fontdimen2\font. So, if one puts 6 manual spaces (with the spacebar key), it is exported as \hspace*{6\fontdimen2\font} --=20 Juan Manuel Mac=C3=ADas https://juanmanuelmacias.com https://lunotipia.juanmanuelmacias.com https://gnutas.juanmanuelmacias.com --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=0001-lisp-ox-latex.el-add-the-literal-attribute-to-verse-.patch >From baf9cc50313bb7df94e8173349db9c834f1ccf64 Mon Sep 17 00:00:00 2001 From: Juan Manuel Macias Date: Fri, 11 Aug 2023 19:57:49 +0200 Subject: [PATCH] lisp/ox-latex.el: add the `:literal' attribute to verse block. * (org-latex-verse-block): now the treatment of blank lines is consistent with the syntax of the LaTeX `verse' environment, and the one provided by the `verse' package. If the `':literal attribute is used, the content is not exported within a `verse' environment, but as-is, preserving horizontal spaces, line breaks, and blank lines. --- lisp/ox-latex.el | 52 ++++++++++++++++++++++++++++++++++++------------ 1 file changed, 39 insertions(+), 13 deletions(-) diff --git a/lisp/ox-latex.el b/lisp/ox-latex.el index 31cad1dc4..557ceee1b 100644 --- a/lisp/ox-latex.el +++ b/lisp/ox-latex.el @@ -4116,32 +4116,58 @@ contextual information." (let* ((lin (org-export-read-attribute :attr_latex verse-block :lines)) (latcode (org-export-read-attribute :attr_latex verse-block :latexcode)) (cent (org-export-read-attribute :attr_latex verse-block :center)) - (attr (concat - (if cent "[\\versewidth]" "") - (if lin (format "\n\\poemlines{%s}" lin) "") - (if latcode (format "\n%s" latcode) ""))) + (lit (org-export-read-attribute :attr_latex verse-block :literal)) + (attr (if (not lit) + (concat + (if cent "[\\versewidth]" "") + (if lin (format "\n\\poemlines{%s}" lin) "") + (if latcode (format "\n%s" latcode) "")) + "")) (versewidth (org-export-read-attribute :attr_latex verse-block :versewidth)) - (vwidth (if versewidth (format "\\settowidth{\\versewidth}{%s}\n" versewidth) "")) - (linreset (if lin "\n\\poemlines{0}" ""))) + (vwidth (if (not lit) + (if versewidth (format "\\settowidth{\\versewidth}{%s}\n" versewidth) "") + "")) + (linreset (if (not lit) + (if lin "\n\\poemlines{0}" "") + ""))) (concat (org-latex--wrap-label verse-block ;; In a verse environment, add a line break to each newline ;; character and change each white space at beginning of a line - ;; into a space of 1 em. Also change each blank line with - ;; a vertical space of 1 em. - (format "%s\\begin{verse}%s\n%s\\end{verse}%s" + ;; into a normal space, calculated with `\fontdimen2\font'. + ;; One or more blank lines between lines are exported as a + ;; single blank line. If the `:literal' attribute is used, + ;; CONTENTS is exported as is, with no environment, preserving + ;; line breaks and vertical and horizontal spaces. + (format (if (not lit) + "%s\\begin{verse}%s\n%s\\end{verse}%s" + "%s%s\n%s%s") vwidth attr (replace-regexp-in-string - "^[ \t]+" (lambda (m) (format "\\hspace*{%dem}" (length m))) + "^[ \t]+" (lambda (m) (format "\\hspace*{%d\\fontdimen2\\font}" (length m))) (replace-regexp-in-string - (concat "^[ \t]*" (regexp-quote org-latex-line-break-safe) "$") - "\\vspace*{1em}" + (if (not lit) + (concat "\\(" + (regexp-quote org-latex-line-break-safe) + "\n\\)" + "\\(^[ \t]*" + (regexp-quote org-latex-line-break-safe) + "\n" + "\\)+") + (concat "^[ \t]*" (regexp-quote org-latex-line-break-safe) "$")) + (if (not lit) + (if lin "\\\\!\n\n" "\n\n") + "\\vspace*{\\baselineskip}") (replace-regexp-in-string "\\([ \t]*\\\\\\\\\\)?[ \t]*\n" (concat org-latex-line-break-safe "\n") - contents nil t) + (if (not lit) + ;; Remove any blank lines before and after CONTENTS. + (concat (org-trim contents t) "\n") + contents) + nil t) nil t) nil t) linreset) -- 2.41.0 --=-=-=--