Matplotlib mathtext does not understand basic delimiters with right/left - latex

When using \left and \right in matplotlib with mathtext parsing, it doesn't recognize useful delimiters. In particular, brace and square bracket are errors:
ylabel(r'$\left\{ \frac{a}{b} \right\}$')
ylabel(r'$\left[ \frac{a}{b} \right]$')
In both cases I get something like
ParseFatalException: Expected a delimiter
$\left\{ \frac{a}{b} \right\}$ (at char 0), (line:1, col:1)
On the other hand \left{ (incorrectly leaving off the backslash) does actually work. I can't find any way to make the square bracket work, though.
I couldn't find any bug reports on this, but maybe I'm looking in the wrong place. Any ideas what's going on?
(matplotlib.__version__ = '1.1.0')

Just to be able to put this question to bed, this was just a bug, and will be fixed in a future release.

Related

Getting align in Latex to work for Phonological Rules

First time questioner and extremely new LaTeX user here. I'm trying to get equations to line up according to the arrow symbol used in my linear rules for a Phonology paper.
\begin{align}
\text{/b'al/} &\arrow\ \text{[b\super{j}\textipa{A}l]}\\
\text{/luna/} &\arrow\ \text{[wu.n\textipa{A}]}\\
\end{align}
For this I made \newcommand{\arrow}[0]{$\rightarrow$} to avoivd swapping in and out of mathmode.The format I'm trying to get is that it would have the first and second lines match up according to the arrow. However, I keep getting a "Missing } inserted. } l.38 \end{align}".
Sorry for the possibly dumb question, but can anyone help?
If you are using \arrow in both math and text mode, then you can use
\newcommand{\arrow}{\ensuremath{\rightarrow}}
which will ensure it be typeset in math-mode, regardless of the context. Note that there are some problems with using \ensuremath. However, they may not pertain to your situation.
It looks like the problem is that the align environment already defines math mode, and because your \arrow definition includes the math mode delimiters it breaks the whole thing. You just have to write \rightarrow without the $ ... $ around it.
If you want, define another command \marrow[0]{\rightarrow} to use within math mode.
If this answered your question, please mark it as such so that others know that it worked for you.

In reStructuredText greek alpha needs "\\", other greek letters only "\" when target is pdf

I recently discovered reST/Sphinx and tried to use it to document a python class I had written some time before.
After some experimentation I found out I needed to write :math:`K_\\alpha` to get the greek letter in the subscript while using the make latexpdf target. With a single \ there were errors. Strangely enough every other greek letter only needed a single \ to produce the desired output.
What is happening?
Thank you so much for asking this. It finally helped me solve my related problem.
For me, \alpha and \beta both fail.
They both fail even without the subscript part coming into play. But if I use the curly braces it works:
:math:`\alpha`
does not compile
:math:`{\alpha}`
gives me the symbol I want
:math:`{\\alpha}`
gives me the word 'alpha' written as adjacent math variables a, l, p, h, a.
To get a K followed by a subscripted α in inline text, use
:math:`K_{\alpha}`
Note curly braces and backticks. It works fine and is what you would expect based on these references:
http://www.emerson.emory.edu/services/latex/latex_117.html
http://sphinx-doc.org/ext/math.html#role-math
In math markup used in Python docstrings, you need two backslashes (or use "raw" strings):
:math:`K_{\\alpha}`
Edit: I was wrong about the curly braces. It turns out that these two samples give the same result in the PDF output:
:math:`K_{\alpha}`
and
:math:`K_\alpha`
What is happening?
\a is interpreted as a control character ("bell", just like e.g. \n "end of line"). Notably, \b (backspace) could be a control character as well, but is for some reason not interpreted as such.
Note that another possible workaround is using raw strings (r"""some text"""), as noted also in the sphinx math documentation 2.
Sources: Wikipedia, Sphinx documentation, "Math support in Sphinx"

Does ctx-solver-simplify (and similar tactics) produce equivalent formulas, or just SAT-equivalent, or am I doing things completely wrong?

I'm trying to make z3 (I'm using z3py) to simplify some formulas for me (so that I can have more or less human-readable output). Using ctx-solver-simplify tactic seemed a good choice for me since in a couple of passes it would produce nice compact formulas. But soon I've run into a situation when the output of ctx-solver-simplify does not seem to be equivalent to the original formula (it looks more like being satisfiability-equivalent or so). Also, it might be the case that I'm not dealing with tactics correctly.
Here's what I was trying to do: http://rise4fun.com/Z3Py/g5sX. So, I construct a formula Set2 (everything before the definition of Set2 is just a setup needed to define it) which has a particular satisfying assignment. After applying ctx-solver-simplify, I get a single formula (as a goal) for which this assignment is not satisfying. So what am I dong wrong?
Am I wrong assuming that ctx-solver-simplify would produce an equivalent formula?
Am I handling the tactics and their output in the wrong way?
Anything else?
Thanks.
I have been looking into this, but have so far been unable to reproduce the bug directly
with our current branch. A bug in the context simplifier was fixed a little while ago, and it could
be manifesting itself with the online version of Z3.
There are still a few things I can do to double check if we can reproduce the bug
and I will update this post with what I find.

How do I get auto-conversion of Part [[ double-brackets ]] on paste?

A pet peeve of mine is the use of double square brackets for Part rather than the single character \[LeftDoubleBracket] and \[RightDoubleBracket]. I would like to have these automatically replaced when pasting plain-text code (from StackOverflow for example) into a Mathematica Notebook. I have been unable to configure this.
Can it be done with ImportAutoReplacements or another automatic method (preferred), or will I need use a method like the "Paste Tabular Data Palette" referenced here?
Either way, I am not good with string parsing, and I want to learn the best way to handle bracket counting.
Sjoerd gave Defer and Simon gave Ctrl+Shift+N which both cause Mathematica to auto-format code. These are fine options.
I am still interested in a method that is automatic and/or preserves as much of the original code as possible. For example, maintaining prefix f#1, infix 1 ~f~ 2, and postfix 1 // f functions in their original forms.
A subsection of this question was reposted as Matching brackets in a string and received several good answers.
Not really an answer, but a thread on entering the double [[ ]] pair (with the cursor between both pairs) using a single keystroke occurred a couple of weeks ago on the mathgroup. It didn't help me, but for others this was a solution apparently.
EDIT
to make good on my slightly off-topic first response here's a pattern replacement that seems to do the job (although I have difficulties myself to understand why it should be b and not b_; the latter doesn't work):
Defer[f[g[h[[i[[j[2], k[[1, m[[1, n[2]]]]]]]]]]]] /.
HoldPattern[Part[b, a_]] -> HoldPattern[b\[LeftDoubleBracket]a\[RightDoubleBracket]]
I leave the automation part to you.
EDIT 2
I discovered that if you add the above rule to ImportAutoReplacements and paste your SO code in a notebook in a Defer[] and evaluate this, you end up with a usable form with double brackets which can be used as input somewhere else.
EDIT 3
As remarked by Mr.Wizard invisibly below in the comments, the replacement rule isn't necessary. Defer does it on its own! Scientific progress goes "Boink", to cite Bill Watterson.
EDIT 4
The jury is still out on Defer. It has some peculiar side effects, and doesn't work well on all expressions. try the "Paste Tabular Data Palette" in the toolbag question for instance. Pasting this block of code in Defer and executing gives me this:
It worked much better in another code snippet from the same thread:
The second part is how it looks after turning it in to input by editing the output of the first block (basically, I inserted a couple of returns to restore the format). This turns it into Input. Please notice that all double brackets turned into the correct corresponding symbol, but notice also the changing position of ReleaseHold.
Simon wrote in a comment, but declined to post as an answer, something fairly similar to what I requested, though it is not automatic on paste, and is not in isolation from other formatting.
(One can) select the text and press Ctrl+Shift+N to translate to StandardForm

What do the square brackets in LaTeX logs mean?

I'm currently working on a parser that reads complete LaTeX logs. Most of the log format is, though weird, easy to figure out, but these square brackets are puzzling me. Here's an example from near the end of one of my logs:
Overfull \hbox (10.88788pt too wide) in paragraph at lines 40--40
[]$[]$
[]
[102]) [103]
Kapitel 14.
(./Thermo-141-GrenzenFundamentalpostulat.tex [104
])
(./Thermo-142-Mastergleichung.tex [105]) (./Thermo-143-HTheorem.tex [106pdfTeX
warning (ext4): destination with the same identifier (name{equation.14.3.3}) ha
s been already used, duplicate ignored
Can anybody give me a hint what these square brackets mean? I can't see any structure in them.
I have the suspicion that lines 2/3 above are some kind of ASCII art representing the box layout, though I know too less about badboxes to justify this or identify the meaning of the single characters.
Then, the "[104" etc. seem to correspond to the page numbers, but I am still not seeing the reason why there is sometimes something inbetween the square brackets (like the pdfTeX warning above), and sometimes not.
As told in the comments []$[]$ means that Tex want to tell you that something takes too much horizontal space (Overfull \hbox). It tries to print the offending boxes, but fails, as those seem to be formulas, which can't be printed in normal text. If the same error would occur with normal text, you would get that text inside square brackets as a hint, where Tex thinks it can break your text.
As for the numbers inside square brackets, those are the page numbers. In your example Tex got your text set until page 102, where it got problems with a too wide formula.
For more information about reading the log files of Tex try the following website.

Resources