emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* Bug: Exporting internal link to special latex block [9.3.7 (9.3.7-14-gb2b587-elpa @ /home/lobo/.emacs.d/elpa/org-20200720/)]
@ 2020-07-21 13:52 Marco Falconi
  2020-08-04  6:41 ` Eric S Fraga
  2020-09-05 10:28 ` Bastien
  0 siblings, 2 replies; 9+ messages in thread
From: Marco Falconi @ 2020-07-21 13:52 UTC (permalink / raw)
  To: emacs-orgmode


I am trying to export to html a labeled latex special block (a theorem
environment, defined by #+begin_theorem [...] #+end_theorem ). I have named the theorem with
#+NAME: thm:mv (I also tried with #+LABEL: and the behavior described below does not change).

I have a link to such block later in the body, in the form [[thm:mv]]. The link works
perfectly in the org file, however it is exported incorrectly to html.

In fact, while the theorem environment gets exported in the html as

   <div class="theorem" id="thm:mv">
   <p>
   [...]
   </p>
   </div>

,

the link does not href to "#thm:mv" as expected, but to an auto-generated label:

    <p>
    <a href="#orgd9d024a">1</a>
    </p>

I have tried to play around a bit with export options, but to no avail.

Is this a known bug?

Best regards,
_____
Marco

------------------------------------------------------------------------

Emacs  : GNU Emacs 26.3 (build 1, x86_64-pc-linux-gnu, GTK+ Version 3.24.20)
 of 2020-05-19
Package: Org mode version 9.3.7 (9.3.7-14-gb2b587-elpa @ /home/lobo/.emacs.d/elpa/org-20200720/)

current state:
==============
(setq
 org-src-mode-hook '(org-src-babel-configure-edit-buffer org-src-mode-configure-edit-buffer)
 org-link-shell-confirm-function 'yes-or-no-p
 org-metadown-hook '(org-babel-pop-to-session-maybe)
 org-export-date-timestamp-format "%B %d, %Y"
 org-clock-out-hook '(org-clock-remove-empty-clock-drawer)
 org-html-format-inlinetask-function 'org-html-format-inlinetask-default-function
 org-latex-subtitle-separate t
 org-pretty-entities t
 org-latex-default-packages-alist '(("AUTO" "inputenc" t ("pdflatex" "latex")) ("" "fontspec" nil ("xelatex" "lualatex")) ("" "amssymb" t nil)
				    ("" "amsmath" t nil) ("" "amsthm" nil nil) ("" "amscd" t nil) ("" "amsfonts" t nil)
				    ("" "unicode-math" nil ("xelatex" "lualatex")) ("" "graphicx" t nil) ("" "grffile" t nil)
				    ("" "wrapfig" nil nil) ("" "rotating" nil nil) ("normalem" "ulem" t nil) ("" "textcomp" t nil)
				    ("" "capt-of" nil nil) ("" "longtable" nil nil))
 org-odt-format-headline-function 'org-odt-format-headline-default-function
 org-agenda-files '("~/home.org" "~/postdoc/work.org")
 org-ascii-format-inlinetask-function 'org-ascii-format-inlinetask-default
 org-reveal-start-hook '(org-decrypt-entry)
 org-format-latex-header "\\documentclass[leqno]{article}\n\\usepackage[usenames]{color}\n[PACKAGES]\n[DEFAULT-PACKAGES]\n\\pagestyle{empty}             % do not remove\n% The settings below are copied from fullpage.sty\n\\setlength{\\textwidth}{\\paperwidth}\n\\addtolength{\\textwidth}{-3cm}\n\\setlength{\\oddsidemargin}{1.5cm}\n\\addtolength{\\oddsidemargin}{-2.54cm}\n\\setlength{\\evensidemargin}{\\oddsidemargin}\n\\setlength{\\textheight}{\\paperheight}\n\\addtolength{\\textheight}{-\\headheight}\n\\addtolength{\\textheight}{-\\headsep}\n\\addtolength{\\textheight}{-\\footskip}\n\\addtolength{\\textheight}{-3cm}\n\\setlength{\\topmargin}{1.5cm}\n\\addtolength{\\topmargin}{-2.54cm}"
 org-mode-hook '((lambda nil (local-set-key (kbd "C-l C-e") (function LaTeX-environment))) turn-on-visual-line-mode
		 my/org-include-img-from-pdf-before-save (lambda nil (org-bullets-mode 1))
		 #[0 "\301\211\207" [imenu-create-index-function org-imenu-get-tree] 2]
		 (lambda nil (local-set-key (kbd "C-c p") (function mail-org-preamble))) smartparens-mode (lambda nil (setq fill-column 95))
		 #[0 "\300\301\302\303\304$\207" [add-hook before-save-hook org-encrypt-entries nil t] 5] turn-off-auto-fill
		 org-display-inline-images turn-on-org-cdlatex
		 #[0 "\300\301\302\303\304$\207" [add-hook change-major-mode-hook org-show-all append local] 5]
		 #[0 "\300\301\302\303\304$\207" [add-hook change-major-mode-hook org-babel-show-result-all append local] 5]
		 org-babel-result-hide-spec org-babel-hide-all-hashes)
 org-export-with-smart-quotes t
 org-odt-format-drawer-function #[514 "\207" [] 3 "\n\n(fn NAME CONTENTS)"]
 org-archive-hook '(org-attach-archive-delete-maybe)
 org-agenda-restore-windows-after-quit t
 org-confirm-elisp-link-function 'yes-or-no-p
 org-agenda-before-write-hook '(org-agenda-add-entry-text)
 org-preview-latex-default-process 'dvisvgm
 org-metaup-hook '(org-babel-load-in-session-maybe)
 org-startup-with-latex-preview t
 org-bibtex-headline-format-function #[257 "\300\236A\207" [:title] 3 "\n\n(fn ENTRY)"]
 org-latex-format-drawer-function #[514 "\207" [] 3 "\n\n(fn _ CONTENTS)"]
 org-agenda-deadline-faces '((1.0 . org-warning) (0.5 . org-upcoming-deadline) (0.0 . org-agenda-calendar-event))
 org-crypt-key nil
 org-babel-pre-tangle-hook '(save-buffer)
 org-latex-compiler "xelatex"
 org-tab-first-hook '(org-babel-hide-result-toggle-maybe org-babel-header-arg-expand)
 org-agenda-skip-deadline-prewarning-if-scheduled 3
 org-highlight-latex-and-related '(native entities)
 org-ascii-format-drawer-function #[771 "\207" [] 4 "\n\n(fn NAME CONTENTS WIDTH)"]
 org-occur-hook '(org-first-headline-recenter)
 outline-minor-mode-hook '((lambda nil (require (quote outline-magic)) (define-key outline-minor-mode-map [(f11)] (quote outline-cycle))))
 org-agenda-window-setup 'only-window
 org-agenda-include-diary t
 org-structure-template-alist '(("a" . "export ascii") ("c" . "center") ("C" . "comment") ("e" . "example") ("E" . "export")
				("h" . "export html") ("L" . "export latex") ("q" . "quote") ("s" . "src") ("v" . "verse") ("t" . "theorem")
				("l" . "lemma") ("p" . "proposition") ("k" . "corollary") ("d" . "definition") ("r" . "remark"))
 org-cycle-hook '(org-cycle-hide-archived-subtrees org-cycle-show-empty-lines org-optimize-window-after-visibility-change)
 org-support-shift-select t
 org-speed-command-hook '(org-speed-command-activate org-babel-speed-command-activate)
 org-tags-column -130
 org-odt-format-inlinetask-function 'org-odt-format-inlinetask-default-function
 org-agenda-window-frame-fractions '(0.2 . 0.9)
 org-return-follows-link 1
 org-format-latex-options '(:foreground default :background default :scale 2 :html-foreground "Blue" :html-background "Transparent" :html-scale
			    1.5 :matchers ("begin" "$1" "$" "$$" "\\(" "\\["))
 org-latex-subtitle-format "\\dedicatory{%s}"
 org-confirm-shell-link-function 'yes-or-no-p
 org-link-parameters '(("attachment" :follow org-attach-open-link :export org-attach-export-link :complete org-attach-complete-link)
		       ("id" :follow org-id-open) ("eww" :follow eww :store org-eww-store-link)
		       ("rmail" :follow org-rmail-open :store org-rmail-store-link) ("mhe" :follow org-mhe-open :store org-mhe-store-link)
		       ("irc" :follow org-irc-visit :store org-irc-store-link :export org-irc-export)
		       ("info" :follow org-info-open :export org-info-export :store org-info-store-link)
		       ("gnus" :follow org-gnus-open :store org-gnus-store-link)
		       ("docview" :follow org-docview-open :export org-docview-export :store org-docview-store-link)
		       ("bibtex" :follow org-bibtex-open :store org-bibtex-store-link)
		       ("bbdb" :follow org-bbdb-open :export org-bbdb-export :complete org-bbdb-complete-link :store org-bbdb-store-link)
		       ("w3m" :store org-w3m-store-link) ("mu4e" :follow mu4e-org-open :store mu4e-org-store-link)
		       ("elfeed" :follow elfeed-link-open :store elfeed-link-store-link) ("file+sys") ("file+emacs")
		       ("shell" :follow org-link--open-shell)
		       ("news" :follow #[257 "\301\300\302Q!\207" ["news" browse-url ":"] 5 "\n\n(fn URL)"])
		       ("mailto" :follow #[257 "\301\300\302Q!\207" ["mailto" browse-url ":"] 5 "\n\n(fn URL)"])
		       ("https" :follow #[257 "\301\300\302Q!\207" ["https" browse-url ":"] 5 "\n\n(fn URL)"])
		       ("http" :follow #[257 "\301\300\302Q!\207" ["http" browse-url ":"] 5 "\n\n(fn URL)"])
		       ("ftp" :follow #[257 "\301\300\302Q!\207" ["ftp" browse-url ":"] 5 "\n\n(fn URL)"])
		       ("help" :follow org-link--open-help) ("file" :complete org-link-complete-file) ("elisp" :follow org-link--open-elisp)
		       ("doi" :follow org-link--open-doi))
 org-latex-format-headline-function 'org-latex-format-headline-colored-keywords-function
 org-link-elisp-confirm-function 'yes-or-no-p
 org-latex-format-inlinetask-function 'org-latex-format-inlinetask-default-function
 org-html-format-drawer-function #[514 "\207" [] 3 "\n\n(fn NAME CONTENTS)"]
 org-latex-caption-above nil
 org-latex-packages-alist '(("dvipsnames" "xcolor" t) ("" "dsfont" t) ("unicode,psdextra" "hyperref" t)
			    "\\hypersetup{pdfborder={0 0 0.06},citebordercolor=[rgb]{0.8196,0.2275,0.5098},linkbordercolor=[rgb]{0.1765,0.5490,0.8118},urlbordercolor=[rgb]{0.7059,0.5333,0.1137}}"
			    ("" "tikz-cd" t) ("" "enumitem" nil) ("" "setspace" nil) ("font={scriptsize,bf}" "caption" nil)
			    ("" "changepage" nil) ("" "booktabs" nil) ("" "csquotes" nil))
 outline-structedit-modifiers '(meta shift)
 org-latex-classes '(("article" "\\documentclass[11pt]{article}" ("\\section{%s}" . "\\section*{%s}") ("\\subsection{%s}" . "\\subsection*{%s}")
		      ("\\subsubsection{%s}" . "\\subsubsection*{%s}") ("\\paragraph{%s}" . "\\paragraph*{%s}")
		      ("\\subparagraph{%s}" . "\\subparagraph*{%s}"))
		     ("report" "\\documentclass[11pt]{report}" ("\\part{%s}" . "\\part*{%s}") ("\\chapter{%s}" . "\\chapter*{%s}")
		      ("\\section{%s}" . "\\section*{%s}") ("\\subsection{%s}" . "\\subsection*{%s}")
		      ("\\subsubsection{%s}" . "\\subsubsection*{%s}"))
		     ("book" "\\documentclass[11pt]{book}" ("\\part{%s}" . "\\part*{%s}") ("\\chapter{%s}" . "\\chapter*{%s}")
		      ("\\section{%s}" . "\\section*{%s}") ("\\subsection{%s}" . "\\subsection*{%s}")
		      ("\\subsubsection{%s}" . "\\subsubsection*{%s}"))
		     ("amsart" "\\documentclass{amsart}" ("\\section{%s}" . "\\section*{%s}") ("\\subsection{%s}" . "\\subsection*{%s}")
		      ("\\subsubsection{%s}" . "\\subsubsection*{%s}") ("\\paragraph{%s}" . "\\paragraph*{%s}")
		      ("\\subparagraph{%s}" . "\\subparagraph*{%s}"))
		     )
 org-html-format-headline-function 'org-html-format-headline-default-function
 org-pretty-entities-include-sub-superscripts nil
 org-link-from-user-regexp "\\<marco\\.falconi@gmail\\.com\\>\\|\\<Marco Falconi\\>"
 org-html-postamble-format '(("en"
			      "<p class=\"author\">Author: %a (%e)</p>\n<p class=\"date\">%d</p>\n<p class=\"creator\">%c</p>\n<p class=\"validation\">%v</p>")
			     )
 org-publish-project-alist '(("orgfiles" :base-directory "~/website/org_files/" :base-extension "org" :publishing-directory
			      "~/website/html_files/" :recursive t :auto-sitemap t :publishing-function org-html-publish-to-html)
			     ("attachments" :base-directory "~/website/org_files/" :base-extension "jpg\\|gif\\|png\\|css\\|el\\|bib\\|pdf"
			      :publishing-directory "~/website/html_files/" :recursive t :publishing-function org-publish-attachment)
			     ("website" :components ("orgfiles" "attachments"))
			     ("orgfilestemp" :base-directory "~/website/temp/org/" :base-extension "org" :publishing-directory
			      "~/website/temp/html/" :recursive t :auto-sitemap t :publishing-function org-html-publish-to-html)
			     ("attachmentstemp" :base-directory "~/website/temp/org/" :base-extension "jpg\\|gif\\|png\\|css\\|el\\|bib\\|pdf"
			      :publishing-directory "~/website/temp/html/" :recursive t :publishing-function org-publish-attachment)
			     ("tempwebsite" :components ("orgfilestemp" "attachmentstemp")))
 org-tags-exclude-from-inheritance '("crypt")
 org-html-validation-link ""
 )


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Bug: Exporting internal link to special latex block [9.3.7 (9.3.7-14-gb2b587-elpa @ /home/lobo/.emacs.d/elpa/org-20200720/)]
  2020-07-21 13:52 Bug: Exporting internal link to special latex block [9.3.7 (9.3.7-14-gb2b587-elpa @ /home/lobo/.emacs.d/elpa/org-20200720/)] Marco Falconi
