TikZ libraries in bookdown - r-markdown

I'm building a file that will be compiled to PDF and HTML (gitbook and tufte style), and I'm trying to get my tikzpicture environments working. I've seen that I can include them as figures by using something like
```{r,echo=FALSE,engine='tikz',fig.ext=if (knitr:::is_latex_output()) 'pdf' else 'png'}
\begin{tikzpicture}
CODE HERE
\end{tikzpicture}
```,
but I haven't figured out how to include any extra TikZ libraries when doing this (which would be achieved for LaTeX output by including \usetikzlibrary{decorations}, for example, but in the preamble, not in the body (hence the difficulties)). How can I do this, or is it not possible?

It turns out that you can simply put the \usetikzlibrary{...} command directly before the \begin{tikzpicture} and everything works fine :)

Related

Generating working CHM files using Doxygen and GraphViz (Invalid .hhc file?)

I'm in the middle of documenting my C++ GUI library and I just started using Doxygen. I've got two test files that are documented now, but I have problems when trying to generate the CHM help files. Doxygen runs without error, and dot appears to be functioning correctly to generate images.
However, it appears the resulting .hhc, .hhk, and .hhp files are broken in some way. index.hhc and index.hhk are exactly the same and running 'hhc index.hhp' does not work. It returns an error :
HHC6000: Error: An internal file could not be created. Make certain there is enough disk space on the drive where you are compiling your file.
HHC5007: Error: Fatal navigational compilation error. This is likely the result of an invalid contents (.hhc) file.
I have uploaded a zip file of my two test sources, the Doxyfile generated by the Doxy Wizard, and the .hh* files created by doxygen.
http://members.allegro.cc/EdgarReynaldo/temp/test1.zip
Both HTML Help Workshop and GraphViz are on my path.
Do I need to change a setting in the doxyfile? How do I fix this?
Regards, bugsquasher
EDIT
After taking albert 's advice, everything seemed to magically work. Nothing was really different though.

Applying a Patch to a library using MinGW?

There's a similarenter link description here It's on the below link.
I have been given a patch on an email and I need to create a patch file. I have just pasted the contents into a text file and saved it as 'All Files' as file.patch. As far as I can tell this is correct.
This patch will apply to multiple files in a library.
I'm not sure how to apply the patch. I'm guessing that this is done using MinGW but I'm not sure how. I have set the above directory to the library in the command line like this..
cd c:\library
I place the patch file in this libraries base director and write the name of the patch.
file.patch
When I do this (I have tortoise svn installed on my pc) a the patch file opens up with a bunch of colors (Red/Yellor/Green) highlighting some of the text in the file.
Does this mean the patch automatically applies or am I going about this completely the wrong way?
I can't put the patch on the internet but the explanation above is clear.
If I have it all wrong would someone mind explaining how I apply a patch using MinGW on Windows? Thanks

How to add and use .zip (or .pak) files to c++ project?

