How use sub and superscript in Mathematica text, eg: chemical formulas? - wolfram-mathematica

This is not quite a programming question, but it's about a programming environment, so hopefully not too out of place. I need to be able to write chemical formulas in Mathematica text (this is specifically about text, not input/code). Something like: H3O+. But Mathematica can't seem to do this. If you use the normal sub/superscript functions, or hit Cntl-_ or Cntl-6, it puts you in "math mode" even when you are in text, and so the letters become italic, and it puts a space between the 3 and the O. Like this: H3 O+. Ugly, especially with longer chemicals.
Other things in Mathematica work like normal word processors -- you can style fonts as italic, bold, big, small, colored -- but the subscript and superscript functions common in word processors seems to be missing.
Am I missing something? I hope so...
thanks,
Rob

You could use a trick similar to that used in LaTeX for printing subscripts on the left. That is place the subscript on an object with no width.
To enter math mode type Cntl-( and to exit type Cntl-) .
Attach the sub and superscripts to ⋮null⋮ or ⋮ ⋮ or ⋮- ⋮ (where ⋮ = escape)
Here's how it displays - compared to some expressions in mathmode:
I've placed the Cell Expression in a gist for you.

In ChemData, Mathematica uses contructs like
Style[
Row[
{Subscript["H",3],Superscript["O","+"]}
],
Rule[ScriptBaselineShifts,{0.5`,0.75`}]
]
Example:
HTH!

Related

Use a google sheets formula to set text value as italic

I'd like to concatenate values in a text cell so that a part of the cell is standard font and a part of it is italic. I'm envisioning something like this:
="("&italic("text sample")&")"
... where the enclosing parentheses are standard font and the text is italic. So the result would look like this: (text sample). Obviously, my example is not an actual formula.
Anyone know how to do that?
Thanks!
After quite a bit of research, looks like there is no way to do this with native google sheet functions. A custom function would be needed. Not really a big problem, but a function that I wish were there to use.

Change font style when typing in powerpont

