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/)]

2021-04-18 Thread Nicolas Goaziou
Hello,

Eric S Fraga  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



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 Thread Bastien
Bastien  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



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 Thread Bastien
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



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 Thread Nicolas Goaziou
Hello,

Bastien  writes:

> Marco Falconi  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
>From 243c213c205b8157d9ce5552dd0489cc6ae229ff Mon Sep 17 00:00:00 2001
From: Nicolas Goaziou 
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 ==.
 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."
  "\"" """ (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 option

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 Thread Bastien
Hi Marco,

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

Marco Falconi  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



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 Thread Marco Falconi
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  writes:

> Hi Marco,
>
> Marco Falconi  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
>>
>>
>>
>>[...]
>>
>>
>>
>> ,
>>
>> the link does not href to "#thm:mv" as expected, but to an auto-generated 
>> label:
>>
>> 
>> 1
>> 
>>
>> 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,




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 Thread Bastien
Hi Marco,

Marco Falconi  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
>
>
>
>[...]
>
>
>
> ,
>
> the link does not href to "#thm:mv" as expected, but to an auto-generated 
> label:
>
> 
> 1
> 
>
> 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



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-03 Thread Eric S Fraga
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



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-01 Thread Marco Falconi


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

   
   
   [...]
   
   

,

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


1


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-fu