From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp1 ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms0.migadu.com with LMTPS id 0CLOEd8RvWAv2QAAgWs5BA (envelope-from ) for ; Sun, 06 Jun 2021 20:20:15 +0200 Received: from aspmx1.migadu.com ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp1 with LMTPS id RXcXDd8RvWCTLgAAbx9fmQ (envelope-from ) for ; Sun, 06 Jun 2021 18:20:15 +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 AFF8F14646 for ; Sun, 6 Jun 2021 20:20:14 +0200 (CEST) Received: from localhost ([::1]:41566 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lpxNd-0007hT-3M for larch@yhetil.org; Sun, 06 Jun 2021 14:20:13 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:53650) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lpxNG-0007hB-RX for emacs-orgmode@gnu.org; Sun, 06 Jun 2021 14:19:50 -0400 Received: from mail-pj1-x1035.google.com ([2607:f8b0:4864:20::1035]:44897) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lpxNE-00040U-VW for emacs-orgmode@gnu.org; Sun, 06 Jun 2021 14:19:50 -0400 Received: by mail-pj1-x1035.google.com with SMTP id h12-20020a17090aa88cb029016400fd8ad8so8988628pjq.3 for ; Sun, 06 Jun 2021 11:19:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=user-agent:from:to:subject:message-id:date:mime-version; bh=L8ArYbUa7b06OSvPUVrn/E6VdOfslPz4YdjflCi04lw=; b=V3Zk+1LHchFUE9PoziPBi6ZEC+KXDqx5tvnzToDzCjhAsqUa/b658EkRfixX9c8HqW zvUa7WfinbCivLsV+Xys9prDvORhH+b7xIAC/A2OmGYH7fs0gJXJPBhzC3GOMdbpjItq 8p5Hi4KACgMTf1PDTcVmrPtBCWhjKfPb/tSOwsHxN0yk6LN0bB4vOMqPufO/lVRR1JvI O8tMLpQ9dTbjjYOZv+5SDaBoeLvB45vcsgEbySYjYNuYiy1nNZR7RCX3brhm0JSKa0Tg YdFrnlljlcJLSzt14BD96rKvd1MFXtNUaazdpvVgtKHcoxtIASWvMWyUwFKiQZ0N2I4H XW5w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:user-agent:from:to:subject:message-id:date :mime-version; bh=L8ArYbUa7b06OSvPUVrn/E6VdOfslPz4YdjflCi04lw=; b=PRGbiulVqFTVNuvmsJLPkyT6n8LfjYmr+21GYPcvY++YP5Z7sQFEKaC08Ha0cQoB9Y oGT2DJLyTrYBEdgDiIy+Pnwtrs3+2xrjicXRqNSt/LRcD/iTyAgvqRRr8WJhsXa2+LAa KG8U9BADd8aZ/4xBlYeDKdRgvXUKsEnffW/8IL/f1T7I7VYrLq9n4rChvpJFX013Kht7 JR52FFfk27amzCPHZHIP9wxdA3quJxrLZtC0lU33qR7ixecxQ4McVnH5kZt5Qz+U9I0e JU+BcDUyPBwOpONIGfljsXpd5Fup4VjEjFaWH8dPQRXHvHSDe8miVcWFcfmPk6trbPL6 52bw== X-Gm-Message-State: AOAM531nPrO7rsZAVs2WaXM9Iv/Q2QNLJBBKAOcPN7Qyf6sCwwt8Th8V ysS9ZWN1fHp+kOd0cRi9H8dEX47m1ng= X-Google-Smtp-Source: ABdhPJxZTTo0Oamp0z+ONfPAq/wu5tjXXLlnE5z5DS0265LAtZQVBPgmwCJI3jjd3Og2LHg0hhX83Q== X-Received: by 2002:a17:902:b616:b029:ee:c73b:163d with SMTP id b22-20020a170902b616b02900eec73b163dmr14315439pls.30.1623003586895; Sun, 06 Jun 2021 11:19:46 -0700 (PDT) Received: from localhost (180-150-91-8.b4965b.per.nbn.aussiebb.net. [180.150.91.8]) by smtp.gmail.com with ESMTPSA id fw16sm8578003pjb.30.2021.06.06.11.19.45 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 06 Jun 2021 11:19:46 -0700 (PDT) User-agent: mu4e 1.4.15; emacs 28.0.50 From: Timothy To: org-mode-email Subject: [PATCH] Allow LaTeX reference command (\ref) to be customised Message-ID: <87mts25000.fsf@gmail.com> Date: Mon, 07 Jun 2021 02:19:43 +0800 MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Received-SPF: pass client-ip=2607:f8b0:4864:20::1035; envelope-from=tecosaur@gmail.com; helo=mail-pj1-x1035.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 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=1623003614; 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=L8ArYbUa7b06OSvPUVrn/E6VdOfslPz4YdjflCi04lw=; b=gsLlfh1KOyq9NyDza2VIE/RS1MF1USLX+dfl66NBkvFIz1+Mmp3EacC7UrKYBCM/+m4a7+ zfiPq15COp4pLsIpoHbAHVxEWD8nfOQVq757Qz9CDH352AvGtz8LDJ2aIIjF4//WuaOg7J hedBRX497RiVvQoLJGvxgs2erqWlIxVoW2je+Wb93Gvpk+b84fntLY6s9/IHGnRUGDwEgX PQ/1bv7pUk+Mxixdj5Ad0CCVootmJMF2Dru7EPGRrd+neGOPVT9u5Lyirn52XUOI96lZyq YhrJDhNi+Z4Hs9BqZCc+08FmdsobXY5cdMuwV8299t7aIDkuao62z5uGfM7DfA== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1623003614; a=rsa-sha256; cv=none; b=ne5cwk6gZR5eMGgi98LfnnMvWKTWZhGgCheHsu57g4xb9vzqlxjLDtc2dk5SnpkDg2u9AR 7G59wDrBBAnUe5o2MvjDNLItoE06pLIl7nb7C+57iGp1cJVuIzoZhWZCs+ZhLeHGo1674F SDhW9FFZPSjNycAmsHAED+FrjJ7fJw818QZsiqJRTW0iJc0ONB8W5B/6DlZ3a9IQWwrl8C UOnEafqkZ8c3RcnENu8atM0h25UB3ct4mEYW1MUxIs0xhG1kBV+kdphAtZc7Y8dPAZnT+2 aBB3u8I1EHqA8EXzRgiEYvYobRPfovAj5CdhLwxOhCAIPE26TaoxbkVHJuOvwA== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=pass header.d=gmail.com header.s=20161025 header.b=V3Zk+1LH; 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-Migadu-Spam-Score: -3.13 Authentication-Results: aspmx1.migadu.com; dkim=pass header.d=gmail.com header.s=20161025 header.b=V3Zk+1LH; 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-Migadu-Queue-Id: AFF8F14646 X-Spam-Score: -3.13 X-Migadu-Scanner: scn0.migadu.com X-TUID: Qg8c8NQa0CRg --=-=-= Content-Type: text/plain Hi All, I've started doing some more cross-referencing in documents exported to LaTeX, and a hardcoded use of \ref has begun to stand out to me as a rather annoying thing. Hypperef provides \autoref for adding helpful prefixes (section, figure, etc.), and there are other packages which one may want to use to generate 'clever' references (like cleveref with \cref). As such, I think that the hardcoded \ref should actually be turned into a customisable format string, which is what the attached patch does. -- Timothy --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=0001-ox-latex-Allow-reference-command-to-be-customised.patch >From db01398de3a29043dbb545ee66006b0b7c0f1368 Mon Sep 17 00:00:00 2001 From: TEC Date: Mon, 7 Jun 2021 02:13:18 +0800 Subject: [PATCH] ox-latex: Allow reference command to be customised * lisp/ox-latex.el (org-latex-reference-command): Create a new variable so the user may modify the reference command used. (org-latex-link): Make use of the new `org-latex-reference-command' when generating references for labels without a description (previously using \ref). (org-latex-prefer-user-labels): Mention the new `org-latex-reference-command' when describing the generated LaTeX referencing labels. --- lisp/ox-latex.el | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/lisp/ox-latex.el b/lisp/ox-latex.el index c761cfd7f..940800750 100644 --- a/lisp/ox-latex.el +++ b/lisp/ox-latex.el @@ -381,6 +381,9 @@ (defcustom org-latex-prefer-user-labels nil This is section \\ref{sec:foo}. And this is still section \\ref{sec:foo}. +A non-default value of `org-latex-reference-command' will change the +command (\\ref by default) used to create label references. + Note, however, that setting this variable introduces a limitation on the possible values for CUSTOM_ID and NAME. When this variable is non-nil, Org passes their value to \\label unchanged. @@ -400,6 +403,18 @@ (defcustom org-latex-prefer-user-labels nil :version "26.1" :package-version '(Org . "8.3")) +(defcustom org-latex-reference-command "\\ref{%s}" + "Format string that takes a reference to produce a LaTeX reference command. + +The reference is a label such as sec:intro. A format string of \"\\ref{%s}\" +produces numbered references and will always work. It may be desirable to make +use of a package such as hyperref or cleveref and then change the format string +to \"\\autoref{%s}\" or \"\\cref{%s}\" for example." + :group 'org-export-latex + :type 'string + :version "28.1" + :package-version '(Org . "9.5")) + ;;;; Preamble (defcustom org-latex-default-class "article" @@ -2608,7 +2623,7 @@ (defun org-latex-link (link desc info) (let ((label (org-latex--label destination info t))) (if (and (not desc) (org-export-numbered-headline-p destination info)) - (format "\\ref{%s}" label) + (format org-latex-reference-command label) (format "\\hyperref[%s]{%s}" label (or desc (org-export-data @@ -2616,7 +2631,7 @@ (defun org-latex-link (link desc info) ;; Fuzzy link points to a target. Do as above. (otherwise (let ((ref (org-latex--label destination info t))) - (if (not desc) (format "\\ref{%s}" ref) + (if (not desc) (format org-latex-reference-command ref) (format "\\hyperref[%s]{%s}" ref desc))))))) ;; Coderef: replace link with the reference name or the ;; equivalent line number. -- 2.31.1 --=-=-=--