I'm compiling CEF (Chromium Embedded Framework) for our local html5 presentation.
I should say I'm very new for all this (CEF and C++).
I've already optimized cefclient project for the presentation, but I need to embed all html/js/css/etc files into project (reading from local storage is not an option).
As I understood, I should use .zip or .pak (renamed zip) files to embed. But how can I use them inside the project?
Should I use some lib for unzipping (zlib?) or there is another popular way? And how can I be sure that files will be compiled into project?
Sorry for such basic questions but there are very few information about this (or google hates me today).
Thank you for any help!
UPD: found great tool - WBEA (http://asterclick.drclue.net/WBEA.html), it looks like exactly what I want to, but works pretty slow (with JS).
UPD 2: It turns out that there are many ways to make HTML5 desktop application, for example Node-Webkit.
Here is an article that compares some of them http://clintberry.com/2013/html5-apps-desktop-2013/
You need:
Create zip file whitin your resources.
Embed it as win32 resource (after this step you will get correct executable with .zip file inside).
Create custom scheme handler to access this zip file.
CefZipReader class will be handly to implement handler from step 3.
Look around, may be something like what you want already exist somewhere.
This sounds very similar to self extracting installers.
No need to compile anything, just concatenate the zip to the end of the executable. All you need to do is find the offset at runtime from the start of the executable. This can be done easily by writing a large magic number and looking for it later.
Example Linux:
cat app magic_number data > new_app
Example Windows:
copy app.exe /B + magic.dat /B + data.dat /B new_app.exe

How to convert R Markdown to PDF?

I've previously asked about the commands for converting R Markdown to HTML.
What is a good way to convert R Markdown files to PDF documents?
A good solution would preserve as much as possible of the content (e.g., images, equations, html tables, etc.). The solution needs to be able to be run from the command-line. A good solution would also be cross-platform, and ideally minimise dependencies to make it easier to share makefiles and so forth.
Specifically, there are a lot of options:
Whether to convert RMD to MD to HTML to PDF; or RMD to MD to PDF; or RMD to PDF
If using the markdown package in R, which options to specify
Whether to use pandoc, a package built into R, or something else
Here's an example rmd file that presumably provides a reasonable test of any proposed solution. It was used as the basis for this blog post.
Updated Answer (10 Feb 2013)
rmarkdown package:
There is now an rmarkdown package available on github that interfaces with Pandoc.
It includes a render function. The documentation makes it pretty clear how to convert rmarkdown to pdf among a range of other formats. This includes including output formats in the rmarkdown file or running supplying an output format to the rend function. E.g.,
render("input.Rmd", "pdf_document")
Command-line:
When I run render from the command-line (e.g., using a makefile), I sometimes have issues with pandoc not being found. Presumably, it is not on the search path.
The following answer explains how to add pandoc to the R environment.
So for example, on my computer running OSX, where I have a copy of pandoc through RStudio, I can use the following:
Rscript -e "Sys.setenv(RSTUDIO_PANDOC='/Applications/RStudio.app/Contents/MacOS/pandoc');library(rmarkdown); library(utils); render('input.Rmd', 'pdf_document')"
Old Answer (circa 2012)
So, a number of people have suggested that Pandoc is the way to go. See notes below about the importance of having an up-to-date version of Pandoc.
Using Pandoc
I used the following command to convert R Markdown to HTML (i.e., a variant of this makefile), where RMDFILE is the name of the R Markdown file without the .rmd component (it also assumes that the extension is .rmd and not .Rmd).
RMDFILE=example-r-markdown
Rscript -e "require(knitr); require(markdown); knit('$RMDFILE.rmd', '$RMDFILE.md'); markdownToHTML('$RMDFILE.md', '$RMDFILE.html', options=c('use_xhml'))"
and then this command to convert to pdf
Pandoc -s example-r-markdown.html -o example-r-markdown.pdf
A few notes about this:
I removed the reference in the example file which exports plots to imgur to host images.
I removed a reference to an image that was hosted on imgur. Figures appear to need to be local.
The options in the markdownToHTML function meant that image references are to files and not to data stored in the HTML file (i.e., I removed 'base64_images' from the option list).
The resulting output looked like this. It has clearly made a very LaTeX style document in contrast to what I get if I print the HTML file to pdf from a browser.
Getting up-to-date version of Pandoc
As mentioned by #daroczig, it's important to have an up-to-date version of Pandoc in order to output pdfs. On Ubuntu as of 15th June 2012, I was stuck with version 1.8.1 of Pandoc in the package manager, but it seems from the change log that for pdf support you need at least version 1.9+ of Pandoc.
Thus, I installed caball-install.
And then ran:
cabal update
cabal install pandoc
Pandoc was installed in ~/.cabal/bin/pandoc
Thus, when I ran pandoc it was still seeing the old version.
See here for adding to the path.
I think you really need pandoc, which great software was designed and built just for this task :) Besides pdf, you could convert your md file to e.g. docx or odt among others.
Well, installing an up-to-date version of Pandoc might be challanging on Linux (as you would need the entire haskell-platform˙to build from the sources), but really easy on Windows/Mac with only a few megabytes of download.
If you have the brewed/knitted markdown file you can just call pandoc in e.g bash or with the system function within R. A POC demo of that latter is implemented in the Ṗandoc.convert function of my little package (which you must be terribly bored of as I try to point your attention there at every opportunity).
Right now (August 2014) You could use RStudio for converting R Markdown to PDF.
Basically, RStudio use pandoc to convert Rmd to PDF.
You could change metadata to:
Add table of contents
Change figure options
Change syntax highlighting style
Add LaTeX options
And many more...
For more details - http://rmarkdown.rstudio.com/pdf_document_format.html
For an option that looks more like what you get when you print from a browser, wkhtmltopdf provides one option.
On Ubuntu
sudo apt-get install wkhtmltopdf
And then the same command as for the pandoc example to get to the HTML:
RMDFILE=example-r-markdown
Rscript -e "require(knitr); require(markdown); knit('$RMDFILE.rmd', '$RMDFILE.md'); markdownToHTML('$RMDFILE.md', '$RMDFILE.html', options=c('use_xhml'))"
and then
wkhtmltopdf example-r-markdown.html example-r-markdown.pdf
The resulting file looked like this. It did not seem to handle the MathJax (this issue is discussed here), and the page breaks are ugly. However, in some cases, such a style might be preferred over a more LaTeX style presentation.
Only two steps:
Install the latest release "pandoc" from here:
https://github.com/jgm/pandoc/releases
Call the function pandoc in the library(knitr)
library(knitr)
pandoc('input.md', format = 'latex')
Thus, you can convert your "input.md" into "input.pdf".
I found using R studio the easiest way, but if wanting to control from the command line, then a simple R script can do the trick using rmarkdown render command (as mentioned above). Full script details here
#!/usr/bin/env R
# Render R markdown to PDF.
# Invoke with:
# > R -q -f make.R --args my_report.Rmd
# load packages
require(rmarkdown)
# require a parameter naming file to render
if (length(args) == 0) {
stop("Error: missing file operand", call. = TRUE)
} else {
# read report to render from command line
for (rmd in commandArgs(trailingOnly = TRUE)) {
# render Rmd to PDF
if ( grepl("\\.Rmd$", rmd) && file.exists(rmd)) {
render(rmd, pdf_document())
} else {
print(paste("Ignoring: ", rmd))
}
}
}
If you don't want to install anything you can output html. Then open the html file - it should open in a browser window, then right click to print. In the print window, select "save as pdf" in the bottom right hand corner if you're on a Mac. Voila!
Follow these simple steps :
1: In the Rmarkdown script run Knit(Ctrl+Shift+K)
2: Then after the html markdown is opened click Open in Browser(top left side) and
the html is opened in your web browser
3: Then use Ctrl+P and save as PDF .

