Re: [O] using vref in latex export, and normal links in html export

2016-03-14 Thread Alan Schmitt
On 2016-03-12 22:36, John Kitchin  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


signature.asc
Description: PGP signature


Re: [O] using vref in latex export, and normal links in html export

2016-03-14 Thread Alan Schmitt
On 2016-03-12 09:44, Stefan Nobis  writes:

> Alan Schmitt  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


signature.asc
Description: PGP signature


Re: [O] using vref in latex export, and normal links in html export

2016-03-12 Thread John Kitchin
I guess these are defined in backends, e.g. org-latex-link.

Alan Schmitt writes:

> On 2016-03-11 16:05, Alan Schmitt  writes:
>
>> On 2016-03-11 15:02, John Kitchin  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



Re: [O] using vref in latex export, and normal links in html export

2016-03-12 Thread John Kitchin
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
   "%s"
   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  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



Re: [O] using vref in latex export, and normal links in html export

2016-03-12 Thread Stefan Nobis
Alan Schmitt  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.



Re: [O] using vref in latex export, and normal links in html export

2016-03-11 Thread Alan Schmitt
On 2016-03-11 16:05, Alan Schmitt  writes:

> On 2016-03-11 15:02, John Kitchin  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


signature.asc
Description: PGP signature


Re: [O] using vref in latex export, and normal links in html export

2016-03-11 Thread Alan Schmitt
On 2016-03-11 15:02, John Kitchin  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


signature.asc
Description: PGP signature


Re: [O] using vref in latex export, and normal links in html export

2016-03-11 Thread John Kitchin
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  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



Re: [O] using vref in latex export, and normal links in html export

2016-03-11 Thread Alan Schmitt
Hello Eric,

On 2016-03-11 12:03, Eric S Fraga  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


signature.asc
Description: PGP signature


Re: [O] using vref in latex export, and normal links in html export

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



[O] using vref in latex export, and normal links in html export

2016-03-11 Thread Alan Schmitt
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


signature.asc
Description: PGP signature