Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for tikzscale package, remove extra whitespace #975

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Add support for tikzscale package, remove extra whitespace #975

wants to merge 2 commits into from

Conversation

ilia-kats
Copy link

This patch adds support for the tikzscale package, making it possible to generate tikz plots with external=FALSE while still being able to scale them to the desired size. In addition, several linebreaks in the generated LaTeX code are commented out, as they led to extra whitespace being inserted before the plot, which is very annoying when trying to have multiple plots in one figure using the subfig package.

@yihui
Copy link
Owner

yihui commented Mar 15, 2015

Thanks, but why not just insert \usepackage{tikzscale} in your LaTeX preamble? I do not quite see the point of adding this automatically to all LaTeX documents.

@ilia-kats
Copy link
Author

You need to use \includegraphics in order for tikzscale to do its thing,
and the knitr behaviour up until now was to use \input when
external=FALSE. And if we now use \includegraphics for plain tikz files
we also need to automatically include tikzscale in the preamble.

@yihui
Copy link
Owner

yihui commented Mar 15, 2015

I see. I think the resize.width/resize.height options were designed for rescaling \input{foo.tikz}, although this is the first time I have seen they could be useful to a real user. Here is a minimal example:

\documentclass{article}
\usepackage{tikz}
\begin{document}

<<foo, dev='tikz', external=FALSE, resize.width='.7\\textwidth'>>=
plot(1:10)
@

\end{document}

Is there a reason why you prefer external=FALSE? It makes use of your LaTeX preamble, and makes it faster to compile the document when cache=TRUE.

@yihui yihui added this to the v1.10 milestone Mar 15, 2015
@ilia-kats
Copy link
Author

The difference between resize.width and tikzscale is that resizewidth
also scales the fonts, while tikzscale keeps the fontsize constant and
just scales everything else. So if I get my graphics device size close
to what I want as final size, I can use tikzscale for finetuning using
''.7\textwidth'' or somesuch. This is also the reason why I prefer
external=FALSE, this way the fonts get rendered with the settings of the
environment the figure is in, not just the global settings.

@ilia-kats
Copy link
Author

Oh, and as far as speed, goes, I found a workaround to make tikzexternalize work, so that's not an issue. Briefly:

\usetikzlibrary{external}
\ifx\iftikzinternalcomputation\undefined\tikzexternalize\fi

<<setup, include=FALSE, cache=FALSE>>=
    library(knitr)
    library(tikzDevice)
    options(tikzXelatexPackages = c(
    getOption( "tikzXelatexPackages" ),
    "\\newif\\iftikzinternalcomputation",
    "\\tikzinternalcomputationtrue"
    ))
@

@yihui yihui modified the milestones: v1.10, v1.11 Apr 26, 2015
@yihui yihui modified the milestones: v1.10.5, v1.11 May 13, 2015
@yihui yihui force-pushed the master branch 2 times, most recently from 560c398 to 7561a3f Compare July 25, 2015 02:41
@yihui yihui modified the milestones: v1.11, v1.12 Aug 14, 2015
@yihui yihui modified the milestones: v1.12, v1.13 Jan 13, 2016
@yihui yihui modified the milestone: v1.12.3 Jan 23, 2016
@CLAassistant
Copy link

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants