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

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

Related

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.

The ``\nabla'' symbol showed incorrectly as a black disc

I am working on a report, which contains an equation involved gradient. So I need the nabla symbol to be printed out like this:
But actually, I finally got a black disc as I try to input the nabla symbol:
I don't know if it is the problem of my code:
$\nabla_{w}\mathcal{L}(w, b, a)$
As for background details, I use TeXShop4.38 on macOS 10.14.6, the packages are the following:
\usepackage{algorithm}
\usepackage{algpseudocode}
\usepackage{amssymb}
\usepackage{amsmath}
\usepackage{txfonts}
\usepackage{fdsymbol}
\usepackage{graphicx}
\graphicspath{{secret}}
\DeclareMathOperator*{\argmax}{argmax}
\DeclareMathOperator*{\argsup}{argsup}
Can anyone help me target the problem? Thanks a lot!
You can find the root cause of such problems by creating a minimal example, i.e. the minimum amount of code that is needed to reproduce the problem. In your case that would be:
\documentclass{article}
\usepackage{fdsymbol}
\begin{document}
$\nabla_{w}\mathcal{L}(w, b, a)$
\end{document}
Indeed, the documentation for fdsymbol states that it does not contain a symbol for \nabla. One simple solution would be loading txfonts after fdsymbol. Alternatively, you could update to the more modern newtxtext and newtxmath:
\documentclass{article}
\usepackage[full]{textcomp}
\usepackage{fdsymbol}
\usepackage{newtxtext,newtxmath}
\begin{document}
$\nabla_{w}\mathcal{L}(w, b, a)$
\end{document}
Result:
Notes:
textcomp is needed because both dfdsymbol and newtxtext load is with different options.
You have to decide yourself if fdsymbol is still needed in this case.

Left justification of nomenclature description in LaTeX

