emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* using vref in latex export, and normal links in html export
@ 2016-03-11 10:20 Alan Schmitt
  2016-03-11 11:03 ` Eric S Fraga
  2016-03-12  8:44 ` Stefan Nobis
  0 siblings, 2 replies; 11+ messages in thread
From: Alan Schmitt @ 2016-03-11 10:20 UTC (permalink / raw)
  To: emacs-orgmode

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

Hello,

I'm converting a latex document into org-mode to easily export it both
to latex and html. I've just encountered something that I don't know how
to do: export a \vref reference. I would like to have something that
exports to \vref in latex, and to a normal link in html.

I thought I could do this trick with a macro:

#+macro: vref @@latex:\myvref{$1}{@@[[$1]]@@latex:}@@

then define the latex command to ignore the second argument:

\newcommand{\myvref}{2}{\vref{#1}}

Unfortunately this does not work, as the name of the label is changed
during export:

Figure \myvref{fig:log-expt-7}{\ref{fig:orgparagraph1}} 

So my question is: is anyone using vref with org-mode? Or should I just
convert this to a plain reference?

Thanks,

Alan


-- 
OpenPGP Key ID : 040D0A3B4ED2E5C7
Monthly Athmospheric CO₂ (2016-02, Mauna Loa Obs.): 404.02

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 472 bytes --]

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

* Re: using vref in latex export, and normal links in html export
  2016-03-11 10:20 using vref in latex export, and normal links in html export Alan Schmitt
@ 2016-03-11 11:03 ` Eric S Fraga
  2016-03-11 13:11   ` Alan Schmitt
  2016-03-12  8:44 ` Stefan Nobis
  1 sibling, 1 reply; 11+ messages in thread
From: Eric S Fraga @ 2016-03-11 11:03 UTC (permalink / raw)
  To: Alan Schmitt; +Cc: emacs-orgmode

On Friday, 11 Mar 2016 at 11:20, Alan Schmitt wrote:
> Hello,
>
> I'm converting a latex document into org-mode to easily export it both
> to latex and html. I've just encountered something that I don't know how
> to do: export a \vref reference. I would like to have something that
> exports to \vref in latex, and to a normal link in html.
>
> I thought I could do this trick with a macro:
>
> #+macro: vref @@latex:\myvref{$1}{@@[[$1]]@@latex:}@@

I may be missing something but could you not simply use

  [[vref:fig:log-expt-7]]

(along with description text if you wished) and define an org link as
below?

#+begin_src elisp
  (org-add-link-type "vref" nil
                     (lambda (path desc format)
                       (cond
                        ((eq format 'latex)
                         (format "\\vref{%s}" path)))))
#+end_src

(untested)

-- 
: Eric S Fraga (0xFFFCF67D), Emacs 25.0.91.1, Org release_8.3.4-626-gb62d55

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

* Re: using vref in latex export, and normal links in html export
  2016-03-11 11:03 ` Eric S Fraga
@ 2016-03-11 13:11   ` Alan Schmitt
  2016-03-11 14:02     ` John Kitchin
  0 siblings, 1 reply; 11+ messages in thread
From: Alan Schmitt @ 2016-03-11 13:11 UTC (permalink / raw)
  To: emacs-orgmode

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

Hello Eric,

On 2016-03-11 12:03, Eric S Fraga <e.fraga@ucl.ac.uk> writes:

> On Friday, 11 Mar 2016 at 11:20, Alan Schmitt wrote:
>> Hello,
>>
>> I'm converting a latex document into org-mode to easily export it both
>> to latex and html. I've just encountered something that I don't know how
>> to do: export a \vref reference. I would like to have something that
>> exports to \vref in latex, and to a normal link in html.
>>
>> I thought I could do this trick with a macro:
>>
>> #+macro: vref @@latex:\myvref{$1}{@@[[$1]]@@latex:}@@
>
> I may be missing something but could you not simply use
>
>   [[vref:fig:log-expt-7]]
>
> (along with description text if you wished) and define an org link as
> below?
>
> #+begin_src elisp
>   (org-add-link-type "vref" nil
>                      (lambda (path desc format)
>                        (cond
>                         ((eq format 'latex)
>                          (format "\\vref{%s}" path)))))
> #+end_src
>
> (untested)

Thank you for the suggestion, but I end up with the same thing as with
the macro: the reference generated is to "fig:log-expt-7", but this does
not work as the label assigned by org to the figure is
"fig:orgparagraph1".

Here is a small example of a similar problem. Exporting this to latex

This is a \ref{fig:foo} and this is a link [[fig:foo]]

#+label: fig:foo
#+begin_figure
Test
#+end_figure

results in

#+begin_src latex
This is a \ref{fig:foo} and this is a link \ref{orgspecialblock1}

\begin{figure}
Test
\label{orgspecialblock1}
\end{figure}
#+end_src

Alan

-- 
OpenPGP Key ID : 040D0A3B4ED2E5C7
Monthly Athmospheric CO₂ (2016-02, Mauna Loa Obs.): 404.02

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 472 bytes --]

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

* Re: using vref in latex export, and normal links in html export
  2016-03-11 13:11   ` Alan Schmitt
@ 2016-03-11 14:02     ` John Kitchin
  2016-03-11 15:05       ` Alan Schmitt
  0 siblings, 1 reply; 11+ messages in thread
From: John Kitchin @ 2016-03-11 14:02 UTC (permalink / raw)
  To: Alan Schmitt; +Cc: emacs-orgmode

Try:

(setq org-latex-prefer-user-labels t)

I think this does what you want for org 8.3.4 at least.


Alan Schmitt writes:

> Hello Eric,
>
> On 2016-03-11 12:03, Eric S Fraga <e.fraga@ucl.ac.uk> writes:
>
>> On Friday, 11 Mar 2016 at 11:20, Alan Schmitt wrote:
>>> Hello,
>>>
>>> I'm converting a latex document into org-mode to easily export it both
>>> to latex and html. I've just encountered something that I don't know how
>>> to do: export a \vref reference. I would like to have something that
>>> exports to \vref in latex, and to a normal link in html.
>>>
>>> I thought I could do this trick with a macro:
>>>
>>> #+macro: vref @@latex:\myvref{$1}{@@[[$1]]@@latex:}@@
>>
>> I may be missing something but could you not simply use
>>
>>   [[vref:fig:log-expt-7]]
>>
>> (along with description text if you wished) and define an org link as
>> below?
>>
>> #+begin_src elisp
>>   (org-add-link-type "vref" nil
>>                      (lambda (path desc format)
>>                        (cond
>>                         ((eq format 'latex)
>>                          (format "\\vref{%s}" path)))))
>> #+end_src
>>
>> (untested)
>
> Thank you for the suggestion, but I end up with the same thing as with
> the macro: the reference generated is to "fig:log-expt-7", but this does
> not work as the label assigned by org to the figure is
> "fig:orgparagraph1".
>
> Here is a small example of a similar problem. Exporting this to latex
>
> This is a \ref{fig:foo} and this is a link [[fig:foo]]
>
> #+label: fig:foo
> #+begin_figure
> Test
> #+end_figure
>
> results in
>
> #+begin_src latex
> This is a \ref{fig:foo} and this is a link \ref{orgspecialblock1}
>
> \begin{figure}
> Test
> \label{orgspecialblock1}
> \end{figure}
> #+end_src
>
> Alan


--
Professor John Kitchin
Doherty Hall A207F
Department of Chemical Engineering
Carnegie Mellon University
Pittsburgh, PA 15213
412-268-7803
@johnkitchin
http://kitchingroup.cheme.cmu.edu

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

* Re: using vref in latex export, and normal links in html export
  2016-03-11 14:02     ` John Kitchin
@ 2016-03-11 15:05       ` Alan Schmitt
  2016-03-11 15:20         ` Alan Schmitt
  0 siblings, 1 reply; 11+ messages in thread
From: Alan Schmitt @ 2016-03-11 15:05 UTC (permalink / raw)
  To: John Kitchin; +Cc: emacs-orgmode

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

On 2016-03-11 15:02, John Kitchin <jkitchin@andrew.cmu.edu> writes:

> Try:
>
> (setq org-latex-prefer-user-labels t)
>
> I think this does what you want for org 8.3.4 at least.

Thank you! This is what I was missing.

Alan

-- 
OpenPGP Key ID : 040D0A3B4ED2E5C7
Monthly Athmospheric CO₂ (2016-02, Mauna Loa Obs.): 404.02

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 472 bytes --]

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

* Re: using vref in latex export, and normal links in html export
  2016-03-11 15:05       ` Alan Schmitt
@ 2016-03-11 15:20         ` Alan Schmitt
  2016-03-12 21:36           ` John Kitchin
  0 siblings, 1 reply; 11+ messages in thread
From: Alan Schmitt @ 2016-03-11 15:20 UTC (permalink / raw)
  To: John Kitchin; +Cc: emacs-orgmode

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

On 2016-03-11 16:05, Alan Schmitt <alan.schmitt@polytechnique.org> writes:

> On 2016-03-11 15:02, John Kitchin <jkitchin@andrew.cmu.edu> writes:
>
>> Try:
>>
>> (setq org-latex-prefer-user-labels t)
>>
>> I think this does what you want for org 8.3.4 at least.
>
> Thank you! This is what I was missing.

As a followup question, I read the documentation for `org-add-link-type`
which says "Org mode has a built-in default for exporting links." What
is the name of that function? I would like to change Eric's function to
something like:

#+begin_src elisp
  (org-add-link-type "vref" nil
                     (lambda (path desc format)
                       (cond
                        ((eq format 'latex)
                         (format "\\vref{%s}" path))
                        (t (call org default)))))
#+end_src

I searched through ox.el but could not find that function.

Thanks,

Alan

-- 
OpenPGP Key ID : 040D0A3B4ED2E5C7
Monthly Athmospheric CO₂ (2016-02, Mauna Loa Obs.): 404.02

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 472 bytes --]

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

* Re: using vref in latex export, and normal links in html export
  2016-03-11 10:20 using vref in latex export, and normal links in html export Alan Schmitt
  2016-03-11 11:03 ` Eric S Fraga
