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

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].

Related

Is there any way to automatically move periods inside quotation marks? (csquotes doesn't seem to work)

csquotes doesn't work in this case, maybe because I'm using a custom command:
\documentclass[12pt, letter, american]{article}
\usepackage[american]{babel}
\usepackage[autopunct,style=american]{csquotes}
\newcommand{\qq}[1]{\textquote{#1}}
\begin{document}
This is an \qq{example}.
\end{document}
\qq will not move the trailing period into the quotation, e.g. This is an \qq{example}. will still yield This is an “example”. I have written a book using \qq and would like to change the quotation styles to one which moves periods and colons into the quotes. Is there a safe way to achieve this automatically? Maybe a package different from csquotes? The only solution I've found on the net so far didn't work with spacing correctly.
See the csquotes documentation, section 9.2:
\documentclass[12pt]{article}
\usepackage[american]{babel}
\usepackage[autopunct,style=american]{csquotes}
\renewcommand{\mktextquote}[6]{#1#2#4#5#3#6}
\newcommand{\qq}[1]{\textquote{#1}}
\begin{document}
This is an \qq{example}.
\end{document}

How to automatic break lines in latex?

I have searched but nothing useless, only "use \newline" or "use \".
I'm creating a simple latex document to store any texts instead of using .txt, and the problem is that the pdf document contains the lines going towards right until they go out of the paper.
I'm using this simple code
\documentclass[a4paper]{article}
\usepackage{geometry}
\geometry{
a4paper,
total={170mm,257mm},
left=5mm,
top=20mm,
}
\begin{document}
\section{Text 1}
Loremipsumdolorsitamet,consecteturadipiscingelit,seddoeiusmodtemporincididuntutlabore etdoloremagnaaliqua.Utenimadminimveniam,quisnostrudexercitationullamcolaborisnisiutaliquipexeacommodoconsequat.Duisauteiruredolorinreprehenderitinvoluptatevelitessecillum doloreeufugiatnullapariatur.Excepteursintoccaecatcupidatatnonproident,suntinculpaquiofficiadeseruntmollitanimidestlaborum.
\end{document}
Since latex sees it as a one word, it refuses to break it since it doenst know its hyphenation. But I would like to allow latex to break it regardless. Any thoughts ?
Remarks: I already have used:
\hspace{0pt}
\leavevmode\nobreak\hspace{0pt}
\mbox{Loremip...larorum.}
Nothing worked.
I think I got why nothing worked. See my code below, that I managed to compile successfully after editing your MWE.
You basically have two ways to force hyphenation here.
As in the comment by SamCarter, you manually split words within text, just using \- where necessary. I did it below in line 18 (6 from bottom).
You add to your preamble the command \hyphenation{word-to-split}: I did this below to hyphenate the word in line 20 (4 from bottom). Notice that, in this case, you use - instead of \- within the braces {} enclosing the argument.
\documentclass[a4paper]{article}
\usepackage{geometry}
\geometry{
a4paper,
total={170mm,257mm},
left=5mm,
top=20mm,
}
\hyphenation{Duisauteiruredolorinre-prehenderitinvoluptatevelitesse-cillum doloreeufugiatnullapariatur}
\begin{document}
\section{Text 1}
Loremipsumdolorsitamet, consecteturadipiscingelit,
seddoeiusmodtemporincididuntutlaboreetdoloremagna.
Uten\-imadminimveniam,
quisnostrudexercitationullamcolaborisnisiutaliquipexeacommodoconsequat.
Duisauteiruredolorinreprehenderitinvoluptatevelitessecillumdoloreeufugiatnullapariatur.
Excepteursintoccaecatcupidatatnonproident,
suntinculpaquiofficiadeseruntmollitanimidestlaborum.
\end{document}
Finally, if the full stop character . is not followed by a space, two separate words may be interpreted as one and the command \hyphenation may not work as expected. Not sure that this was the detail making you write that nothing worked, but be careful to this too.

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.

Figures occurring after ^ and _ macros (was: LaTeX limitation?)

I've hit an annoying problem in LaTeX. I've got a tex file of about 1000 lines. I've already got a few figures, but when I try to add another figure, It barfs with:
! Undefined control sequence.
<argument> ... \sf#size \z# \selectfont \#currbox
l.937 \begin{figure}[t]
If I move the figure to other parts of the file, I can get similar errors on different lines:
! Undefined control sequence.
<argument> ... \sf#size \z# \selectfont \#currbox
l.657 \paragraph
{A Centering Algorithm}
If I comment out the figure, all is ok.
%\begin{figure}[t]
% \caption{Example decision tree, from Reiter and Dale [2000]}
% \label{fig:relation-decision-tree}
% \centering
% \includegraphics[keepaspectratio=true]{./relation-decision-tree.eps}
%\end{figure}
If I keep just the begin and end like:
\begin{figure}%[t]
% \caption{Example decision tree, from Reiter and Dale [2000]}
% \label{fig:relation-decision-tree}
% \centering
% \includegraphics[keepaspectratio=true]{./relation-decision-tree.eps}
\end{figure}
I get:
! Undefined control sequence.
<argument> ... \sf#size \z# \selectfont \#currbox
l.942 \end
{figure}
At first, I thought maybe LaTeX has hit some limit, and I tried playing with the ulimits, but that didn't help. Any ideas?
i've got other figures with graphics already. my preamble looks like:
\documentclass[acmcsur,acmnow]{acmtrans2n}
\usepackage{array}
\usepackage{lastpage}
\usepackage{pict2e}
\usepackage{amsmath}
\usepackage{varioref}
\usepackage{epsfig}
\usepackage{graphics}
\usepackage{qtree}
\usepackage{rotating}
\usepackage{tree-dvips}
\usepackage{mdwlist}
\makecompactlist{quote*}{quote}
\usepackage{verbatim}
\usepackage{ulem}
I found, not that it's a problem with \textsuperscript, but that it's with a ^ def I picked up from http://anthony.liekens.net/index.php/LaTeX/SubscriptAndSuperscriptInTextMode . The fix is to put the use of ^ in {}, as in I've put entire sections where I use lots of ^ and _ in {}. Hurrah!
During the end of my Master Thesis I also had the problem that after some amount of figures, I got an error without any special error message. After I read you thread, I also tried something with the packages included and in the end I was successful by taking out the \usepackage{pxfonts} and \usepackage{txfonts}. Yeah, finally.. I almost went crazy.. ;)
If I Google for "latex undefined control sequence" I get this.
I've successfully included a graphic into LaTeX using something like this:
\usepackage{amsmath,amsthm,graphicx}
...
I just wanted to test adding an image to a \LaTeX file:
\includegraphics[scale=0.60]{basic-info.png}
I typeset an entire dissertation of 200 pages with lots of figures in LaTeX and didn't run into a limit like that. I'd bet on a syntax problem first before I'd assume a size issue.
Your error lies elsewhere. I wouldn't be the least surprised if it turned out to be the document class. Try altering your document for \documentclass{article} and see where you get. If that fixes the problem you can complain to the ACM (ROTFLMAO—I've dealth with ACM).
If that doesn't fix, the problem, slip in a \tracingall somewhat before the offending figure or section, put the results into http://pastebin.com/, and let us know.
Please receive the thanks of a (formerly) utterly-confounded graduate student. Quick clarification for other users:
{The quickest ^{way} to put this solution into practice is to bracket all sections of text involving the character ``\^'' as shown here.}

Suppress indentation after environment in LaTeX

I'm trying to create a new environment in my LaTeX document where indentation in the next paragraph following the environment is suppressed.
I have been told (TeXbook and LaTeX source) that by setting \everypar to {\setbox0\lastbox}, the TeX typesetter will execute this at the beginning of the next paragraph and thus remove the indentation:
\everypar{\setbox0\lastbox}
So this is what I do, but to no effect (following paragraph is still indented):
\newenvironment{example}
{\begin{list}
{}
{\setlength\leftmargin{2em}}}
{\end{list}\everypar{\setbox0\lastbox}}
I have studied LaTeX's internals as well as I could manage. It seems that the \end routine says \endgroup and \par at some point, which may be the reason LaTeX ignores my \everypar setting. \global doesn't help either. I know about \noindent but want to do this automatically.
Example document fragment:
This is paragraph text. This is paragraph text, too.
\begin{example}
\item This is the first item in the list.
\item This is the second item in the list.
\end{example}
This is more paragraph text. I don't want this indented, please.
Internal routines and switches of interest seem to be \#endpetrue, \#endparenv and others. Thanks for your help.
I couldn't get anything to work without redefining \end, but I'm certainly no expert.
The following is quite hacky, but worked in my limited testing. Of course this will interfere with nested environments (you should be able to redefine \begin to restore the old \end if you have problems).
\newenvironment{example}{%
\bgroup
\let\oldend=\end
\def\end##1{\oldend{##1}\csname #afterindentfalse\endcsname
\csname #afterheading\endcsname}
\begin{list}{}
{\setlength\leftmargin{2em}}
}{%
\end{list}
\egroup
}
Can't you avoid this by not having a blank line between your environment and the next line?
This is paragraph text. This is paragraph text, too.
\begin{example}
\item This is the first item in the list.
\item This is the second item in the list.
\end{example}
% (No blank line)
This is more paragraph text. I don't want this indented, please.
Something as simple as this works for me:
\makeatletter
\newenvironment{example}{%
\bgroup
\list{}{}
}{%
\endlist
\#afterindentfalse
\#afterheading
\egroup
}
\makeatother
But, it doesn't work before the first \section (or \chapter, in the case of classes "book" and "report") is called. I don't know why.
I tried the Ivan's answer, but it wasn't working for me. But I did get it working! Here's what I did:
\makeatletter
\renewenvironment{quotation}{%
\bgroup%
\let\oldend=\end%
\def\end##1{\oldend{##1}\csname #afterindentfalse\endcsname%
\csname #afterheading\endcsname}%
\list{}{\listparindent 1.5em%
\itemindent \listparindent%
\leftmargin 1.5em% This controls the size of the indentation
\rightmargin \leftmargin
\parsep \z# \#plus\p#}% This line reduces inter-paragraph space to normal values.
\item\relax%
}{%
\endlist%%
\egroup%
}
\makeatother
The advantage to this is that it typesets your blockquotes very nicely, and removes the indentation from paragraph after the blockquote.
You can do this without redefining \end
\makeatletter
\newenvironment{example}
{\begin{list}
{}
{\setlength\leftmargin{2em}}}
{\end{list}%
\def\if#endpe{%
\#doendpe
\let\par\##par
\iffalse}}
\makeatother
Explanation
\end changes \everypar after expanding \endexample. To make things even more complicated it sets \par to restore \everypar{}. Appearently \#doendpe is ment to make sure that there is no indentation if the paragraph continues after the environment, but to restore normal behavior if there is a \par (or empty line) after the environment.
You may want to avoid changing \end because it would have to be changed at the begining of the environment and may therefore disturb nested environments. Luckily the definition of \end contains \expandafter\endgroup\if#endpe. We can use \if#endpe as a hook to inject our code to the outer scope. After the \endgroup \if#endpe is automatically restored.
Include \#afterindentfalse\#afterheading at the end of your definition.
I had the same problem. I just used this:
\noindent \newenvironment
You should not mess with the \everypar token list, unless you know exactly what you are doing. Use
\setlength{\parindent}{0pt}
to get rid of indenting in the whole document.
ending your environment with \noindent could help you

Resources