I'm using a LaTeX template (provided by ASME) to write a conference paper.
The asme2e.cls class defines a "nomenclature" environment as follows:
% Nomenclature environment
\newbox\tempbox
\newenvironment{nomenclature}{%
\newcommand\entry[2]{%
\setbox\tempbox\hbox{##1.\quad}
\hangindent\wd\tempbox\noindent{##1}\quad\ignorespaces##2\par}
\section*{NOMENCLATURE}}{\par\addvspace{12pt}}
which is used, in the .tex source file, as follows:
\begin{nomenclature}
% [...]
\entry{$C_{visc}$}{Viscous friction coefficient.}
\entry{$M$}{Spool mass.}
% [...]
\end{nomenclature}
resulting in the description texts not being left justified (since a fixed horizontal space is inserted between the symbol (e.g.: M) and the description (e.g.: Spool mass.), but the symbols have different lengths (e.g.: Cvisc is longer than M).
Is there a way to fix the class to have left-justified descriptions?
(I did a few experiments with \dimexpr and the calc package, but just got a bunch of errors).
(I also asked ASME if they could provide an updated template, but I'm still waiting for their feedback...)
I couldn't solve the problem, but I found a "quick and dirty" workaround, using the Tabbing and setspace packages.
Here is the new .tex source:
%[...]
\usepackage{Tabbing}
\usepackage{setspace}
%[...]
\begin{nomenclature}
{\setstretch{1.1}
\begin{tabbing}
\noindent
% [...]
\entry{$C_{visc}$}\quad\quad\={Viscous friction coefficient.}\\
\entry{$M$}\>{Spool mass.}\\
\entry{$v$}\>{Spool velocity.}\\
% [...]
\end{tabbing}
} % end \setstretch
\end{nomenclature}
%[...]
(Clearly, I'm completely bypassing the \entry command defined by the asme2e.cls class for the nomenclature environment).
I also tried to edit the asme2ej.cls file but nothing working for me. Then I ended up using the tabbing and set space packages. However, I did not use the \setstretch, and my document compiled just fine.
%[...]
\usepackage{Tabbing}
\usepackage{setspace}
%[...]
\begin{nomenclature}
\begin{tabbing}
\noindent
\entry{XYZ}\quad\quad\={This is an example}\\
\entry{PQR}\>{This is an example}\\
\entry{ZXC}\>{This is an example}\\
\entry{CVN}\>{This is an example}\\
\end{tabbing}
\end{nomenclature}
%[...]
I ran into a similar issue when submitting a paper to an ASME journal. My solution was to edit the asme2e.cls file:
\newenvironment{nomenclature}{%
\newcommand\entry[2]{\noindent\hbox to 0.05\textwidth{##1}\ignorespaces##2\par}
\section*{Nomenclature}}{\par\addvspace{12pt}}
You can change the amount of indentation by changing "0.05\textwidth".
I'm not sure if this is what you're asking, but see the following MWE:
\documentclass[12pt]{article}
\newlength{\nomenlabelindent}
\setlength{\nomenlabelindent}{4em}
\newenvironment{nomenclature}{%
\newcommand\entry[2]{%
\hangindent\nomenlabelindent\noindent\makebox[\nomenlabelindent][l]{##1\quad}\ignorespaces##2\par}%
\section*{NOMENCLATURE}}{\par\addvspace{12pt}}
\begin{document}
\begin{nomenclature}
\entry{$A$} {Parameter}
\entry{$B$} {Parameter}
\entry{$C$}{Parameter}
\entry{$D$}{Parameter}
\entry{$E$}{Parameter}
\end{nomenclature}
\end{document}
Output:
Nomenclature

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

How to create own and fancy \sub<float> command

I'm using packages subfigure and float to create figures and tables that I want to create and I'm trying to create my own environment graph with its own counter and caption (solved there, thanks to dmckee). Now I'd like to create \subgraph command which will do exactly the same as \subfigure command.
I tried create my own command with propreate counter (Assisted here, thanks to Alexey). But problem appears with using \ref command. Reference to \subfigure returns 2.1(a) but reference to \subgraph returns 1.
As I tried to find out how to solve this I read subfig manual, where I've found \newsubfloat command with an example. First error was in use of subfig's commands in subfigure and I got stuck there. If I use subfigure I can access \subfigure but can't force \subgraph working, when I use subfig I can acces \subfloat in graph but not in figure and \ref returns 1.0a instead of 1.1 (a).
definition by subfig package:
\newfloat{graph2}{tbph}{lom}[chapter]
\restylefloat*{graph2}
\floatstyle{plain}
\floatname{grap2}{Graph2}
\captionsetup[graph2]{position=top}
\newcommand{\listofGraphs}{\listof{Graph2}{List of Graphs}}
\newsubfloat[position=bottom,listofformat=subsimple]{graph2}
definition my own \subgraph
\newfloat{graph1}{H}{lop}[chapter]
\floatname{graph1}{Graph1}
\newcounter{GraphOne}[graph1]
\def\theGraphOne{\alph{GraphOne}}
\newcommand{\subgraph}[2][]{
\captionof{subGraph}{#1} #2
}
\newfloat{subGraph}{H}{lop}[graph1]
\floatname{subGraph}{}
Please help me with understanding how \label and \ref commands work (I think my solution collapses because \label is before \caption) and/or with forcing subfig package to work as I want.
Thank you for any idea and be merciful to my english.
Crowley
Improvement:
By using caption package I can create new counter (subGraph) and use it outside its environment. Only way how to have both counter (subgraph and graph) correcly referred is using \captionof{graph} before \subgraph.
So, my new question is: How to execute \captionof{graph} before subgraphs and typeset in below them? And how to force \ref to show 1.1-a instead of 1.1.1
Atachements:
Code for subfigure: (Returns <chapter>.<figure> (<subfigure>) correct.
\begin{figure}
\subfigure[sub-caption]{\includegraphics{fig1}\label{fig:1}}
\caption{main caption}
\end{figure}
\ref{fig:1}
Code for subfig: (Returns <chapter>.<graph2>-1<subfigure>) incorrect.
\begin{graph2}
\subfloat[sub-caption]{\includegraphics{fig1}\label{fig:2}}
\caption{main caption}
\end{graph2}
\ref{fig:2}
My code: (Returns <chapter>.<graph1>.<subgraph> but caption shows the same "adress")
\begin{graph1}
\captionof{graph1}{main caption}
\subgraph[sub-caption]{\includegraphics{fig1}\label{fig:3}}
\end{graph1}
\ref{fig:3}
I think your subfig solution should work (subfigure is deprecated anyway). The issue with the wrong references might have to do with you using \label incorrectly. You must have the \label command after the \caption, or as a part of it:
\begin{figure}
\caption{A Figure}
\label{fig}
\end{figure}
or
\begin{figure}
\caption{A Figure%
\label{fig}}
\end{figure}
Edit: the following "works for me". As I said, the \label is after the \caption:
\documentclass{report}
\usepackage{float}
\usepackage{subfig}
\newfloat{graph2}{tbph}{lom}[chapter]
\restylefloat*{graph2}
\floatstyle{plain}
\floatname{grap2}{Graph2}
\captionsetup[graph2]{position=top}
\newcommand{\listofGraphs}{\listof{Graph2}{List of Graphs}}
\newsubfloat[position=bottom,listofformat=subsimple]{graph2}
\begin{document}
\chapter{Test}
\section{Test s}
\begin{graph2}
\subfloat[sub-caption]{\fbox{Fig 1}}
\caption{main caption}
\label{fig:1}
\end{graph2}
\begin{graph2}
\subfloat[sub-caption]{\fbox{Fig 2}}
\caption{main caption}
\label{fig:2}
\end{graph2}
Graph~\ref{fig:1} is the first graph, and~\ref{fig:2} is the second.
\end{document}
This produces:
Graph 1.1 is the first graph, and 1.2 is the second.
I can't elaborate right now, but you want to use \refstepcounter instead of \addtocounter.

Resources