emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* Passing an image reference to source code block
@ 2016-12-27  2:00 shripad sinari
  2016-12-27 16:05 ` John Kitchin
  0 siblings, 1 reply; 5+ messages in thread
From: shripad sinari @ 2016-12-27  2:00 UTC (permalink / raw)
  To: Orgmode Mailing List

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

Hello all,
I would like to know if there is a way to pass a reference for a figure to
a source block as in the following example:

----x-----------x---

* Section name

some text
#+CAPTION: Fig Caption
#+NAME: fig:image
[[file:img.jpg]]
some reference to figure [[fig:image]]

* other section
reference to Section [[Section name]]

#+BEGIN_SRC R :session *sample* default :exports results :results output
latex :tangle yes :var plot=[[fig:image]]
  library(xtable)
  print(xtable(BOD
             , caption = paste("Link the image", plot,"to this table")))
#+END_SRC


----x-----------x---

I would like the caption of the table to point to the image, at the point
where the word "plot" is located, in LaTeX export of the org file.

Any help or other workarounds are appreciated. I am using org version 9.0.3
in GNU Emacs 24.5.1.

Thanks for your help and regards,

Shripad
Tucson, AZ

[-- Attachment #2: Type: text/html, Size: 1295 bytes --]

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

* Re: Passing an image reference to source code block
  2016-12-27  2:00 Passing an image reference to source code block shripad sinari
@ 2016-12-27 16:05 ` John Kitchin
  2016-12-27 18:12   ` shripad sinari
  0 siblings, 1 reply; 5+ messages in thread
From: John Kitchin @ 2016-12-27 16:05 UTC (permalink / raw)
  To: Orgmode Mailing List, shripad sinari

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

Can you pass \ref{fig:image} in? I think that is what you would do in
Latex.


On Mon, Dec 26, 2016 at 7:00 PM shripad sinari <shripad.sinari@gmail.com>
wrote:

> Hello all,
> I would like to know if there is a way to pass a reference for a figure to
> a source block as in the following example:
>
> ----x-----------x---
>
> * Section name
>
> some text
> #+CAPTION: Fig Caption
> #+NAME: fig:image
> [[file:img.jpg]]
> some reference to figure [[fig:image]]
>
> * other section
> reference to Section [[Section name]]
>
> #+BEGIN_SRC R :session *sample* default :exports results :results output
> latex :tangle yes :var plot=[[fig:image]]
>   library(xtable)
>   print(xtable(BOD
>              , caption = paste("Link the image", plot,"to this table")))
> #+END_SRC
>
>
> ----x-----------x---
>
> I would like the caption of the table to point to the image, at the point
> where the word "plot" is located, in LaTeX export of the org file.
>
> Any help or other workarounds are appreciated. I am using org version
> 9.0.3 in GNU Emacs 24.5.1.
>
> Thanks for your help and regards,
>
> Shripad
> Tucson, AZ
>
>
>
>
>

[-- Attachment #2: Type: text/html, Size: 2633 bytes --]

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

* Re: Passing an image reference to source code block
  2016-12-27 16:05 ` John Kitchin