I am using PowerPoint2013 for create a presentation about math. And I do not want to use "equation object". I chose Italic time new roman font and I write for example A=(a1,a2,...) but it show me A=(a1,a2,...) instead of A=(a1,a2,...). Except letters, other characters not to be italic style.
So if a character (that I write) be a letter then automatically must be show italic style, and if not, must be show normal style.
How can I do.
I'll present a few options here:
VBA
You could use VBA to italicise only the letters on a slide. If this is something that could be useful then let me know and I'll give you a few pointers. A few downsides though:
It wouldn't work in real time. Also, not all letters should be italicised when typesetting math; for example, cos(x).
It still won't look great. Times is not a mathematical font.
Beamer
Most university lecturers will use LaTeX with Beamer to create mathematical presentations. It will export each slide as a static .pdf (i.e. you won't be able to use animation other than things appearing one by one), but will look much more professional than powerpoint, and you will be able to take advantage of LaTeX's wonderful maths typesetting.
TeXPoint
I haven't used this myself, but it is a plugin for powerpoint which lets you use LaTeX to typeset equations: http://texpoint.necula.org/
Out of interest, why do you not want to use PowerPoint's built-in equation editor?

How to write a subscript and superscript in Matlab that will be displayed in Graphical User Interface(GUI)?

I want to have a subscript and superscript in my GUI in Matlab. So far I have tried to use x_2 and x^2 and neither of them work. Is there anyone who knows how to do this?
Thanks in advance!
From http://www.mathworks.com/matlabcentral/newsreader/view_thread/158410#398940
You can use an undocumented feature of all Matlab uicontrols, which is
the fact that they use underlying Java Swing controls, and these in
turn accept any valid HTML strings. So you can do the following for
example:
uicontrol('string','<html><b>1<sub>2</sub>3<sup>4</sup>5</b></html>')
This is equivalent to the tex string '\bf1_23^45\rm'. You can set font
faces, colors, sizes, bold/italic and any other valid HTML 3.0
property. It's limited, but should do the trick in most conceivable
cases.
The same is true for tooltips, by the way: try setting multi-line
(<br>) multi-colored (<font color="red"> ... </font>) tooltip once and
you'll never use the standard boring single-line black tooltip
again...
And just in case you were wondering - yes, it also works for menus,
listboxes etc.

How to force two figures to stay on the same page in LaTeX?

I have two images that I want to display on a page as figures. Each eats up little less than half of the space available so there's not much room for any other stuff on that page, but I know there is enough space for both of the figures. I tried to place the figures with [ht] and [hb], both [h] and both [ht] but still I can't get those two images on the same page but instead at least few paragraphs between them.
How do I force those two figures to stay on the same page?
You can put two figures inside one figure environment. For example:
\begin{figure}[p]
\centering
\includegraphics{fig1}
\caption{Caption 1}
\includegraphics{fig2}
\caption{Caption 2}
\end{figure}
Each caption will generate a separate figure number.
If you want to have images about same topic, you ca use subfigure package and construction:
\begin{figure}
\subfigure[first image]{\includegraphics{image}\label{first}}
\subfigure[second image]{\includegraphics{image}\label{second}}
\caption{main caption}\label{main_label}
\end{figure}
If you want to have, for example two, different images next to each other you can use:
\begin{figure}
\begin{minipage}{.5\textwidth}
\includegraphics{image}
\caption{first}
\end{minipage}
\begin{minipage}{.5\textwidth}
\includegraphics{image}
\caption{second}
\end{minipage}
\end{figure}
For images in columns you will have [1] [2] [3] [4] in the source, but it will look like
[1] [3]
[2] [4].
I had this problem while trying to mix figures and text. What worked for me was the 'H' option without the '!' option.
\begin{figure}[H]
'H' tries to forces the figure to be exactly where you put it in the code.
This requires you include
\usepackage{float}
The options are explained here
If you want them both on the same page and they'll both take up basically the whole page, then the best idea is to tell LaTeX to put them both on a page of their own!
\begin{figure}[p]
It would probably be against sound typographic principles (e.g., ugly) to have two figures on a page with only a few lines of text above or below them.
By the way, the reason that [!h] works is because it's telling LaTeX to override its usual restrictions on how much space should be devoted to floats on a page with text. As implied above, there's a reason the restrictions are there. Which isn't to say they can be loosened somewhat; see the FAQ on doing that.
Try adding a !, e.g. [h!].
try [h!] first but else you can do it the ugly way.
LateX is a bit hard in placing images with such constraints as it manages placing itself. What I usually do if I want a figure right in that spot is do something like|:
text in front of image here
\newpage
\figure1
\figure2
text after images here
I know it may not be the correct way to do it but it works like a charm :).
//edit
You can do the same if you want a little text at top of the page but then just use /clearpage. Of course you can also scale them a bit smaller so it does not happen anymore. Maybe the non-seen whitespace is a bit larger than you suspect, I always try to scale down my image until they do appear on the same page, just to know for sure there is not like 1% overlap only making all of this not needed.
Sometimes we want to put only one caption for two or three related images, and then again, we have two or three associated charts with one caption (for some journals, this style is necessary. In this case, subfloat or other similar environments does not help since they only allow one caption per subfloat, not a cation for all subfloats like the following:
|------| |------| |------|
|image1| |image2| |image3|
|______| |______| |______|
Figure 1. cation for all of the
subfloats
|------| |------| |------|
|image1| |image2| |image3|
|______| |______| |______|
Figure 2. cation for all of the
subfloats
content of the article, content of the article
content of the article content of the article
To produce such a style, I used the following snippet:
\begin{figure}[t]
\subfloat[]{}
\subfloat[]{}
\subfloat[]{}
\end{figure}
\begin{figure}[t!]
\subfloat[]{}
\subfloat[]{}
\subfloat[]{}
\end{figure}
\begin{figure}[t!]
\subfloat[]{}
\subfloat[]{}
\subfloat[]{}
\end{figure}
Try using the float package and then the [H] option for your figure.
\usepackage{float}
...
\begin{figure}[H]
\centering
\includegraphics{fig1}
\caption{Write some caption here}\label{fig1}
\end{figure}
as already suggested by this insightful answer!
https://tex.stackexchange.com/questions/8625/force-figure-placement-in-text

How can I use variables to DRY up Vim colorthemes

I would like to tidy up my Vim color scheme file, by replacing #ABCDEF colors
with variables. For example, I would like to replace this:
highlight String guifg=#61CE3C
highlight Identifier guifg=#61CE3C
highlight Type guifg=#84A7C1
with something like this (pseudo-code vimscript):
my_string =#61CE3C
my_type =#84A7C1
highlight String guifg=my_string
highlight Identifier guifg=my_string
highlight Type guifg=my_type
I wasn't sure whether vimscript considers the hex color to be a string, or a
hexadecimal number. Apparently it's a string, cause this seems to work:
:highlight Normal guifg='#ffffff'
So I thought I'd try this:
:let my_color='#ffffff'
:highlight Normal guifg=my_color
But this gives the error "E254: Cannot allocate color my_color". Can anyone
suggest a way to make this work?
Since :highlight doesn't accept a variable as an argument, you have to build the command to run as an expression and then evaluate it with the :execute command.
:let my_color='#ffffff'
:exe 'highlight Normal guifg=' . my_color
As jamessan has said, you need to use :exe to do this. I found the general syntax for the colour scheme files a bit difficult to manage, so I made my own, which you may be interested in. I find it a lot more maintainable, but you may still find it a bit too verbose, in which case see the alternative at the end of this answer.
Rather than writing the long :hi lines, you create a dictionary along the lines of:
" Unspecified colours default to NONE, EXCEPT cterm(.*) which default to matching gui(.*)
" ctermfg will default to 'Blue' and ctermbg to 'NONE' if gui(.*) are RGB
"
" In most cases, only GUIFG is therefore important unless support for Black and White
" terminals is essential
let ColourAssignment['Normal'] = {"GUIFG": 'White', "GUIBG": 'Black'}
let ColourAssignment['Comment'] = {"GUIFG": '#00ff00'}
As mentioned in the comment, all unspecified parts assume sensible defaults, so you don't have to do the common:
:hi Comment guifg=green ctermfg=green guibg=black ctermfg=black
repetition. You can also (of course) put variables in place of the '#00ff00' bit if you want.
It's currently designed around dark background colour schemes: for light background colour schemes, it automatically chooses an appropriate colour (it makes bright colours darker basically) unless you override it, but if you prefer light background colour schemes, it wouldn't be too hard to change so that the default is light.
The other advantage of it is that it comes with a syntax highlighting file that automatically highlights the "ColourAssignment" bit in the colour that you've selected.
Anyway, if that's any interest to you, you can get it from here.
An alternative you could use would be to create a command like this:
command! -nargs=+ Hi call CustomHighlighter(<f-args>)
function! CustomHighlighter(name, ...)
let colour_order = ['guifg', 'guibg']
let command = 'hi ' . a:name
if (len(a:000) < 1) || (len(a:000) > (len(colour_order)))
echoerr "No colour or too many colours specified"
else
for i in range(0,len(a:000)-1)
let command .= ' ' . colour_order[i] . '=' . a:000[i]
endfor
exe command
endif
endfunc
You could then use:
Hi Comment #00ff00
Hi String Yellow
Hi Normal White Black

Resources