Comments (6)
I think I would try using a different engine for the chunks you are referring to in different languages: http://rmarkdown.rstudio.com/authoring_knitr_engines.html
from thesisdown.
Thank you for your quick answer. I might have poorly expressed my problem and what I wanted to achieve. I do not want to run the code, just display it with syntax highlighting. That's why eval = FALSE
. But thank you for pointing out the bash engine. I'll use that. My problem is: When I use the code above, I see the script file in the PDF output as I want to, but it does not get a caption. It basically looks like that
The TeX output created by it looks like that
\begin{Shaded}
\begin{Highlighting}[]
\KeywordTok{for} \ExtensionTok{foo}\NormalTok{ in (ls bar)}
\KeywordTok{do}
\BuiltInTok{echo} \VariableTok{$foo}
\KeywordTok{done}
\end{Highlighting}
\end{Shaded}
For example, when I use include_graphics - I am aware that this is an R function that creates the figure -
in an R script
```{r img, results="asis", echo=TRUE, fig.cap="A figure", out.width='\\textwidth'}
include_graphics("./figure/afigure.png")
```
the TeX output looks like that
\begin{Shaded}
\begin{Highlighting}[]
\KeywordTok{include_graphics}\NormalTok{(}\StringTok{"./figure/afigure.png"}\NormalTok{)}
\end{Highlighting}
\end{Shaded}
\begin{figure}
\includegraphics[width=\textwidth]{./figure/afigure} \caption{A figure}\label{fig:img}
\end{figure}
What I basically want to achieve is to get a \begin{figure} .. \end{figure}
with a label etc around the \begin{shaded} .. \end{shaded}
part. I thought that this is not an uncommon problem and as I could not find anything on Google I was asking here. The solutions I see at that point are
- Creating an image by hand and including it with include_graphics(). I don't really like that solution as that is error prone especially when the code changes.
- I could probably use a knitr hook and making a new option
echo.asfig
. When this is set, I create the needed TeX before and after the echoed output. Probably the easiest to implement. - I could write an R function like "highlight(sourcefile)" that renders the code (using a tool like prism or highlight) and then includes the figure using
\include_graphics
. That is probably the solution that takes the most effort to implement and creates dependencies to other (platform dependent) tools - prism for example is written in JavaScript and would need nodeJs to run.
Do you have any suggestions on what other options I may have, or have I just overlooked on how to do it in Rmd?
from thesisdown.
Ah, thanks for clarifying. I didn't quite understand. I think your best bet here is a knitr hook. Here is a related example, though it is using the old Rnw format: https://github.com/yihui/knitr-examples/blob/master/074-example-environment.Rnw
from thesisdown.
Thank you. I'll think about it and try around a bit over the next couple of weeks. If I have a solution are you interested in a pull request?
from thesisdown.
Yes, please!
from thesisdown.
This issue has been automatically locked. If you believe you have found a related problem, please file a new issue (with a reprex: https://reprex.tidyverse.org whenever possible) and link to this issue. If a reprex is not applicable, recording a short Loom video showing what you are seeing can go a long way in helping to diagnose problems.
from thesisdown.
Related Issues (20)
- How to add \part ? HOT 2
- thesisdown and quarto HOT 3
- Thesis by ... HOT 1
- Problems in getting front matter, TOC and headings right when adapting bookdown/thesisdown to local university LaTeX template
- Unable to use single quotes in abstract.Rmd HOT 2
- apostrophe โ in the abstract file is rendered as รขโฌโข HOT 3
- Failing to knit in times new roman HOT 2
- italics and accented vowels in prelims HOT 1
- Thesis by ... HOT 1
- How to cite? HOT 3
- How do I remove the "Approved for the division page" without running into an error? HOT 1
- Landscape pages HOT 4
- chapter bibliographies using thesisdown? HOT 1
- DOI overstretching in references HOT 8
- Page header: overlap between page and "Chapter X" HOT 3
- dynamic placement of LoF and LoT? HOT 3
- Chapter bibliography rendering incorrectly in HTML for final chapter HOT 3
- speed things up HOT 1
- Is it possible to split the RMD output per each section? HOT 3
- Is it possible to use officedown functionalities within thesisdown? HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. ๐๐๐
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google โค๏ธ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from thesisdown.