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.
Related
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
I think this question is novel. Here is the problem I have. I have a relatively short piece of text associated with a lot of figures and a table. I want floats to appear on pages just for floats but in the order I specify. I have set all of the table and figure parameters to [hp] and placed them in the order I want them to appear in the source e.g.
Figure 1
Figure 2
Figure 3
Table 1
Figure 4
Figure 5
The problem I have is that no matter what I do the document typesets like this
Table 1
Figure 1
Figure 2
etc....
I have tried trashing the Aux files before typesetting. I am aware of the endfloats package but I still want latex to place the floats in between larger sections of txts in other parts of the document. Any help is greatly appreciated.
Thanks
I'll try to explain why the fix by #user476160 (placement modifier hp instead of just p) works. A figure is a float, i.e. an element that cannot be broken across a page. The figure environment accepts a parameter list with placement hints:
\begin{figure}[placement parameters]
% ...
\end{figure}
The placement specifier h stands for here and places the figure approximately at the same point as in the source text. The placement specifier p puts the figure in a special page that contains only floats:
\begin{figure}[hp]
% ...
\end{figure}
Wikibooks has an excellent article on figure placement if you want to fine-tune your figure and table placement.
I also recommend posting LaTeX-related questions in the TeX Stack Exchange Q&A.
Problem solved, the first figure in my list had the parameter [p] rather [hp]. This seemed to cause latex a lot of grief for some reason. Anyhow problem solved for now. The figures and txt all appear in the order I have specified.
It is quite easy. All you have to do is use this package.
\usepackage{float}
And you have to change the figure parameters to
\begin{figure}{H}
%..
\end{figure]}
Let me know if it works :)
What sort of code should I put in preamble, such that every math fomula (in dolar signs) that is too long to fit in line width (a.k.a. produces Bad Box) start in new line (like putting // before equation) ? Or is it impossible to detect and prevent Bad Box in compiling ?
You could use \sloppy or \sloppypar, but that will reduce the quality of the line breaks.
Take a look here.
Are you talking about inline math or TeX-style $$? In the first case: think about putting it in its own environment, long inline math isn't a good idea. In the second case, start using align (or the appropriate environment) and place those breaks yourself. Or use breqn, it will do it automatically.
In case it's inline and you want it to stay inline: consider rewriting your sentences, as usual with bad boxes. And consider using microtype if you're building to pdf, it will enhance the flexibility of the fonts, hence, more possibilities for line breaking.
I don't have an actual solution for line breaks in inline math, I usually resort to these tricks. Maybe someone with a better insignt in inline math can help you with that :).
It seems to be common practice, when writing mathematics, to add punctuation to displayed formulas.
Is there any trick to avoid putting the punctuation mark inside the formula?
I want to avoid
Consider the function
\[ \sin(x).\]
I'd rather have something like:
Consider the function
\[ \sin(x)\].
But of course the full stop is displayed below the formula.
Is there a clever way to separate formulas and punctuation in LaTeX?
\catcode`\#=11
\let\seveendformula\]
\def\]{\#ifnextchar.\PointAndEndFormula\seveendformula}
\def \PointAndEndFormula #1{.\seveendformula}
\catcode`\#=12
Add
More complex solution works with .,?!;: :
\catcode`\#=11
\def\addtopunct#1{\expandafter\let\csname punct#\meaning#1\endcsname\let}
\addtopunct{.} \addtopunct{,} \addtopunct{?}
\addtopunct{!} \addtopunct{;} \addtopunct{:}
\let\seveendformula\]
\def\PunctAndEndFormula #1{#1\seveendformula}
\def\]{\futurelet\punctlet\checkpunct#i}
\def\checkpunct#i{\expandafter\ifx\csname punct#\meaning\punctlet\endcsname\let
\expandafter\PunctAndEndFormula
\else \expandafter\seveendformula\fi}
\catcode`\#=12
There's also the issue of which font the punctuation should be in. You won't see a problem until you try a different math font such as Euler. Then commas and periods are clearly different in text mode and in math mode. I've written text-mode punctuation in displayed formulas as \mbox{,} or lazily as \mbox, just before $$.
You can load the breqn package (compatible with amsmath) and have this behaviour inbuilt with its dmath environment:
Consider the function
\begin{dmath}\sin(x)\end{dmath}.
Will output the same as \[\sin(x).\], i.e., as if the dot was inside the expression.
As a bonus, you'll also get automatic line-breaking in your math equation.
Putting the punctuation inside a display environment is the usual way. The problem is that when Latex processes the \], it ends the mathbox, so anything following will be part of a new vertical box.
You could try something like:
\hbox{\[My formula\]}.
This is not tested, and probably has spacing issues, but if you are interested in this kind of solution, I could try and get something working.
FWIW, you might be interested in https://mathoverflow.net/questions/6675/periods-and-commas-in-mathematical-writing
I'm working on a large project involving multiple documents typeset in LaTeX. I want to be consistent in my use of symbols, so it might be a nice idea to define a command for every symbol that has a specific meaning throughout the project. Does anyone have any experience with this? Are there issues I should pay attention to?
A little more specific. Say that, throughout the document I would denote something called permability by a script P, would it be an idea to define
\providecommand{\permeability}{\mathscr{P}}
or would this be more like the case "defining a command for $n$"?
A few tips:
Using \providecommand will define that command only if it's not been previously defined. So if you're not getting the results you expected, you may be trying to define a command that's been defined elsewhere.
If you wrap the math in your commands with \ensuremath, it will do the right thing regardless of whether you're in math mode when you issue the command:
\providecommand{\permeability}{\ensuremath{\mathscr{P}}}
Now I can easily use \permeability in text or $\permeability$ in math mode.
Using your own commands allows you to easily change the typographical representation of something later. For instance:
\newcommand{\vect}[1]{\ensuremath{\mathbf{#1}}}
would print \vect{x} as a boldfaced x. If you later decide you prefer arrows above your vectors, you could change the command to:
\newcommand{\vect}[1]{\ensuremath{\vec{#1}}}
I have been doing this for anything that has a specific meaning and is longer than a single symbol, mostly to save typing:
\newcommand{\objId}{\mbox{$\mathit{objId}$}\xspace}
\newcommand{\insOp}[1]{#1\mbox{$^+$}\xspace}
\newcommand{\delOp}[1]{#1\mbox{$^-$}\xspace}
However then I noticed that I stopped making inconsistency errors (objId vs ObjId vs ObjID), so I agree that it is a nice idea.
However I am not sure if it is a good idea in case symbols in the output are, well, single Latin symbols, as in:
\newcommand{\numOfObjs}{$n$}
It is too easy to type a single symbol and forget about it even though a command was defined for it.
EDIT: using your example IMHO it'd be a good idea to define \permeability because it is more than a single P that you have to type in without the command. But it's a close call.