@ 2016-12-27 18:12   ` shripad sinari
       [not found]     ` <CAJ51ETonOMi3UFfT4QwxUbqqFqed1rit9Z0HA5-Qt1QzARWdKA@mail.gmail.com>
  2016-12-27 20:36     ` Nick Dokos
  0 siblings, 2 replies; 5+ messages in thread
From: shripad sinari @ 2016-12-27 18:12 UTC (permalink / raw)
  To: John Kitchin; +Cc: Orgmode Mailing List

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

Hello John,
Thanks for the suggestion. The proposed solution does not work since the
recent org versions generate their own labels and the label value cannot be
predetermined. See the LaTeX code generated by the above example with your
suggestion included:

----x-----------------x----

\section{Section name}
\label{sec:org62816be}
some text
\begin{figure}[htbp]
\centering
\includegraphics[width=.9\linewidth]{img.jpg}
\caption{\label{fig:org43b3d3f}
Fig Caption}
\end{figure}
some reference to figure \ref{fig:org43b3d3f}
\section{other section}
\label{sec:org1e9d137}
reference to Section \ref{sec:org62816be}

% latex table generated in R 3.3.1 by xtable 1.8-2 package
% Tue Dec 27 10:56:43 2016
\begin{table}[ht]
\centering
\begin{tabular}{rrr}
  \hline
 & Time & demand \\
  \hline
1 & 1.00 & 8.30 \\
  2 & 2.00 & 10.30 \\
  3 & 3.00 & 19.00 \\
  4 & 4.00 & 16.00 \\
  5 & 5.00 & 15.60 \\
  6 & 7.00 & 19.80 \\
   \hline
\end{tabular}
\caption{Link the image \ref{fig:image} to this table}
\end{table}
\end{document}


----x-----------------x----

the difference is the image is labelled "fig:org43b3d3f" and not
"fig:image".

Is there a way to solve this using CUSTOM_ID? Or is there a very different
approach to the way such table should be generated and then org-caption
should be used?

Any pointers are appreciated.

I believe this is common requirement in scientific writing which is what I
do most often. I use orgmode to write papers. Till org version 8.2.10 at
least I had a workaround in the following sense:

----x-----------------x----

* Section name
some text
#+CAPTION: Fig Caption
#+LABEL: fig:image
[[file:img.jpg]]
some reference to figure [[fig:image]]
* other section
reference to Section [[Section name]]

#+BEGIN_SRC R :session *sample* default :exports results :results output
latex :tangle yes :var plot="\\\\ref{fig:image}"
  library(xtable)
  print(xtable(BOD
             , caption = paste("Link the image", plot,"to this table")))
#+END_SRC

----x-----------------x----

which produced the following latex code:

----x-----------------x----

\begin{document}

\maketitle
\tableofcontents

\section{Section name}
\label{sec-1}
some text
\begin{figure}[htb]
\centering
\includegraphics[width=.9\linewidth]{img.jpg}
\caption{\label{fig:image}Fig Caption}
\end{figure}
some reference to figure \ref{fig:image}
\section{other section}
\label{sec-2}
reference to Section \ref{sec-1}

 % latex table generated in R 3.3.1 by xtable 1.8-2 package
% Tue Dec 27 11:08:40 2016
\begin{table}[ht]
\centering
\begin{tabular}{rrr}
  \hline
 & Time & demand \\
  \hline
1 & 1.00 & 8.30 \\
  2 & 2.00 & 10.30 \\
  3 & 3.00 & 19.00 \\
  4 & 4.00 & 16.00 \\
  5 & 5.00 & 15.60 \\
  6 & 7.00 & 19.80 \\
   \hline
\end{tabular}
\caption{Link the image \ref{fig:image} to this table}
\end{table}
% Emacs 24.5.1 (Org mode 8.2.10)
\end{document}


----x-----------------x----


This code compiles to the desired document.

Thanks and regards,


Shripad
Tucson, AZ

On Tue, Dec 27, 2016 at 9:05 AM, John Kitchin <jkitchin@andrew.cmu.edu>
wrote:

> Can you pass \ref{fig:image} in? I think that is what you would do in
> Latex.
>
>
> On Mon, Dec 26, 2016 at 7:00 PM shripad sinari <shripad.sinari@gmail.com>
> wrote:
>
>> Hello all,
>> I would like to know if there is a way to pass a reference for a figure
>> to a source block as in the following example:
>>
>> ----x-----------x---
>>
>> * Section name
>>
>> some text
>> #+CAPTION: Fig Caption
>> #+NAME: fig:image
>> [[file:img.jpg]]
>> some reference to figure [[fig:image]]
>>
>> * other section
>> reference to Section [[Section name]]
>>
>> #+BEGIN_SRC R :session *sample* default :exports results :results output
>> latex :tangle yes :var plot=[[fig:image]]
>>   library(xtable)
>>   print(xtable(BOD
>>              , caption = paste("Link the image", plot,"to this table")))
>> #+END_SRC
>>
>>
>> ----x-----------x---
>>
>> I would like the caption of the table to point to the image, at the point
>> where the word "plot" is located, in LaTeX export of the org file.
>>
>> Any help or other workarounds are appreciated. I am using org version
>> 9.0.3 in GNU Emacs 24.5.1.
>>
>> Thanks for your help and regards,
>>
>> Shripad
>> Tucson, AZ
>>
>>
>>
>>
>>

[-- Attachment #2: Type: text/html, Size: 8018 bytes --]

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

* Re: [Away message] Re: Passing an image reference to source code block
       [not found]       ` <CAJ51ETrvoF=EvRKuAWB77m489EmxmG3KP5FOovpgRpe_qT3XHQ@mail.gmail.com>