@ 2016-03-12  8:44 ` Stefan Nobis
  2016-03-12 21:27   ` John Kitchin
  2016-03-14  9:29   ` Alan Schmitt
  1 sibling, 2 replies; 11+ messages in thread
From: Stefan Nobis @ 2016-03-12  8:44 UTC (permalink / raw)
  To: emacs-orgmode

Alan Schmitt <alan.schmitt@polytechnique.org> writes:

> I'm converting a latex document into org-mode to easily export it both
> to latex and html. I've just encountered something that I don't know how
> to do: export a \vref reference. I would like to have something that
> exports to \vref in latex, and to a normal link in html.

I solve this with the help of an export filter:

--8<---------------cut here---------------start------------->8---
(defun sn/ox-latex-filter-varioref (text backend info)
  (when (org-export-derived-backend-p backend 'latex)
    (replace-regexp-in-string "\\\\ref{" "\\\\vref{" text)))
    
(eval-after-load "ox-latex"
  '(progn
     (add-to-list 'org-export-filter-link-functions 'sn/ox-latex-filter-varioref)))
--8<---------------cut here---------------end--------------->8---

-- 
Until the next mail...,
Stefan.

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

* Re: using vref in latex export, and normal links in html export
  2016-03-12  8:44 ` Stefan Nobis
@ 2016-03-12 21:27   ` John Kitchin
  2016-03-14  9:29   ` Alan Schmitt
  1 sibling, 0 replies; 11+ messages in thread
From: John Kitchin @ 2016-03-12 21:27 UTC (permalink / raw)
  To: Stefan Nobis; +Cc: emacs-orgmode

you could also try redefining the export of a ref link like this.