@ 2020-08-04  6:41 ` Eric S Fraga
  2021-04-18 15:42   ` Nicolas Goaziou
  2020-09-05 10:28 ` Bastien
  1 sibling, 1 reply; 9+ messages in thread
From: Eric S Fraga @ 2020-08-04  6:41 UTC (permalink / raw)
  To: Marco Falconi; +Cc: emacs-orgmode

On Tuesday, 21 Jul 2020 at 15:52, Marco Falconi wrote:
> I am trying to export to html a labeled latex special block (a theorem
> environment,

[...]

> the link does not href to "#thm:mv" as expected, but to an auto-generated label:

Confirmed with org from git a few minutes ago.  The link using an
auto-generated label would be fine if the label were the one for the
special block but it's not.

-- 
: Eric S Fraga via Emacs 28.0.50, Org release_9.3.7-682-geac255


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Bug: Exporting internal link to special latex block [9.3.7 (9.3.7-14-gb2b587-elpa @ /home/lobo/.emacs.d/elpa/org-20200720/)]
  2020-07-21 13:52 Bug: Exporting internal link to special latex block [9.3.7 (9.3.7-14-gb2b587-elpa @ /home/lobo/.emacs.d/elpa/org-20200720/)] Marco Falconi
  2020-08-04  6:41 ` Eric S Fraga
