tikzjax badly clips when two pictures together - tikz

I am using the tikzjax extension to enable the latex tikz package to be used within a php script. The minimal example below demonstrates the problem. The script <head> uses the information from https://tikzjax.com/. Then follows the exact same tikzpicture except the positioning of the node B in both cases (the second case is the reflection of the first). The problem is the \clip doesn't work in the second case. If the first case is commented out, then it works. Here's a picture of the output from my browser:
The problem is tha the clip seems to follow the same kind of path in the second instance as for the first. How can this situation be solved, could it be a tikzjax bug? Are we not supposed to have more than one such diagram rendered in a php page?
<?php
echo '<head><link rel="stylesheet" type="text/css" href="https://tikzjax.com/v1/fonts.css">
<script src="https://tikzjax.com/v1/tikzjax.js"></script></head>';
echo 'Top node at (0,3)
<script type="text/tikz">
\begin{tikzpicture}
\coordinate (C) at (0,0);
\coordinate (B) at (0,3);
\coordinate (A) at (2,0);
\draw (A)--(B)--(C)--(A);
\begin{scope}
\clip (A)--(B)--(C)--(A);
\draw (0,0.5)--++(0.5,0)--++(0,-1)--++(-1,0)--++(0,1)--++(1,0);
\end{scope}
\end{tikzpicture}
</script>
<br><br>
';
echo 'Top node at (0,-3)
<script type="text/tikz">
\begin{tikzpicture}
\coordinate (C) at (0,0);
\coordinate (B) at (0,-3);
\coordinate (A) at (2,0);
\draw (A)--(B)--(C)--(A);
\begin{scope}
\clip (A)--(B)--(C)--(A);
\draw (0,0.5)--++(0.5,0)--++(0,-1)--++(-1,0)--++(0,1)--++(1,0);
\end{scope}
\end{tikzpicture}
</script>
';
?>

Related

Problem importing Bezier curve coordinates in Matlab from .svg

I'm trying to draw Bezier curves from an .svg file using Matlab.
I've opened the .svg in a text editor. One of the lines I'm trying to draw is this one: <path fill="none" stroke="#000000" stroke-miterlimit="10" d="M117.125,310.375c0-77.729,80.738-140.625,180.515-140.625"/>
If I understand things correctly, the start point is (x , y) (117.125 , 310.375), the first control point is (0 , -77.729), the second control point is (80.738 , -140.625) and the end point is (180.515 , -140.625). However this doesn't seem to be correct as the output I get is far from the actual curve.
How it looks:
How it's supposed to look:
The start and end points are all right, but the control points seem wrong... Matlab draws the correct points, I've checked them (the axis may look a bit weird but it's correct)
I'm using the code from Mathworks (https://blogs.mathworks.com/graphics/2014/10/13/bezier-curves/). It needs the start point pt1, the control points pt2 and pt3 and the end point pt4.
The code works, the problem seems to lie with the coordinates of the points.
I've tried entering the coordinates above in an online .svg editor (it only supports integers so every coordinate is positive here, the control points shouldn't 'pull' the curve that much but the output is the same as the one obtained with MatLab): http://www.useragentman.com/tests/textpath/bezier-curve-construction-set.html#path=M%20297%2C%20169%20C%2058%2C%200%2C%2098%2C%2077%2C%2098%2C%20192&imageURL=http://www.useragentman.com/tests/textpath/images/grid.png
Here is the entire file, created with Illustrator CS6:
<?xml version="1.0" encoding="utf-8"?>
<!-- Generator: Adobe Illustrator 16.0.4, SVG Export Plug-In . SVG Version: 6.00 Build 0) -->
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
width="595.28px" height="841.89px" viewBox="0 0 595.28 841.89" enable-background="new 0 0 595.28 841.89" xml:space="preserve">
<line fill="none" stroke="#000000" stroke-miterlimit="10" x1="116.083" y1="608.292" x2="117.125" y2="310.375"/>
<path fill="none" stroke="#000000" stroke-miterlimit="10" d="M117.125,310.375c0-77.729,80.738-140.625,180.515-140.625"/>
<path fill="none" stroke="#000000" stroke-miterlimit="10" d="M297.64,169.75c58.959,0,98.652,77.535,98.652,192.708"/>
<line fill="none" stroke="#000000" stroke-miterlimit="10" x1="396.292" y1="362.458" x2="387.958" y2="653.083"/>
</svg>
I'm really hoping someone can help me with this. I'm new to .svg
Thanks to #Paul LeBeau for the link. It turns out ".svg"s are case sensitive and that a C is not a c... You learn things every day. The website I looked at for help before I posted didn't mention this.
2, 3 and 4 are all relative to 1 in this case. I added a few lines of code to my script so that 2 = 1 + 2relative, 3 = 1 + 3relative and 4 = 1 + 4relative, and it works!
Now I can finally clean up my code to do both the lines and the paths at the same time and draw my racing line.
NB: I know the points are reversed for the purple curve. This is due to Illustrator not being able to do a curve "the other way round" without switching the points...

