I have a bar graph, and I am using text() to display fractions above each of the bars. For example:
text(1, 20, "300/400")
displays the string "300/400" at position (1,20).
I would now like to prettify the fractions so that "300" appears over the "400":
300
---
400
Is there a way to do this, eg with tex or latex?
I tried each of these, but the interpreter is not getting called:
text(1, 20, '\frac{300}{400}');
text(1, 20, '\frac{300}{400}', 'interpreter', 'tex');
text(1, 20, '\frac{300}{400}', 'interpreter', 'latex');
It looks like it's not yet possible in Octave. The TeX interpreter doesn't support the \frac structure, and the LaTeX interpreter isn't yet implemented.
http://www.network-theory.co.uk/docs/octave3/octave_172.html
Related
For better or worse, I don't use LaTeX (yet). I like producing stargazer formatted tables on the fly for class examples in both HTML and in the console. However, I'm having trouble with 3 formatting elements; so far I've found solutions for LaTeX and some in HTML, but the ASCII console text eludes me.
The 3 challenges are:
Breaking a line so that a variable name can wrap instead of increasing the table width.
Aligning coefficients & std. errors at the decimal, even when there are p-value stars.
Making space in the covariate labels & coefficients to allow for a reference group.
Let's start with some reproducible data & outputs to reference.
set.seed(3); x1 <- factor(sample(letters[1:4], 1000, replace=TRUE))
set.seed(4); x2 <- runif(1000, -10, 10)
set.seed(5); x3 <- rbinom(1000, size = 1, prob = 0.13)
set.seed(6); y <- runif(1000, -10, 10)
model <- (lm(y ~ x1 + x2 + x3))
stargazer(model, align=TRUE,
#type="html", out="SO_stargazer.html",
type="text", out="SO_stargazer.txt",
title="Example Title Goes Here",
dep.var.caption="",
dep.var.labels="This is my long title for the Dependent Variable Y",
covariate.labels=c("X1 Group B",
"X1 Group C",
"X1 Group D",
"X2 with a super ridiculous and annoyingly long name",
"X3"))
Line break
My default approach is to use \n in the character string. For example, I might try to break the DV caption:
dep.var.labels="This is my long title for \n the Dependent Variable Y",
But that generates the following error message:
Error in if (nchar(text.matrix[r, c]) > max.length[real.c]) { : missing value where TRUE/FALSE needed
Found a couple posts about this issue (here which reference here), but the poster on the first did not provide much of an example to follow and the second pertained to an underscore that I don't have or gave LaTeX solutions. The only difference that broke what already worked was the addition of the \n. I did try using the tex \\ escape, but that didn't do anything useful for text output.
I am able to get line breaks using <br> in the string for the html output file version.
This post also mentions the tex and html solutions, but not text.
Alignment on the decimal
When there are no statistical significance stars on coefficients, both the coefficients and std. errors align nicely, centered on the decimal point. However, once the stars appear, it 'pushes' the coefficient to the left. This happens in both the text and html output. This is not so bad with 1 star, but 3 stars can be quite a difference. How can I coerce it back to align on the decimal value for both formats? This issue persists even if I use the single.row=TRUE option. This post answer by #Marco Doe has a great visual of what I'm talking about, but noted the centering is for tex. Found a LaTeX solution, but no mention of the other formats on that post. I've tinkered with the align and float options to no avail (inspired by these quasi-related tex solution posts here and here). The latter post hinted at using xtable or post-process edits, but that was more than 5 years ago; so I'm hoping for an updated viable solution.
This image is from Marco Doe's solution and shows the LaTeX output, but does a good job showing an example output formats I get (left) and what I would like to have (right).
Reference categories
Found a LaTex solution, that 'pushes' the covariates & coeffient data down a row, making room for a reference group to be printed in the covariate column; however, the solution is in tex. How can I replicate this for the text output? Can I replicate it for HTML version as part of the R code without having to get surgical with the HTML output code?
#Giac posted the images (linked above) to illustrate the have (left) and want (right). Although these images are tex, how could I get the right image output in text and html?
I have a text block as a string that contains some SI units and equations. How can I for example use superscript numbers (e.g. 10^-10 m^2) and math equations in strings? Greek letters and e.g. the ± symbol work fine.
from pylatex import Document, Section, Subsection, Command, Figure
from pylatex.utils import italic, bold, NoEscape
doc = Document('Test', geometry_options = {"head": "2cm","margin": "2cm","bottom": "2cm"})
with doc.create(Section('Header 1')):
doc.append('The average area is less than 10m^2 (±0.5m^2).')
doc.generate_pdf(clean_tex = False,compiler='pdflatex')
I also wonder how I can define the line spacing (linespread) in pylatex.
Something's been puzzling me for the better half of a workday now: What's actually going on during markdown to HTML conversion in Dita when I try to keep brackets intact.
Specifically, this is my original markdown:
1. Value[:, :]
Which should be written as-is in HTML. However, looking at the HTML element produced by Dita:
<li class="li">
<p class="p">
Value
<span class="xref"></span>
</p>
</li>
Expected output:
<li class="li">
<p class="p">
Value[:, :]
</p>
</li>
Which means the brackets are interpreted as an external references (?)
I produce my markdown to HTML conversion in dita CLI, version 3.1.2 (windows 10), with the following command:
dita --input=root.ditamap --output=./output --format=html5
The root.ditamap simply contains a single topic that is my markdown file.
I tried at the following first:
1) Using \ to escape the string, results in:
1. Value\[:, :\]
2) using html entity in-place of brackets ([ and ]) results in: 1. Value:, :
3) using UTF code in-place of brackets ([ and ]) results in:
1. Value:, :
Then I tried to add more brackets there and it worked!
4) Markdown that worked: 1. Value[[]:, :[]] produced expected output 1. Value[:, :]
My question(s):
1) Which of the three pieces is responsible for this behaviour: Markdown, Dita or HTML? (with this behaviour I mean the interpretation of brackets in a way that made them disappear during the original conversion).
2) Is there a "better"/"universal" way to escape strings in markdown -> html by dita? (By better way I mean something that will leave the original markdown's string meaning the same, and by universal I mean something that can be applied to all strings not only brackets)
At the very least I hope my findings will be useful to someone, even though I realize my use-case is very specific. :)
---
title: '1'
author: "A"
date: "April 4, 2017"
output: html_document
---
Figure 3 includes the residual plot and QQ-plot. The residual plot have no obvious pattern: the expect value of residuals is close to 0 and the variances are approximately equal. The QQ-plot shows the standardized residuals are close to the theoretical quantiles. Thus, **the residuals are normally distributed and homoscedastic, and the assumption of the liner model is satisfied**. The VIF values for each variable in the best model is small, indicating **there are no obvious multicolinearity**.
Use the above code for example, as it shows in the picture, the second line and third line are aligned to the left by default.
What should I do if I want to align to both sides? (Notice: not align to the center!)
Text Justification in Rmarkdown word document gives the solution for word output case, but I haven't found a good reference for html case.
Just overwrite the alignment right after the YAML:
---
title: '1'
author: "A"
date: "April 4, 2017"
output: html_document
---
<style>
body {
text-align: justify}
</style>
Figure 3 includes the residual plot and QQ-plot. The residual plot have no obvious pattern: the expect value of residuals is close to 0 and the variances are approximately equal. The QQ-plot shows the standardized residuals are close to the theoretical quantiles. Thus, **the residuals are normally distributed and homoscedastic, and the assumption of the liner model is satisfied**. The VIF values for each variable in the best model is small, indicating **there are no obvious multicolinearity**.
Credits to Guilherme Parreira, here
I know there are HTML entities for 1/2, 1/4, and 3/4, but are there others? Like 1/3 or 1/8? Is there a good way to encode arbitrary fractions?
how about 15⁄16? (<sup>15</sup>⁄<sub>16</sub>)
1/2 → ½ or ½
1/4 → ¼ or ¼
3/4 → ¾ or ¾
1/8 → ⅛ or ⅛
3/8 → ⅜ or ⅜
5/8 → ⅝ or ⅝
7/8 → ⅞ or ⅞
1/3 → ⅓
2/3 → ⅔
1/5 → ⅕
2/5 → ⅖
3/5 → ⅗
4/5 → ⅘
1/6 → ⅙
5/6 → ⅚
...but you could also encode them as decimals: 15/16 = 0.9375 ;)
For the existing fractions as Unicode codepoints (which are mapped to by HTML entities), search for "vulgar fraction" in the Unicode Character Names Index.
Now, for generic fractions, which work in HTML but also work in plain text, use the super- and subscript digits (see Unicode Codepoint Chart, search for "Superscripts") separated by the fraction slash character.
Your example implemented as above:
¹⁵⁄₁₆
Isn't just 15/16ths alright? Or even 15/16ths (15/16<sup>ths</sup>)?
For more complex scenarios there is also MathML. The support for this is slowly getting better. Internet Explorer seems to lag behind with this as well.
There is also a standard called MathML. But is for XML unfortunately. However if you have more expressions you might consider switching to basic XML.
This would depend on your exact needs and audience.
For most purposes many methods would be appropriate.
15/16, 15 parts of 16, 93.75%, 15/16 all mean the same,
you might even use symbols like
++++++++++++++-
For some more complex scenarios you will need more complex solutions more like LaTeX than html. I believe there are also server side components that take LaTeX descriptions and create images that are browser compatible, such as described here: http://www.fauskes.net/nb/htmleqII/
In HTML, this can be done with Unicode code 2044, preceded by &#x and ending with a semicolon. The whole thing is placed between the numerator and the denominator.
For instance, with this solution, 15 divided by 16 in HTML is rendered like this: 15⁄16
This works for combinations of integers acting as numerators and denominators.