@ 2020-09-05 10:28 ` Bastien
  2020-09-05 10:56   ` Marco Falconi
  1 sibling, 1 reply; 9+ messages in thread
From: Bastien @ 2020-09-05 10:28 UTC (permalink / raw)
  To: Marco Falconi; +Cc: emacs-orgmode

Hi Marco,

Marco Falconi <marco.falconi@uniroma3.it> writes:

> I am trying to export to html a labeled latex special block (a theorem
> environment, defined by #+begin_theorem [...] #+end_theorem ). I have named the theorem with
>
> #+NAME: thm:mv (I also tried with #+LABEL: and the behavior described below does not change).
>
> I have a link to such block later in the body, in the form [[thm:mv]]. The link works
> perfectly in the org file, however it is exported incorrectly to html.
>
> In fact, while the theorem environment gets exported in the html as
>
>    <div class="theorem" id="thm:mv">
>    <p>
>    [...]
>    </p>
>    </div>
>
> ,
>
> the link does not href to "#thm:mv" as expected, but to an auto-generated label:
>
>     <p>
>     <a href="#orgd9d024a">1</a>
>     </p>
>
> I have tried to play around a bit with export options, but to no avail.
>
> Is this a known bug?

I also confirm this bug.  I've had a quick look.  It looks like
`org-export-get-reference' get fooled by trying to provide with a "new
reference".  I hope Nicolas can have a look because this area of the
code is quite complexe.

Thanks,

-- 
 Bastien


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Bug: Exporting internal link to special latex block [9.3.7 (9.3.7-14-gb2b587-elpa @ /home/lobo/.emacs.d/elpa/org-20200720/)]
  2020-09-05 10:28 ` Bastien
@ 2020-09-05 10:56   ` Marco Falconi
  2020-09-05 13:07     ` Bastien
  0 siblings, 1 reply; 9+ messages in thread
From: Marco Falconi @ 2020-09-05 10:56 UTC (permalink / raw)
  To: Bastien; +Cc: emacs-orgmode

Dear Bastien,

Thanks for the update. For the moment I have worked around the bug by putting an
html-export block in the org file with the correct href when I have to put a link to it.

However, it would be very nice if it was solved in org. Also, my preference would be for
the exported id to be the one given in the NAME attribute (as it is now), because I use it
in the html file to name the theorem environment. Of course this is just my preference,
and I would understand if the solution would work in another manner.

Best regards,
_____
Marco


Bastien <bzg@gnu.org> writes:

> Hi Marco,
>
> Marco Falconi <marco.falconi@uniroma3.it> writes:
>
>> I am trying to export to html a labeled latex special block (a theorem
>> environment, defined by #+begin_theorem [...] #+end_theorem ). I have named the theorem with
>>
>> #+NAME: thm:mv (I also tried with #+LABEL: and the behavior described below does not change).
>>
>> I have a link to such block later in the body, in the form [[thm:mv]]. The link works
>> perfectly in the org file, however it is exported incorrectly to html.
>>
>> In fact, while the theorem environment gets exported in the html as
>>
>>    <div class="theorem" id="thm:mv">
>>    <p>
>>    [...]
>>    </p>
>>    </div>
>>
>> ,
>>
>> the link does not href to "#thm:mv" as expected, but to an auto-generated label:
>>
>>     <p>
>>     <a href="#orgd9d024a">1</a>
>>     </p>
>>
>> I have tried to play around a bit with export options, but to no avail.
>>
>> Is this a known bug?
>
> I also confirm this bug.  I've had a quick look.  It looks like
> `org-export-get-reference' get fooled by trying to provide with a "new
> reference".  I hope Nicolas can have a look because this area of the
> code is quite complexe.
>
> Thanks,



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Bug: Exporting internal link to special latex block [9.3.7 (9.3.7-14-gb2b587-elpa @ /home/lobo/.emacs.d/elpa/org-20200720/)]
  2020-09-05 10:56   ` Marco Falconi
@ 2020-09-05 13:07     ` Bastien
  2020-09-08  8:21       ` Nicolas Goaziou
  0 siblings, 1 reply; 9+ messages in thread
From: Bastien @ 2020-09-05 13:07 UTC (permalink / raw)
  To: Marco Falconi; +Cc: emacs-orgmode

Hi Marco,

thanks for the feedback, I'm glad you found a workaround.

Marco Falconi <marco.falconi@uniroma3.it> writes:

> However, it would be very nice if it was solved in org. 

Yes, me too.

> Also, my preference would be for the exported id to be the one given
> in the NAME attribute (as it is now), because I use it in the html
> file to name the theorem environment. Of course this is just my
> preference, and I would understand if the solution would work in
> another manner.

I think that's the natural expectation.

Best,

-- 
 Bastien


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Bug: Exporting internal link to special latex block [9.3.7 (9.3.7-14-gb2b587-elpa @ /home/lobo/.emacs.d/elpa/org-20200720/)]
  2020-09-05 13:07     ` Bastien
@ 2020-09-08  8:21       ` Nicolas Goaziou
  2020-09-09  8:24         ` Bastien
  0 siblings, 1 reply; 9+ messages in thread
From: Nicolas Goaziou @ 2020-09-08  8:21 UTC (permalink / raw)
  To: Bastien; +Cc: Marco Falconi, emacs-orgmode

[-- Attachment #1: Type: text/plain, Size: 765 bytes --]

Hello,

Bastien <bzg@gnu.org> writes:

> Marco Falconi <marco.falconi@uniroma3.it> writes:
>
>> Also, my preference would be for the exported id to be the one given
>> in the NAME attribute (as it is now), because I use it in the html
>> file to name the theorem environment. Of course this is just my
>> preference, and I would understand if the solution would work in
>> another manner.
>
> I think that's the natural expectation.

Actually, that's a natural expectation only if you don't use fancy
names, or know a bit of HTML. By default using raw names is not safe.
This is the reason why `org-latex-prefer-user-labels' has a nil default
value.

The following patch implements the same for HTML. I didn't test it
thoroughly, tho.

Regards,
-- 
Nicolas Goaziou

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: Improve consistency in internal anchors --]
[-- Type: text/x-diff, Size: 12710 bytes --]

From 243c213c205b8157d9ce5552dd0489cc6ae229ff Mon Sep 17 00:00:00 2001
From: Nicolas Goaziou <mail@nicolasgoaziou.fr>
Date: Tue, 8 Sep 2020 10:14:06 +0200
Subject: [PATCH] html: Improve consistency on internal anchors naming scheme

* lisp/ox-html.el (org-html-prefer-user-labels): New variable.
(org-html--reference): New function.
(org-html--format-toc-headline):
(org-html-list-of-listings):
(org-html-list-of-tables):
(org-html-example-block):
(org-html-headline):
(org-html-inline-src-block):
(org-html-latex-environment):
(org-html-link):
(org-html-paragraph):
(org-html-quote-block):
(org-html-radio-target):
(org-html-special-block):
(org-html-src-block):
(org-html-table):
(org-html-target): Use new function.
---
 etc/ORG-NEWS    |   7 ++++
 lisp/ox-html.el | 107 +++++++++++++++++++++++++++++++++---------------
 2 files changed, 80 insertions(+), 34 deletions(-)

diff --git a/etc/ORG-NEWS b/etc/ORG-NEWS
index 983709c69..f2bee7254 100644
--- a/etc/ORG-NEWS
+++ b/etc/ORG-NEWS
@@ -298,6 +298,13 @@ possible via column view value edit or with =<C-c C-q>=.
 Counterpart of ~org-show-entry~.
 
 ** New options
+*** New option ~org-html-prefer-user-labels~
+
+When non-nil, use =NAME= affiliated keyword, or raw target values, to
+generate anchor's ID.  Otherwise, consistently use internal naming
+scheme.
+
+=CUSTOM_ID= values are still always used, when available.
 *** New option for using tabs in ~org-agenda-window-setup~
 
 Choosing ~other-tab~ for ~org-agenda-window-setup~ will open the
diff --git a/lisp/ox-html.el b/lisp/ox-html.el
index 76ccbbc4a..d2f24f5c6 100644
--- a/lisp/ox-html.el
+++ b/lisp/ox-html.el
@@ -152,6 +152,7 @@
     (:html-metadata-timestamp-format nil nil org-html-metadata-timestamp-format)
     (:html-postamble-format nil nil org-html-postamble-format)
     (:html-preamble-format nil nil org-html-preamble-format)
+    (:html-prefer-user-labels nil nil org-html-prefer-user-labels)
     (:html-self-link-headlines nil nil org-html-self-link-headlines)
     (:html-table-align-individual-fields
      nil nil org-html-table-align-individual-fields)
@@ -736,6 +737,24 @@ but without \"name\" attribute."
   :type 'boolean
   :safe #'booleanp)
 
+(defcustom org-html-prefer-user-labels nil
+  "When non-nil use user-defined names and ID over internal ones.
+
+By default, Org generates its own internal ID values during HTML
+export.  This process ensures that these values are unique and
+valid, but the keys are not available in advance of the export
+process, and not so readable.
+
+When this variable is non-nil, Org will use NAME keyword, or the
+real name of the target to create the ID attribute.
+
+Independently of this variable, however, CUSTOM_ID are always
+used as a reference."
+  :group 'org-export-html
+  :package-version '(Org . "9.4")
+  :type 'boolean
+  :safe #'booleanp)
+
 ;;;; Inlinetasks
 
 (defcustom org-html-format-inlinetask-function
@@ -1607,6 +1626,36 @@ attribute with a nil value will be omitted from the result."
                              "\"" "&quot;" (org-html-encode-plain-text item))))
                  (setcar output (format "%s=\"%s\"" key value))))))))
 
