sebastiansauer / yart

RMarkdown Template for writing PDF reports
89 stars 19 forks source link

Image references #10

Closed MAlexGR closed 6 years ago

MAlexGR commented 6 years ago

Hello guys!

There are some problems I faced using yart and specifically referencing images. I was trying to use the following code chunk to insert an image.:

```{r fig1, echo = TRUE, eval = FALSE, fig.cap = "Example of a figure", out.width = "30%"}
knitr::include_graphics("figure-name.npg")
```

According to Sebastians demo .Rmd file, images can be inserted this way and also can be referenced too. According to Knittr-Pandoc concept, references to images inserted like this, have to follow the \@ref(figure-label) syntax, where figure-label generated automatically by chunk label and fig: prefix (in this case figure-label is automatically constructed as fig:fig1).

I did follow all the above but I wasn't able to reference my image. After every compilation the actual reference I got was something like As we can see in Picture \@ref(figure-label)... (and not the expected As we can see in Picture 1...).

I did a (lot of) search (in case I didn't got it right) and did follow instructions, tips etc I found. But nothing, always the same results. Finally I came accross the same issue here to find that I have to manually label the image, like:

```{r fig1, echo = TRUE, eval = FALSE, fig.cap = "\\label{fig:fig1}Example of a figure"}, out.width = "30%"}
knitr::include_graphics("figure-name.npg")
```

and then reference to it using \label{fig:fig1}. Note the raw LaTeX syntax in both chunk options (for image caption) and the reference one (without @ character and curly brackets)

I'm opening this issue first to ask if I'm doing something wrong (or ask for any tip) and secondly to report a possible solution (in case someone else faces the same problem).

Yours Alex.

sebastiansauer commented 6 years ago

Hi @MAlexGR,

try \ref(fig:fig1) instead of \@ref(fig1).

Eg:

Figures

Use knit to insert images. Figures can be referenced, cf. Figure \ref{fig:fig1}. Alternatively, use R code to plot figures.

#knitr::include_graphics("../docs/picture2.png")
plot(mtcars$hp)

HTH!

MAlexGR commented 6 years ago

Hello @sebastiansauer

Sorry for the late reply! I tried it but didn't work. I don't know what's going wrong but I'll figure it out. Anyway I think I'll use the LaTeX notations for now as I'm a bit familiar with it's basics.

I know I can plot figures with R but now I need to insert some "ready-made" figures for a report (some paintings).

There still remains a major issue for me (and I think the answer to this will solve a lot of my prombems with yart): how can I fine tune the output .tex file. So far, every time I'm trying to change anything on it, it returns to its original setup, after compilation. I don't understand how yart is structured. But this will be a future issue.

Thank you for the advise!

sebastiansauer commented 6 years ago

Hi Alex,

have a look in the tex-template of yart (easiest way is probably to download or folk the whole folder from github), there you will find that a number of markdown/pandoc variables are woven in the tex template. One compiled to tex, you have a tex file that you can adapt to your wishes. Then take your adopted tex file and compile it to pdf.

Best Sebastian

 

Am 11. Mai 2018 um 20:59:52, MAlexGR (notifications@github.com) schrieb:

Hello @sebastiansauer

Sorry for the late reply! I tried it but didn't work. I don't know what's going wrong but I'll figure it out. Anyway I think I'll use the LaTeX notations for now as I'm a bit familiar with it's basics.

I know I can plot figures with R but now I need to insert some "ready-made" figures for a report (some paintings).

There still remains a major issue for me (and I think the answer to this will solve a lot of my prombems with yart): how can I fine tune the output .tex file. So far, every time I'm trying to change anything on it, it returns to its original setup, after compilation. I don't understand how yart is structured. But this will be a future issue.

Thank you for the advise!

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or mute the thread.

MAlexGR commented 6 years ago

Hi Sebastian

Thank you for your suggestion. I already did this (I test the produced .tex file in a LaTeX environment - Texstudio) and I can say it works fine. But this drives me back to pure LaTeX editing, something I was trying to avoid throught Rstudio.

I did use LaTeX in the past and had perfect results but in exchange of too much time spend (it is true LaTeX gives superior control over the output but needs a lot of search and "pick-and-try" effort). On the other hand, Rstudio gives (in my opinion) a better flexibility and balance, over the effort needed for the final product (I mean the output pdf, wich is my aim). I need a much less time to spend to produce what I need (just some YAML options, some LaTeX commands in "preable.tex" and ... voila! -plus it's reproducible!).

So I was trying to experiment with Rstudio-Knitr-Pandoc chain to produce some templates that can fill my needs. And then I faced your YART, which is almost perfect for me. By "almost" I mean that there still are some details I need to adjust (for example I don't need so much margin space, I need to add some more details in cover page and rearrange the existing ones, I don't need colored footnotes but, yes I need colored citations etc). For the time, I manage to do all this stuff by renewing and overiding your commands throught my "preable.tex" and this is not the correct approach.

Summing up, what I meant in my last post was that I need, somehow, a way to "adjust", "fine tune", "configure" (name it), your YART's source parameters (I explained before in wich direction). So far, when I need a pdf document based on YART (again, because I like its simplicity and completeness), I follow the procedure "File">"New File">"R Markdown">"from Template">"Yart" and I suppose you understand that, this doesn't give me much control. Moreover, I didn't find any quide of how it works.

So, I hope I described correctly and accurately what I meant. I understand that time is precious for you, so there is no need to answer to this mail. I'm just explain what I meant.

I ask for apologies for this extensive mail.

Yours Alex

https://www.avast.com/sig-email?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail Απαλλαγμένο από ιούς. www.avast.com https://www.avast.com/sig-email?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail <#DAB4FAD8-2DD7-40BB-A1B8-4E2AA1F9FDF2>

2018-05-14 10:30 GMT+03:00 Sebastian Sauer notifications@github.com:

Hi Alex,

have a look in the tex-template of yart (easiest way is probably to download or folk the whole folder from github), there you will find that a number of markdown/pandoc variables are woven in the tex template. One compiled to tex, you have a tex file that you can adapt to your wishes. Then take your adopted tex file and compile it to pdf.

Best Sebastian

Am 11. Mai 2018 um 20:59:52, MAlexGR (notifications@github.com) schrieb:

Hello @sebastiansauer

Sorry for the late reply! I tried it but didn't work. I don't know what's going wrong but I'll figure it out. Anyway I think I'll use the LaTeX notations for now as I'm a bit familiar with it's basics.

I know I can plot figures with R but now I need to insert some "ready-made" figures for a report (some paintings).

There still remains a major issue for me (and I think the answer to this will solve a lot of my prombems with yart): how can I fine tune the output .tex file. So far, every time I'm trying to change anything on it, it returns to its original setup, after compilation. I don't understand how yart is structured. But this will be a future issue.

Thank you for the advise!

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or mute the thread.

— You are receiving this because you modified the open/close state. Reply to this email directly, view it on GitHub https://github.com/sebastiansauer/yart/issues/10#issuecomment-388722660, or mute the thread https://github.com/notifications/unsubscribe-auth/AlDlSxJ3JWPcQ_9fGZI-20yGDUwi3UQtks5tyTKPgaJpZM4T3KEv .

sebastiansauer commented 6 years ago

Hi Alex,

I just added some formatting options to the yaml header, such as those to control paper size or margin. I'll push the new version 0.1.14 in a minute.

Sebastian

Am 16. Mai 2018 um 22:17:14, MAlexGR (notifications@github.com) schrieb:

Hi Sebastian

Thank you for your suggestion. I already did this (I test the produced .tex file in a LaTeX environment - Texstudio) and I can say it works fine. But this drives me back to pure LaTeX editing, something I was trying to avoid throught Rstudio.

I did use LaTeX in the past and had perfect results but in exchange of too much time spend (it is true LaTeX gives superior control over the output but needs a lot of search and "pick-and-try" effort). On the other hand, Rstudio gives (in my opinion) a better flexibility and balance, over the effort needed for the final product (I mean the output pdf, wich is my aim). I need a much less time to spend to produce what I need (just some YAML options, some LaTeX commands in "preable.tex" and ... voila! -plus it's reproducible!).

So I was trying to experiment with Rstudio-Knitr-Pandoc chain to produce some templates that can fill my needs. And then I faced your YART, which is almost perfect for me. By "almost" I mean that there still are some details I need to adjust (for example I don't need so much margin space, I need to add some more details in cover page and rearrange the existing ones, I don't need colored footnotes but, yes I need colored citations etc). For the time, I manage to do all this stuff by renewing and overiding your commands throught my "preable.tex" and this is not the correct approach.

Summing up, what I meant in my last post was that I need, somehow, a way to "adjust", "fine tune", "configure" (name it), your YART's source parameters (I explained before in wich direction). So far, when I need a pdf document based on YART (again, because I like its simplicity and completeness), I follow the procedure "File">"New File">"R Markdown">"from Template">"Yart" and I suppose you understand that, this doesn't give me much control. Moreover, I didn't find any quide of how it works.

So, I hope I described correctly and accurately what I meant. I understand that time is precious for you, so there is no need to answer to this mail. I'm just explain what I meant.

I ask for apologies for this extensive mail.

Yours Alex

https://www.avast.com/sig-email?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail Απαλλαγμένο από ιούς. www.avast.com https://www.avast.com/sig-email?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail <#DAB4FAD8-2DD7-40BB-A1B8-4E2AA1F9FDF2>

2018-05-14 10:30 GMT+03:00 Sebastian Sauer notifications@github.com:

Hi Alex,

have a look in the tex-template of yart (easiest way is probably to download or folk the whole folder from github), there you will find that a number of markdown/pandoc variables are woven in the tex template. One compiled to tex, you have a tex file that you can adapt to your wishes. Then take your adopted tex file and compile it to pdf.

Best Sebastian

Am 11. Mai 2018 um 20:59:52, MAlexGR (notifications@github.com) schrieb:

Hello @sebastiansauer

Sorry for the late reply! I tried it but didn't work. I don't know what's going wrong but I'll figure it out. Anyway I think I'll use the LaTeX notations for now as I'm a bit familiar with it's basics.

I know I can plot figures with R but now I need to insert some "ready-made" figures for a report (some paintings).

There still remains a major issue for me (and I think the answer to this will solve a lot of my prombems with yart): how can I fine tune the output .tex file. So far, every time I'm trying to change anything on it, it returns to its original setup, after compilation. I don't understand how yart is structured. But this will be a future issue.

Thank you for the advise!

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or mute the thread.

— You are receiving this because you modified the open/close state. Reply to this email directly, view it on GitHub https://github.com/sebastiansauer/yart/issues/10#issuecomment-388722660, or mute the thread https://github.com/notifications/unsubscribe-auth/AlDlSxJ3JWPcQ_9fGZI-20yGDUwi3UQtks5tyTKPgaJpZM4T3KEv .

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or mute the thread.