#+BEGIN_SRC emacs-lisp
(setf (elt  (assoc "ref" org-link-protocols) 2)
      (lambda (keyword desc format)
        (cond
         ((eq format 'latex)
          "\\vref{keyword}")
         ((eq format 'html)
          (format
           "<a href=\"%s\">%s</a>"
           keyword (or desc ""))))))
#+END_SRC

I am not sure if that is the kind of html export you want, but you could
adapt it to something else.

Stefan Nobis writes:

> Alan Schmitt <alan.schmitt@polytechnique.org> writes:
>
>> I'm converting a latex document into org-mode to easily export it both
>> to latex and html. I've just encountered something that I don't know how
>> to do: export a \vref reference. I would like to have something that
>> exports to \vref in latex, and to a normal link in html.
>
> I solve this with the help of an export filter:
>
> --8<---------------cut here---------------start------------->8---
> (defun sn/ox-latex-filter-varioref (text backend info)
>   (when (org-export-derived-backend-p backend 'latex)
>     (replace-regexp-in-string "\\\\ref{" "\\\\vref{" text)))
>
> (eval-after-load "ox-latex"
>   '(progn
>      (add-to-list 'org-export-filter-link-functions 'sn/ox-latex-filter-varioref)))
> --8<---------------cut here---------------end--------------->8---


--
Professor John Kitchin
Doherty Hall A207F
Department of Chemical Engineering
Carnegie Mellon University
Pittsburgh, PA 15213
412-268-7803
@johnkitchin
http://kitchingroup.cheme.cmu.edu

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

* Re: using vref in latex export, and normal links in html export
  2016-03-11 15:20         ` Alan Schmitt
@ 2016-03-12 21:36           ` John Kitchin
  2016-03-14  9:33             ` Alan Schmitt
  0 siblings, 1 reply; 11+ messages in thread
From: John Kitchin @ 2016-03-12 21:36 UTC (permalink / raw)
  To: Alan Schmitt; +Cc: emacs-orgmode

I guess these are defined in backends, e.g. org-latex-link.

Alan Schmitt writes:

> On 2016-03-11 16:05, Alan Schmitt <alan.schmitt@polytechnique.org> writes:
>
>> On 2016-03-11 15:02, John Kitchin <jkitchin@andrew.cmu.edu> writes:
>>
>>> Try:
>>>
>>> (setq org-latex-prefer-user-labels t)
>>>
>>> I think this does what you want for org 8.3.4 at least.
>>
>> Thank you! This is what I was missing.
>
> As a followup question, I read the documentation for `org-add-link-type`
> which says "Org mode has a built-in default for exporting links." What
> is the name of that function? I would like to change Eric's function to
> something like:
>
> #+begin_src elisp
>   (org-add-link-type "vref" nil
>                      (lambda (path desc format)
>                        (cond
>                         ((eq format 'latex)
>                          (format "\\vref{%s}" path))
>                         (t (call org default)))))
> #+end_src
>
> I searched through ox.el but could not find that function.
>
> Thanks,
>
> Alan


--
Professor John Kitchin
Doherty Hall A207F
Department of Chemical Engineering
Carnegie Mellon University
Pittsburgh, PA 15213
412-268-7803
@johnkitchin
http://kitchingroup.cheme.cmu.edu

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

* Re: using vref in latex export, and normal links in html export
  2016-03-12  8:44 ` Stefan Nobis
  2016-03-12 21:27   ` John Kitchin
@ 2016-03-14  9:29   ` Alan Schmitt
  1 sibling, 0 replies; 11+ messages in thread
From: Alan Schmitt @ 2016-03-14  9:29 UTC (permalink / raw)
  To: emacs-orgmode

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

On 2016-03-12 09:44, Stefan Nobis <stefan-ml@snobis.de> writes:

> Alan Schmitt <alan.schmitt@polytechnique.org> writes:
>
>> I'm converting a latex document into org-mode to easily export it both
>> to latex and html. I've just encountered something that I don't know how
>> to do: export a \vref reference. I would like to have something that
>> exports to \vref in latex, and to a normal link in html.
>
> I solve this with the help of an export filter:
>
> (defun sn/ox-latex-filter-varioref (text backend info)
>   (when (org-export-derived-backend-p backend 'latex)
>     (replace-regexp-in-string "\\\\ref{" "\\\\vref{" text)))
>     
> (eval-after-load "ox-latex"
>   '(progn
>      (add-to-list 'org-export-filter-link-functions 'sn/ox-latex-filter-varioref)))

Thank you for the suggestion, but this would convert every link in a
vref link. What I want to do is to be able to handle some links as vref.

Alan

-- 
OpenPGP Key ID : 040D0A3B4ED2E5C7
Monthly Athmospheric CO₂ (2016-02, Mauna Loa Obs.): 404.02

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 472 bytes --]

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

* Re: using vref in latex export, and normal links in html export
  2016-03-12 21:36           ` John Kitchin
@ 2016-03-14  9:33             ` Alan Schmitt
  0 siblings, 0 replies; 11+ messages in thread
From: Alan Schmitt @ 2016-03-14  9:33 UTC (permalink / raw)
  To: John Kitchin; +Cc: emacs-orgmode

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

On 2016-03-12 22:36, John Kitchin <jkitchin@andrew.cmu.edu> writes:

> I guess these are defined in backends, e.g. org-latex-link.

Ah, yes, thanks a lot. Unfortunately this approach does not work because
org-add-link-type uses a function whose argument do not contain enough
information to call the backend functions (for instance the first
argument is a string in org-add-link-type, and it's an org link in the
backend functions).

I went back to the macro approach, and with the addition of
org-latex-prefer-user-labels it works great.

Thanks again,

Alan

-- 
OpenPGP Key ID : 040D0A3B4ED2E5C7
Monthly Athmospheric CO₂ (2016-02, Mauna Loa Obs.): 404.02

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 472 bytes --]

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

end of thread, other threads:[~2016-03-14  9:33 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-03-11 10:20 using vref in latex export, and normal links in html export Alan Schmitt
2016-03-11 11:03 ` Eric S Fraga
2016-03-11 13:11   ` Alan Schmitt
2016-03-11 14:02     ` John Kitchin
2016-03-11 15:05       ` Alan Schmitt
2016-03-11 15:20         ` Alan Schmitt
2016-03-12 21:36           ` John Kitchin
2016-03-14  9:33             ` Alan Schmitt
2016-03-12  8:44 ` Stefan Nobis
2016-03-12 21:27   ` John Kitchin
2016-03-14  9:29   ` Alan Schmitt

Code repositories for project(s) associated with this public 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).