+(defun org-html--reference (datum info &optional named-only)
+  "Return an appropriate reference for DATUM.
+
+DATUM is an element or a `target' type object.  INFO is the
+current export state, as a plist.
+
+When NAMED-ONLY is non-nil and DATUM has no NAME keyword, return
+nil.  This doesn't apply to headlines, inline tasks, radio
+targets and targets."
+  (let* ((type (org-element-type datum))
+	 (user-label
+	  (org-element-property
+	   (pcase type
+	     ((or `headline `inlinetask) :CUSTOM_ID)
+	     ((or `radio-target `target) :value)
+	     (_ :name))
+	   datum)))
+    (cond
+     ((and user-label
+	   (or (plist-get info :html-prefer-user-labels)
+	       ;; Used CUSTOM_ID property unconditionally.
+	       (memq type '(headline inlinetask))))
+      user-label)
+     ((and named-only
+	   (not (memq type '(headline inlinetask radio-target target)))
+	   (not user-label))
+      nil)
+     (t
+      (org-export-get-reference datum info)))))
+
 (defun org-html--wrap-image (contents info &optional caption label)
   "Wrap CONTENTS string within an appropriate environment for images.
 INFO is a plist used as a communication channel.  When optional
@@ -2314,8 +2363,7 @@ INFO is a plist used as a communication channel."
 		    (org-export-get-tags headline info))))
     (format "<a href=\"#%s\">%s</a>"
 	    ;; Label.
-	    (or (org-element-property :CUSTOM_ID headline)
-		(org-export-get-reference headline info))
+	    (org-html--reference headline info)
 	    ;; Body.
 	    (concat
 	     (and (not (org-export-low-level-p headline info))
@@ -2343,8 +2391,7 @@ of listings as a string, or nil if it is empty."
 					 (org-html--translate "Listing %d:" info))))
 		(mapconcat
 		 (lambda (entry)
-		   (let ((label (and (org-element-property :name entry)
-				     (org-export-get-reference entry info)))
+		   (let ((label (org-html--reference entry info t))
 			 (title (org-trim
 				 (org-export-data
 				  (or (org-export-get-caption entry t)
@@ -2382,8 +2429,7 @@ of tables as a string, or nil if it is empty."
 					 (org-html--translate "Table %d:" info))))
 		(mapconcat
 		 (lambda (entry)
-		   (let ((label (and (org-element-property :name entry)
-				     (org-export-get-reference entry info)))
+		   (let ((label (org-html--reference entry info t))
 			 (title (org-trim
 				 (org-export-data
 				  (or (org-export-get-caption entry t)
@@ -2484,11 +2530,11 @@ information."
     (if (plist-get attributes :textarea)
 	(org-html--textarea-block example-block)
       (format "<pre class=\"example\"%s>\n%s</pre>"
-	      (let* ((name (org-element-property :name example-block))
+	      (let* ((reference (org-html--reference example-block info))
 		     (a (org-html--make-attribute-string
-			 (if (or (not name) (plist-member attributes :id))
+			 (if (or (not reference) (plist-member attributes :id))
 			     attributes
-			   (plist-put attributes :id name)))))
+			   (plist-put attributes :id reference)))))
 		(if (org-string-nw-p a) (concat " " a) ""))
 	      (org-html-format-code example-block info)))))
 
@@ -2564,8 +2610,7 @@ holding contextual information."
            (full-text (funcall (plist-get info :html-format-headline-function)
                                todo todo-type priority text tags info))
            (contents (or contents ""))
-	   (id (or (org-element-property :CUSTOM_ID headline)
-		   (org-export-get-reference headline info)))
+	   (id (org-html--reference headline info))
 	   (formatted-text
 	    (if (plist-get info :html-self-link-headlines)
 		(format "<a href=\"#%s\">%s</a>" id full-text)
@@ -2652,8 +2697,7 @@ contextual information."
 		(org-element-property :value inline-src-block)
 		lang))
 	 (label
-	  (let ((lbl (and (org-element-property :name inline-src-block)
-			  (org-export-get-reference inline-src-block info))))
+	  (let ((lbl (org-html--reference inline-src-block info t)))
 	    (if (not lbl) "" (format " id=\"%s\"" lbl)))))
     (format "<code class=\"src src-%s\"%s>%s</code>" lang label code)))
 
@@ -2869,8 +2913,7 @@ CONTENTS is nil.  INFO is a plist holding contextual information."
 	(latex-frag (org-remove-indentation
 		     (org-element-property :value latex-environment)))
         (attributes (org-export-read-attribute :attr_html latex-environment))
-        (label (and (org-element-property :name latex-environment)
-                    (org-export-get-reference latex-environment info)))
+        (label (org-html--reference latex-environment info t))
         (caption (and (org-html--latex-environment-numbered-p latex-environment)
 		      (number-to-string
 		       (org-export-get-ordinal
@@ -3107,8 +3150,7 @@ INFO is a plist holding contextual information.  See
 			(org-element-property :raw-link link) info))))
 	  ;; Link points to a headline.
 	  (`headline
-	   (let ((href (or (org-element-property :CUSTOM_ID destination)
-			   (org-export-get-reference destination info)))
+	   (let ((href (org-html--reference destination info))
 		 ;; What description to use?
 		 (desc
 		  ;; Case 1: Headline is numbered and LINK has no
@@ -3135,8 +3177,8 @@ INFO is a plist holding contextual information.  See
 	       ;; environment.  Use "ref" or "eqref" macro, depending on user
                ;; preference to refer to those in the document.
                (format (plist-get info :html-equation-reference-format)
-                       (org-export-get-reference destination info))
-             (let* ((ref (org-export-get-reference destination info))
+                       (org-html--reference destination info))
+             (let* ((ref (org-html--reference destination info))
                     (org-html-standalone-image-predicate
                      #'org-html--has-caption-p)
                     (counter-predicate
@@ -3233,8 +3275,7 @@ the plist used as a communication channel."
 				  info nil #'org-html-standalone-image-p))
 			 " </span>"
 			 raw))))
-	    (label (and (org-element-property :name paragraph)
-			(org-export-get-reference paragraph info))))
+	    (label (org-html--reference paragraph info)))
 	(org-html--wrap-image contents info caption label)))
      ;; Regular paragraph.
      (t (format "<p%s%s>\n%s</p>"
@@ -3340,17 +3381,17 @@ holding contextual information."
 
 ;;;; Quote Block
 
-(defun org-html-quote-block (quote-block contents _info)
+(defun org-html-quote-block (quote-block contents info)
   "Transcode a QUOTE-BLOCK element from Org to HTML.
 CONTENTS holds the contents of the block.  INFO is a plist
 holding contextual information."
   (format "<blockquote%s>\n%s</blockquote>"
-	  (let* ((name (org-element-property :name quote-block))
+	  (let* ((reference (org-html--reference quote-block info t))
 		 (attributes (org-export-read-attribute :attr_html quote-block))
 		 (a (org-html--make-attribute-string
-		     (if (or (not name) (plist-member attributes :id))
+		     (if (or (not reference) (plist-member attributes :id))
 			 attributes
-		       (plist-put attributes :id name)))))
+		       (plist-put attributes :id reference)))))
 	    (if (org-string-nw-p a) (concat " " a) ""))
 	  contents))
 
@@ -3385,7 +3426,7 @@ holding contextual information."
   "Transcode a RADIO-TARGET object from Org to HTML.
 TEXT is the text of the target.  INFO is a plist holding
 contextual information."
-  (let ((ref (org-export-get-reference radio-target info)))
+  (let ((ref (org-html--reference radio-target info)))
     (org-html--anchor ref text nil info)))
 
 ;;;; Special Block
@@ -3404,11 +3445,11 @@ holding contextual information."
                                     (if class (concat class " " block-type)
                                       block-type)))))
     (let* ((contents (or contents ""))
-	   (name (org-element-property :name special-block))
+	   (reference (org-html--reference special-block info))
 	   (a (org-html--make-attribute-string
-	       (if (or (not name) (plist-member attributes :id))
+	       (if (or (not reference) (plist-member attributes :id))
 		   attributes
-		 (plist-put attributes :id name))))
+		 (plist-put attributes :id reference))))
 	   (str (if (org-string-nw-p a) (concat " " a) "")))
       (if html5-fancy
 	  (format "<%s%s>\n%s</%s>" block-type str contents block-type)
@@ -3424,8 +3465,7 @@ contextual information."
       (org-html--textarea-block src-block)
     (let* ((lang (org-element-property :language src-block))
 	  (code (org-html-format-code src-block info))
-	  (label (let ((lbl (and (org-element-property :name src-block)
-				 (org-export-get-reference src-block info))))
+	  (label (let ((lbl (org-html--reference src-block info t)))
 		   (if lbl (format " id=\"%s\"" lbl) "")))
 	  (klipsify  (and  (plist-get info :html-klipsify-src)
                            (member lang '("javascript" "js"
@@ -3620,8 +3660,7 @@ contextual information."
 	   (attributes
 	    (org-html--make-attribute-string
 	     (org-combine-plists
-	      (and (org-element-property :name table)
-		   (list :id (org-export-get-reference table info)))
+	      (list :id (org-html--reference table info t))
 	      (and (not (org-html-html5-p info))
 		   (plist-get info :html-table-attributes))
 	      (org-export-read-attribute :attr_html table))))
@@ -3668,7 +3707,7 @@ contextual information."
   "Transcode a TARGET object from Org to HTML.
 CONTENTS is nil.  INFO is a plist holding contextual
 information."
-  (let ((ref (org-export-get-reference target info)))
+  (let ((ref (org-html--reference target info)))
     (org-html--anchor ref nil nil info)))
 
 ;;;; Timestamp
-- 
2.28.0


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Bug: Exporting internal link to special latex block [9.3.7 (9.3.7-14-gb2b587-elpa @ /home/lobo/.emacs.d/elpa/org-20200720/)]
  2020-09-08  8:21       ` Nicolas Goaziou
@ 2020-09-09  8:24         ` Bastien
  2020-09-09  8:37           ` Bastien
  0 siblings, 1 reply; 9+ messages in thread
From: Bastien @ 2020-09-09  8:24 UTC (permalink / raw)
  To: Nicolas Goaziou; +Cc: Marco Falconi, emacs-orgmode

Hi Nicolas and Marco,

I tested the patch and it fixes the problem just fine, I applied 
it in master as b79fef1da. 

Thanks a lot for this!

-- 
 Bastien


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Bug: Exporting internal link to special latex block [9.3.7 (9.3.7-14-gb2b587-elpa @ /home/lobo/.emacs.d/elpa/org-20200720/)]
  2020-09-09  8:24         ` Bastien
@ 2020-09-09  8:37           ` Bastien
  0 siblings, 0 replies; 9+ messages in thread
From: Bastien @ 2020-09-09  8:37 UTC (permalink / raw)
  To: Nicolas Goaziou; +Cc: Marco Falconi, emacs-orgmode

Bastien <bzg@gnu.org> writes:

> I tested the patch and it fixes the problem just fine, I applied 
> it in master as b79fef1da.

PS: Also marking this as fixed now.

-- 
 Bastien


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Bug: Exporting internal link to special latex block [9.3.7 (9.3.7-14-gb2b587-elpa @ /home/lobo/.emacs.d/elpa/org-20200720/)]
  2020-08-04  6:41 ` Eric S Fraga
@ 2021-04-18 15:42   ` Nicolas Goaziou
  0 siblings, 0 replies; 9+ messages in thread
From: Nicolas Goaziou @ 2021-04-18 15:42 UTC (permalink / raw)
  To: Marco Falconi; +Cc: emacs-orgmode

Hello,

Eric S Fraga <e.fraga@ucl.ac.uk> writes:

> On Tuesday, 21 Jul 2020 at 15:52, Marco Falconi wrote:
>> I am trying to export to html a labeled latex special block (a theorem
>> environment,
>
> [...]
>
>> the link does not href to "#thm:mv" as expected, but to an auto-generated label:
>
> Confirmed with org from git a few minutes ago.  The link using an
> auto-generated label would be fine if the label were the one for the
> special block but it's not.

I couldn't reproduce it.

Regards,
-- 
Nicolas Goaziou


^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2021-04-18 15:43 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-07-21 13:52 Bug: Exporting internal link to special latex block [9.3.7 (9.3.7-14-gb2b587-elpa @ /home/lobo/.emacs.d/elpa/org-20200720/)] Marco Falconi
2020-08-04  6:41 ` Eric S Fraga
2021-04-18 15:42   ` Nicolas Goaziou
2020-09-05 10:28 ` Bastien
2020-09-05 10:56   ` Marco Falconi
2020-09-05 13:07     ` Bastien
2020-09-08  8:21       ` Nicolas Goaziou
2020-09-09  8:24         ` Bastien
2020-09-09  8:37           ` Bastien

Code repositories for project(s) associated with this inbox:

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).