@ 2016-12-27 19:18         ` shripad sinari
  0 siblings, 0 replies; 5+ messages in thread
From: shripad sinari @ 2016-12-27 19:18 UTC (permalink / raw)
  To: John Kitchin, Orgmode Mailing List

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

Thanks John,
Setting the variable org-latex-prefer-user-labels to "t" solves the issue.

Regards,

Shripad
Tucson, AZ

On Tue, Dec 27, 2016 at 11:42 AM, John Kitchin <jkitchin@andrew.cmu.edu>
wrote:

> Set a variable like org-latex-prefer-user-labels to t. I am away from my
> computer to look up the actual name but it is something like that.
>
> On Tue, Dec 27, 2016 at 11:12 AM John Kitchin <jkitchin@andrew.cmu.edu>
> wrote:
>
>> I am traveling with limited access to email. I will be back in the office
>> on Jan 2, 2017.
>> John
>>
>>
>> --
>> John
>>
>> -----------------------------------
>> Professor John Kitchin
>> Doherty Hall A207F
>> Department of Chemical Engineering
>> Carnegie Mellon University
>> Pittsburgh, PA 15213
>> 412-268-7803 <(412)%20268-7803>
>> @johnkitchin
>> http://kitchingroup.cheme.cmu.edu
>>
>>
>>
>>
>>

[-- Attachment #2: Type: text/html, Size: 2663 bytes --]

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

* Re: Passing an image reference to source code block
  2016-12-27 18:12   ` shripad sinari
       [not found]     ` <CAJ51ETonOMi3UFfT4QwxUbqqFqed1rit9Z0HA5-Qt1QzARWdKA@mail.gmail.com>
@ 2016-12-27 20:36     ` Nick Dokos
  1 sibling, 0 replies; 5+ messages in thread
From: Nick Dokos @ 2016-12-27 20:36 UTC (permalink / raw)
  To: emacs-orgmode

shripad sinari <shripad.sinari@gmail.com> writes:

> Thanks for the suggestion. The proposed solution does not work since
> the recent org versions generate their own labels and the label
> value cannot be predetermined.

C-h v org-latex-prefer-user-labels RET

-- 
Nick

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

end of thread, other threads:[~2016-12-27 20:36 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-12-27  2:00 Passing an image reference to source code block shripad sinari
2016-12-27 16:05 ` John Kitchin
2016-12-27 18:12   ` shripad sinari
     [not found]     ` <CAJ51ETonOMi3UFfT4QwxUbqqFqed1rit9Z0HA5-Qt1QzARWdKA@mail.gmail.com>
     [not found]       ` <CAJ51ETrvoF=EvRKuAWB77m489EmxmG3KP5FOovpgRpe_qT3XHQ@mail.gmail.com>
2016-12-27 19:18         ` [Away message] " shripad sinari
2016-12-27 20:36     ` Nick Dokos

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).