I am using GNUPlot 4.7 on Windows with the epslatex terminal. Using latex commands in labels in single quotes works fine. Now I'd like to plot a datafile with a text column including latex commands using the labels plotting style in gnuplot:
data.txt
"\textalpha\n Ge" 0.6 1.05
"\textalpha\n Si" 1.09 0.7
"\ce{GaAs}" 1.43 1.05
Plotting command:
plot 'data.txt' u (column(2)):(column(3)):(column(1)) axes x2y1 w labels center offset 0,1 notitle
However, in the resulting tex file the backslashes and immediately following charakters are missing because they were parsed by GNUPlot. How can I make GNUPlot use the unchanged text within the quotes for its labels? I have tried with no success:
single quotes, both alone and nested within the double quotes
double backslashes
escaping the backslashes using $\ or $\\
using curly brackets within or instead of the double quotes
You need four backslashes to escape one: use "$\\\\alpha$" in your data file to get $\alpha$ in the tex file. Don't ask me why. Out of curiosity, you're plotting what against band gap?
Related
I'm using latex to model a few functions using Z-Notation, however, I'm having issues showing a string for output. In this reduced example code, the text in the quotes has a different formatting from what I would expect. What can I use to keep the formatting the text inside the quotes to be the same in the code snippet?
Edit: The overDraftMessage should be messageOutput, missed changing this when creating a reduced example.
\documentclass{article}
\usepackage{oz} % oz or z-eves or fuzz styles
\begin{document}
\begin{schema}{function}
messageOutput!: $STRING$ \\
\where
messageOutput! = ''Output looks strange.'' \\
\end{schema}
\end{document}
Solution from #lburski works, but tilde is not for this purpose. It should be used to make hard space (non-breaking space). To write space in whitespace insensitive environments, you need to escape it - write backslash before every space: ''Output\ looks\ strange''.
If you want a space between the words on your string ''Output looks strange.'' then try putting a tilde '~' between those words. So you string ends up being ''Output~looks~strange.''
I am trying to create a plot in gnuplot with dots over the symbol theta in legend.
I am looking to do something similar to, \dot{\theta} and \ddot{\theta} from latex. However, most posts ask to use 'set term latex' or 'set term epslatex' which outputs a .tex file. I need to keep the output as a pdf with the dot and double dot over the theta in the legend. Is this possible? Appreciate any help. Thanks!
In place of 'Pitch rate', I need the symbol theta with a dot above it.
In place of 'Pitch acceleration', I need the symbol theta with two dots above it.
set term pdf
set termopt enhanced
set encoding utf8
set output "rampfuncs.pdf"
set style func linespoints
set xlabel 'time'
set format y "%.2f"
plot "output.dat" using 1:2 title '{/Symbol q} - Pitch angle', \
"output.dat" using 1:3 title 'Pitch rate', \
"output.dat" using 1:4 title 'Pitch acceleration'
set term x11
Update after answer from meuh: Image for reference
Second update after comments from meuh: Image 2
This is described in the section Enhanced text mode of the gnuplot guide. You can use the ~ tilde character to overprint two items, for example ~a/ will overprint a and /. In your case you need to raise the dot character by 1.1 times the font size (found empirically) in order for it to appear above the a so you prefix the character with this number, and enclose it in braces to make it one item: ~a{1.1.}
plot "data" using 1:2 title '{/Symbol q} angle', \
"data" using 1:3 title '~{/Symbol q}{1.1.} rate', \
"data" using 1:4 title '~{/Symbol q}{1.1..} accel'
which gives this result:
There seems to be a bug where the title will not be shown correctly if the ~{}{} construct is at the end of the title. The simple workaround is to add an extra space at the end of the title ~{}{} .
I'm on German Windows 8.1 64Bit with gnuplot 4.6.5, using the svg terminal. If I plot datafiles that have big numbers, like "one million", gnuplot does not print a digit grouping sign.
For example, if my datafile has values in the order of one million, I want the numbers at the y-axis be displayed as 1.000.000 (with . being the group sign, not the decimal sign!), but gnuplot gives me just 1000000.
The option set decimalsign locale just changes the decimal sign (separator between whole number and fractional part, like 1+1/2 = 1,5 with , being the decimal sign). But neither setting decimalsign nor not calling this command at all shows digit grouping signs in the plot. I only get ugly 1000000 or 1500000 instead of 1.000.000 or 1.500.000.
I also tried
set decimal locale
set format y "%'f"
which just gives me at all tics the label "%'f", instead of the numbers! Each tic has just "%'f", again and again. It just prints the format string as is into the plot and no numbers at all. The console output is decimal_sign in locale is , which is correct for german locale, so gnuplot recognizes it correctly. In my control panel of Windows the thousand separator is set correctly to . and the decimal sign to , too.
Setting tic by tic by hand is no option. I.e. set ytics add ('1.000.000' 1e6) for dozenz of dozenz tics is no option for me.
How do I automatically get thousand separators in gnuplot?
That seems not to work on Windows. From the gnuplot documentation
Internationalization (locale settings): Gnuplot uses the C runtime library routine setlocale() to control locale-specific formatting of input and output number, times, and date strings. The locales available, and the level of support for locale features such as "thousands’ grouping separator", depend on the internationalization support provided by your individual machine.
And judging from questions like How can I add a thousands separator to a double in C on Windows? Printing integers with thousands separators in Windows using C it is not possible since the apostrophe in the format string is a Unix specialty and not a C standard.
I think there is no workaround to get this working on Windows with autoscaling.
For the records: The following script works fine on Linux:
set format "%'.0f"
set xrange [0:1e6]
plot x
Only ., , and are possible as separator (at least Linux). E.g. "french" gives a space:
set decimalsign locale "french" # thousand separator becomes ` `
set decimalsign "."
set format "%'.2f"; # `'` activates the thousand separator
pl [0:1e5] x
Not the most glamorous of solutions, especially if you've got a lot of tics but you could do something like
set ytics ("1.000.000" 1e6, "1.500.000" 1.5e6, etc.)
I'd be interested to hear of anything nicer!
Just for fun and feasibilty... If you absolutely need thousand separators, you can construct a workaround for Windows (with some complexity and limitations). Tested with gnuplot 5.2.6.
Basic recipe:
define a function which converts numbers into text with thousand separators.
set the tic labels yourself using text with thousand separators
place the tic labels by trying to "mimic" gnuplot's setting of tic labels. For this, use gnuplot's suggestions about the scaling by plotting to a dummy terminal first. For this, this post of #Christoph is very helpful.
Code:
### add thousand separators to tic labels for Windows
reset session
# settings for thousand separator
ts = "'" # thousand separator
ThousandSeparator(a,ts) = abs(a)>=1000 ? (TS_a=sprintf("%.0f",a), TS_b=strlen(TS_a), \
TS_c=strstrt(TS_a,'-')+1, TS_d=TS_c>1?'-':'', (sum[TS_i=TS_c:TS_b] \
(TS_d=((TS_b-TS_i)%3==0&&(TS_i<TS_b)?TS_d.TS_a[TS_i:TS_i].ts:TS_d.TS_a[TS_i:TS_i]),\
0), TS_d)) : sprintf("%g",a)
# settings for (auto-)tics
range(axis) = axis eq "y" ? abs(GPVAL_Y_MAX-GPVAL_Y_MIN) : abs(GPVAL_X_MAX-GPVAL_X_MIN)
power(axis) = 10.**int(sprintf("%.15e",range(axis))[strstrt(sprintf("%.15e",range(axis)),"e")+1:])
rangenorm(axis) =range(axis)/power(axis)
posns(axis) = 20.0 / rangenorm(axis)
tics(axis) = \
posns(axis)>40?0.05:posns(axis)>20?0.1:posns(axis)>10?0.2:posns(axis)>4? \
0.5:posns(axis)>2?1:posns(axis)>0.5?2:ceil(range(axis))
ticstep(axis) = tics(axis) * power(axis)
set xrange[0:1e6]
set terminal push # save current terminal
set terminal unknown
plot x lc rgb "web-green"
set terminal pop # restore terminal
# set xtics
do for [i=0:ceil(range("x")/ticstep("x"))+1] {
set xtics add (ThousandSeparator(GPVAL_X_MIN+i*ticstep("x"),"'") GPVAL_X_MIN+i*ticstep("x"))
}
# set ytics
do for [i=0:ceil(range("y")/ticstep("y"))+1] {
set ytics add (ThousandSeparator(GPVAL_Y_MIN+i*ticstep("y"),"'") GPVAL_Y_MIN+i*ticstep("y"))
}
replot
### end of code
Limitations:
if the begin of the axis (e.g. GPVAL_X_MIN) is not identical with the first tic label, the above procedure doesn't work (yet).
However, I haven't yet found the value which gnuplot sets as first tic value. There seems to be no GPVAL_... variable for this. Maybe it can be extracted somehow?
Example 1: (works ok)
set xrange[0:1e6]
Example 2: (doesn't work, because GPVAL_X_MIN=-50000 but first tic should be at 0)
set xrange[-50000:1e6]
The estout command in Stata will always escape underscores if a variable label has such a character. For example, running this after a simple regression and then
qui sum res, d
estadd scalar test = r(mean)
and outputting to a tex file:
esttab using "filename.tex", stats(r2 test, labels("\$R^2\$" "\$T_i\$")) se r2
star(* 0.10 ** 0.05 *** 0.01) label replace fragment nomtitles
coeflabels(_cons "$\alpha\$") nonumbers tex
will create a string $T\_i$ in the filename.tex output. Trying a label \$\beta=char(95)'{HML}\$` results in the same behavior. Apparently, the 'outreg2' command is smart enough to not escape this character if it sees it is in math mode, but estout did not inherit such behavior. Is there a smart way to stop the escape of the underscore?
To use latex characters such as the underscore, simply add the "substitute" option to the end of esttab. For underscores, your labels look like
label var "\$\beta_i\$"
so add
...substitute(\_ _)
to the 'estadd' command.
Does anyone know how to make (nice looking) double bracket multiset notation in LaTeX, i.e something like (\binom{n}{k}) where there are two outer brackets instead of 1 as in binomial? You can see an example of what I mean in http://en.wikipedia.org/wiki/Multiset under the heading "Multiset coefficients" with the double brackets.
In Wikipedia they typeset it as:
\left(\!\!{n\choose k}\!\!\right)
but although this works well for LaTeX in maths mode, with inline equations the outer bracket becomes much larger than the inner bracket.
I have also tried using
\genfrac{((}{))}{0pt}{}{n}{k}
but it has an error with the double brackets.
I am using \binom as well in my document, so I would like the bracket sizes to be similar for \binom and \multiset.
You can explicitly specify the size of the brackets via
\big( \Big( \bigg( or \Bigg(
Then use \! for negative space to get the brackets closer to each other.
One can use the e-TeX \middle command as follows:
\newcommand{\multibinom}[2]{
\left(\!\middle(\genfrac{}{}{0pt}{}{#1}{#2}\middle)\!\right)
}
This assumes that you are using the AMSmath package. If not, replace \genfrac with the appropriate construct using \atop.
(Of course this is a hack: the proper solution would be scalable glyphs for the doubled parenthesis, but I can't find any fonts that provide it.)
I'm surprised it wasn't googlable either, so I'll provide a solution here for posterity's sake.
It is also possible to define two different new commands, using \tbinom and \dbinom (section 4.11.2 of the User's Guide for the amsmath Package):
\documentclass{article}
\usepackage{amsmath}
\newcommand{\inlinebnm}[2]{\ensuremath{\big(\!\tbinom{#1}{#2}\!\big)}}
\newcommand{\displybnm}[2]{\bigg(\!\!\dbinom{#1}{#2}\!\!\bigg)}
\begin{document}
Text $\inlinebnm{a}{b}$ text. %% inline
Text \inlinebnm{a}{b} text. %% inline (also ok thanks to ensuremath)
\[
\displybnm{a}{b} %% display-style
\]
\end{document}