Issue Matlab EPS figures

I have a problem when I create a EPS figure which I want to include in Latex. Somehow I am unable to place a caption above the figure created with Matlab. It gets overwritten by whitespace. I have created a minimum working example. The figure in matlab is created according the following code:
plot(1:10)
title('A line')
print('test','-depsc2')
And the corresponding latex file:
\documentclass[a4paper]{article}
\usepackage{graphicx}
\begin{document}
\begin{figure}[h]
\caption{Caption is overwritten}
\includegraphics[width=\textwidth]{test.eps}
\end{figure}
\end{document}
No caption is visible in the output pdf. I am a dvi-ps-pdf chain.
It seems to be an issue with the bounding box values. If I add go to the draft mode of graphicx (\usepackage[draft]{graphicx} ) the caption appears.
Thanks for any help.
Best, Rob
Try the clip option in includegraphics:
\includegraphics[width=\textwidth, clip]{test.eps}
You may also want to include some vertical space between caption and figure:
\caption{Caption is overwritten}
\vspace{5mm}
\includegraphics[width=\textwidth, clip]{test.eps}

rmarkdown vector graphics for knit word

When using rmarkdown with knitr in Rstudio to knit a Microsoft Word document, the graphics generally look crappy because the usual vector graphics formats, such as PDF are not supported in Microsoft Word.
Fortunately, the devEMF package in R generates the microsoft vector format EMF, and I almost have this working for my rmarkdown application. The problem is that my image is showing up way too small. How can I control the image size?
I've tried the standard things below:
---
title: "Plot size trouble demo"
author: "for stackoverflow"
output: word_document
---
Here I include graphics in a word document using the `emf` printing device.
```{r dev = 'emf', fig.ext = 'emf'}
require(devEMF)
plot(1:10, 1:10)
```
The plot is small, so I try to make it bigger with the `fig.height` and fig.width` options:
```{r dev='emf', fig.ext='emf', fig.height=10, fig.width=10}
require(devEMF)
plot(1:10, 1:10)
```
The plot region stayed the same size, and now I have super-small labels and points!
Finally, I try to use the `out.width` and `out.height` options to rescale the figure to a different size, but this produces nothing at all:
```{r dev='emf', fig.ext='emf', fig.height=10, fig.width=10, out.width = '5in', out.height= '5in'}
require(devEMF)
plot(1:10, 1:10)
```
Update: I noticed here that rmarkdown supports win.metafile, but the following also produces nothing:
```{r dev = 'win.metafile', out.width = '5in', out.height= '5in'}
plot(1:10, 1:10)
```

Javafx Scene Builder Linear Gradient is what

is there any one knows what on earth is the linear gradient?
How Can I use the right panel, especially the four scroll bar, to adjust the fill of the triangle on the left to make the triangle upper half white but down half black?
Is there any document to help train people how to use this? I am really sorry I can not find it.
Thanks in advance!
General info on linear gradients
The linear-gradient documentation is at:
JavaFX CSS reference.
It is a w3c color stop form.
javadoc of how linear gradients work in JavaFX.
Because the linear gradient in JavaFX CSS is the same syntax as w3c CSS, any tutorial on CSS linear gradients returned by google will probably apply to JavaFX CSS.
Feedback email address for JavaFX documentation is: javasedocs_us#oracle.com
Linear Gradients and SceneBuilder
Scene Builder uses FXML to represent linear gradients. It can also use render linear gradients from CSS, though the gradient editor in SceneBuilder works to edit the FXML representation of gradients and not the CSS representation.
Here is a result of loading the following FXML file into SceneBuilder:
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.paint.*?>
<?import java.lang.*?>
<?import javafx.scene.shape.*?>
<Polygon xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1">
<points>
<Double fx:value="-50.0" />
<Double fx:value="40.0" />
<Double fx:value="50.0" />
<Double fx:value="40.0" />
<Double fx:value="0.0" />
<Double fx:value="-60.0" />
</points>
<fill>
<LinearGradient startX="0.5" startY="0" endX="0.5" endY="1">
<stops>
<Stop color="WHITE" />
<Stop color="BLACK" offset="1.0" />
</stops>
</LinearGradient>
</fill>
</Polygon>
Scroll Bar Settings
The scroll bar settings are marking the proportional co-ordinates of the start and end properties of the linear gradient. These co-ordinates from a directional vector (line) along which colors in the linear gradient change according to the defined stops. The bars work as follows:
left bar: startY
top bar: startX
right bar: endY
bottom bar: endX
For the above fill, it means start at the top center and travel to the bottom center, varying the color from white to black as you go, so it's a straight top to bottom vertical transition.
Discrete Gradients
If you didn't want a smooth gradient, but instead wanted an abrupt one, then add more stops, for example:
<fill>
<LinearGradient endX="0.5" endY="1" startX="0.5" startY="0">
<stops>
<Stop color="WHITE" />
<Stop color="WHITE" offset="0.5"/>
<Stop color="BLACK" offset="0.5" />
<Stop color="BLACK" offset="1.0" />
</stops>
</LinearGradient>
</fill>

How to Control Margin of R Plot in Sweave Using Eclipse with Yap (.dvi)?

I'm having an issue with TeXlipse where I'm generating a plot in Eclipse via Sweave, and the TeX file seems to be jamming all of my PDF plots in the left most corner of the page. This is driving me crazy. I'm not sure what SweaveOpts might fix this, but \oddsidemargin, \evensidemargin, \begin{centering}, and \SweaveOpts{width=x, height=y} does not help. My code is below:
Sweave Code:
\documentclass{article}
\usepackage{Sweave}
\usepackage{graphicx}
\SweaveOpts{prefix.string=C:/SweavePlots/bar}
\DeclareGraphicsExtensions{.pdf}
...
\begin{figure}
\begin{center}
<<figname, fig=TRUE, include=TRUE, echo=FALSE>>=
plot(1:10)
#
\caption{I hope this Works}
\end{center}
\end{figure}
TeX Code:
\begin{figure}
\begin{center}
\includegraphics{C:/SweavePlots/bar-figname}
\caption{I hope this Works}
\end{center}
\end{figure}
Resultant Figure:
I found out that since the more recent versions of R only produce PDFs and I'm trying to use DVI, I need to explicitly set \SweaveOpts{eps=true}. The bottom line is that PDF images just don't get along well with DVI viewers like Yap. My successful code is as follows:
%
\documentclass{article}
\usepackage{Sweave}
\usepackage{graphicx}
\SweaveOpts{prefix.string=C:/SweavePlots/bar}
\SweaveOpts{eps=true}
\DeclareGraphicsExtensions{.eps}
\title{SweavePlotWithEPS}
\author{user992432}
\begin{document}
\maketitle
\begin{figure}
\begin{center}
<<figname, fig=TRUE, include=TRUE, echo=FALSE>>=
plot(1:10)
#
\caption{I hope this Works}
\label{fig:one}
\end{center}
\end{figure}
\end{document}