Alternative input to LaTex newcommand - latex

Is there an alternative way to enter multiple arguments to LaTex newcommand constructions? I have defined
\newcommand{\nuc}[2]{\ensuremath{^{\text{#1}}\text{#2}}}
and I would like to call the command through
\nuc{12,C}
and not
\nuc{12}{C}.
I have created other commands with even more arguments and my poor pinky can't handle all the brackets.
Thanks!

Maybe you will like it.
\def\nuc #1,#2.{\ensuremath{^{\text{#1}}\text{#2}}}
Sample of using:
\nuc 12,C.
Note. Use the dot at the end.

I like to praise perltex for defining complicated functions. This isn't complicated, but you can extend it quite impressively.
%myfile.tex
\documentclass{article}
\usepackage{perltex}
\perlnewcommand{\commafrac}[1]{
$input = shift;
#inputs = split(/,/, $input);
return "\\ensuremath{\\frac{$inputs[0]}{$inputs[1]}}";
}
\begin{document}
One half is $\commafrac{1,2}$.
\end{document}
Compile with perltex --latex=pdflatex myfile.tex. I know that \frac wasn't your example, but I find it a visually appealing one.

Use plain TeX \def:
\makeatletter
\newcommand*{\nuc}[1]{\nuc##1\#nil}
\newcommand*{\nuc#}{}
\protected\def\nuc##1,#2\#nil{\ensuremath{^{\text{#1}}\text{#2}}}
\makeatother

As fas as I know \nuc{12}{c} is the only way. If you don't want to put all the "}{"s, let the editor do it. Write \nuc{12,c} first, then replace all commas with "}{"s.

Related

Howto - Latex syntax with \section[]{}: Putting Brackets [ Inside of Brackets

I am writing a beamer presentation. My problem is a syntax issue with \section[Outline]{title}. \section is working fine with all of my section titles except in the following example:
\section[$\mathbb{Z}[G]$-module constructions]{$\mathbb{Z}[G]$-modules and Geometric Constructions}
I need a [ or \[ symbol around the G (i.e., [G]) in the Outline part of \section,however, Tex throws tons of errors whenever anything resembling a bracket is in there.
All ideas are welcome and thanks in advance.
Michael Anderson points out a much cleaner way of doing the same in the comments. Define the command in your preamble as
\newcommand[1]{\bracket}{[#1]}
and use the syntax $\bracket{G}$ to place brackets around G.
The problem is because LaTeX interprets the ] in [G] as a closing bracket for the [Outline] part of the command. Here's a work around for that. In your preamble, add the following:
\newcommand{\rbracket}{]}
Now define your section as
\section[$\mathbb{Z}[G\rbracket $-module constructions]{$\mathbb{Z}[G]$-modules and Geometric Constructions}
This is how the outline should look like
By wrapping the short title in an additional layer of {...} you can "hide" the problematic content from latex:
\documentclass{beamer}
\begin{document}
\begin{frame}
\tableofcontents
\end{frame}
\section[{$\mathbb{Z}[G]$-module constructions}]{$\mathbb{Z}[G]$-modules and Geometric Constructions}
\begin{frame}
content...
\end{frame}
\end{document}
Michael Anderson gave a nice solution, but when I tried it, I got errors. Then I wrote this:
\newcommand{\bracket}[1]{[#1]}
and that worked to get brackets in brackets with:
\bracket{content}
to get [content].

Multiset notation in LaTeX

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}

Quick way to make 26 macros (one for each letter)

Instead of making a macro for each letter, as in
\def\bA{\mathbf{A}}
...
\def\bZ{\mathbf{Z}}
Is there a way to loop over a character class (like capital letters) and generate macros for each? I'd also like to do the same for Greek letters (using bm instead of mathbf).
\def\mydefb#1{\expandafter\def\csname b#1\endcsname{\mathbf{#1}}}
\def\mydefallb#1{\ifx#1\mydefallb\else\mydefb#1\expandafter\mydefallb\fi}
\mydefallb ABCDEFGHIJKLMNOPQRSTUVWXYZ\mydefallb
New for Greek
\def\mydefgreek#1{\expandafter\def\csname b#1\endcsname{\text{\boldmath$\mathbf{\csname #1\endcsname}$}}}
\def\mydefallgreek#1{\ifx\mydefallgreek#1\else\mydefgreek{#1}%
\lowercase{\mydefgreek{#1}}\expandafter\mydefallgreek\fi}
\mydefallgreek {beta}{Gamma}{Delta}{epsilon}{etaex}{Theta}{Iota}{Lambda}{kappa}{mu}{nu}{Xi}{Pi}{rho}\mydefallgreek
$\bGamma\bDelta \bTheta \bLambda \bXi \bPi $
$\bbeta \bgamma\bdelta \bepsilon \betaex \btheta \biota \blambda \bkappa \bmu \bnu \bxi \bpi \brho$
Expanding on Andrew's answer, here is a solution without \expandafter:
\makeatletter
\#tempcnta=\#ne
\def\#nameedef#1{\expandafter\edef\csname #1\endcsname}
\loop\ifnum\#tempcnta<27
\#nameedef{b\#Alph\#tempcnta}{\noexpand\mathbb{\#Alph\#tempcnta}}
\advance\#tempcnta\#ne
\repeat
This will define \bA, \bB, and so on, to expand to \mathbb{A}, \mathbb{B}, and so on.
Wouldn't be better to define one command
\newcommand\bm[1]{\ensuremath{${\boldmath$#1$}}$}
and it can be used both in text mode and math mode.
Usage:
\[\bm{F(x)}=\int\bm\delta(x)\ dx]
\where \mb F is blah blah blah and \bm \delta is halb halb halb...
Result:
F(x)='inegral delta(x)'dx
Where F is blah blah blah and 'delta' is halb halb halb...
Outer dollars are there to leave math (roman) mode because \boldmath command has no effect in math mode. Inner ones switch back to math (bold). Additional braces (${\boldmath) ensures that \boldmath command will work only with #1
Another advantage of this code is testing new commands for existence of \bb and \bg. So you can't crash LaTeX makros easily.
I hope this is what you're looking for.
I would recommend doing:
\newcommand{\b}[1]{\mathbf{#1}}
as Crowley says, and similar for all the other alphabets. However, if you really want to do it using LaTeX code, here's one that seems to work:
\documentclass{article}
\usepackage{amssymb}
\newcounter{char}
\setcounter{char}{1}
\loop\ifnum\value{char}<27
\edef\c{\Alph{char}}
\expandafter\expandafter\expandafter\expandafter\expandafter\expandafter\expandafter\def\expandafter\expandafter\expandafter\csname\expandafter\expandafter\expandafter b\expandafter\c\expandafter\endcsname\expandafter{\expandafter\mathbb\expandafter{\c}}
\addtocounter{char}{1}
\repeat
\begin{document}
\(\bZ\)
\end{document}
I lost count of how many 'expandafter's there are in that! To get lowercase letters, replace the Alph by alph.

QED symbol in latex

How do I type a QED symbol - I want a full box and not an empty box like \qed gives you. (I'm not using \begin{proof})
You can use \blacksquare ■:
When creating TeX, Knuth provided the symbol ■ (solid black square), also called by mathematicians tombstone or Halmos symbol (after Paul Halmos, who pioneered its use as an equivalent of Q.E.D.). The tombstone is sometimes open: □ (hollow black square).
\documentclass{scrartcl}
\usepackage{amssymb}
\begin{document}
$\backslash$blacksquare: $\blacksquare$
$\backslash$square: $\square$
\end{document}
You can easily find such symbols with http://write-math.com
When you want to align it to the right, add \hfill.
I use:
\renewcommand{\qed}{\hfill\blacksquare}
\newcommand{\qedwhite}{\hfill \ensuremath{\Box}}
If you \usepackage{amsmath}, the \blacksquare command will typeset a solid black square. The \square command will give you a hollow square.
The ulsy package has a few version of the lightning bolt for contradictions: \blitza, \blitzb, ..., \blitze. Just drop \usepackage{ulsy} into the preamble of your document.
Finally, as others have pointed out, the Comprehensive LaTeX Symbols List is a great resource for finding the perfect symbol for the job.
Add to doc header:
\usepackage{ amssymb }
Then at the desired location add:
$ \blacksquare $
As described here, you can redefine the command \qedsymbol, in your case - to \blacksquare:
\renewcommand{\qedsymbol}{\ensuremath{\blacksquare}}
This works both with \qed command and proof environment.
What about \blacksquare? http://amath.colorado.edu/documentation/LaTeX/Symbols.pdf
\rule{1.2ex}{1.2ex} will give you a filled box.
\fbox{\phantom{\rule{.7ex}{.7ex}}} will give you an empty box. The \phantom command will typeset with invisible ink.
The advantage of this approach is that no package is needed. Also the size is up to your control. Less is more.
Simple answer:
In the preamble make sure you have \usepackage{amssymb}
Then in the preamble we can define this simple command: \newcommand{\qed}{\hfill $\blacksquare$}
Then whenever you want the QED symbol to complete a proof, you type \qed.
If you prefer a hollow square, replace \blacksquare with \square
I think you are looking for this:
\newcommand*{\QEDA}{\hfill\ensuremath{\blacksquare}}
Usage:
\begin{example}
blah blah blah \QEDA
\end{example}
The question specifically mentions a full box and not an empty box and not using proof environment from amsthm package. Hence, an option may be to use the command \QED from the package stix. It reproduces the character U+220E (end of proof, ∎).

How to write programming code containing the ' character in latex?

I am trying to write programming code in latex using the verbatim environment, but when I write
\begin{verbatim}
char ch = 'x';
\end{verbatim}
then the ' -characters around x are displayed incorrectly (they look "curly"). How can I fix this problem?
Load the upquote package to fix this issue in verbatim mode.
If you want straight quotes in monospaced text mode (e.g., \texttt{...}), or indeed in any other font, then you can use the \textquotesingle command defined in the textcomp package:
\documentclass{article}
\usepackage{upquote,textcomp}
\begin{document}
\newcommand\upquote[1]{\textquotesingle#1\textquotesingle}
\verb|'c'| \texttt{\upquote{h}}
\textsf{\upquote{h}} \upquote{h}
\end{document}
This will work well for fonts in any encoding rather than depending on a specific glyph slot (such as \char13 in the default OT1 encoding).
Adding \usepackage{upquote} to my preamble was sufficient.
Perhaps older versions of LaTeX or upquote required more work.
I have
What is wrong?
New
If you want to get something like this
write
\makeatletter
\let \#sverbatim \#verbatim
\def \#verbatim {\#sverbatim \verbatimplus}
{\catcode`'=13 \gdef \verbatimplus{\catcode`'=13 \chardef '=13 }}
\makeatother
For displaying source code, you might consider using the listings package; it is quite powerful and offers an option to display “straight” quotation marks.
If you're seeing curly single right quotes in a verbatim environment, then the single right quote in your typewriter font is curly, and that's the correct one to use for what you're doing (which I assume is displaying some C code).
\textsf{``} and \textsf{''} come pretty close to straight quotes. No need for using any special packages.
This is what I got from another source, and this works.
Use `` to start the double quotes (this symbol is below ~ symbol on our keyboard)
Use '' to close the double quotes (this symbol is below the " symbol on our keyboard)
So, `` quote double, unquote double''
Same goes for single quotes, `quote single, unquote single'

Resources