Where should I put this .h file, or how can I properly set my path in TextMate?

I'm just getting my feet wet in C++ using the Stanford CS 106B lectures available online. The assignments have the students use some custom libraries which are available for download online, although the installation instructions are gone.
While I can do the assignments in Xcode using a pre-built blank project which includes the relevant files and source trees set up, I also have TextMate on hand and thought I'd like to try coding with it, since I liked using it a lot for coding LaTeX. So far so good.
The first program I'm trying to run (a very simple ten-line program) contains an # include "genlib.h" in the first line. I have the genlib.h file, but can't seem to get either of the following to work:
Add the path to the relevant file in TextMate: When I try to add the path to the folder on my desktop (/previouspathinthelist:/Users/me/Desktop/C++\ libraries) where the file lives I get an error: /Users/me/Documents/c++ programs/powertab.cpp:9:20: error: genlib.h: No such file or directory even though the file is right there! (Maybe I should note here that the file to be imported and the program file are in two different folders).
Add the file to one of the other paths: I can't move the files using mv in terminal to usr/bin, usr/sbin, etc. because it says I don't have the proper permissions.
Is there something I'm doing wrong in setting my path to my folder in Documents? There aren't any spelling mistakes or anything since the path came straight from get info in the finder. I know this is a programming forum and not a TextMate support forum, but I thought it'd be good to know where people generally put these kinds of files on their systems.
Just put the file in the same directory as your other source files.
#include "filename"
searches the source directory first, whereas
#include <filename>
only searches the include file path.
The reason why /previouspathinthelist:/Users/me/Desktop/C++\ libraries doesn't work probably has to do with the space in the file name. It is quite possible that a backslash is not the right way to quote the space in the tool you're using. Many tools from the C/unix tradition deal rather badly with pathnames that contain space (even though the Unix kernel itself has no such problem); often you'll find that there is no single amount of quoting that will simultaneously satisfy all the tools and subsystems that use some setting. Better to avoid spaces in filenames entirely when you're doing development.