latex undefined control sequence with tableofcontents - latex

I was using \documentclass{amsmath} for awhile with no issues, but I recently wanted to switch to the normal \documentclass{article} because I thought it looked nicer. However, now my \tableofcontents command produces this error:
! Undefined control sequence.
<argument> \tocsection
{}{1}{Purpose}
l.1 ...ne {section}{\tocsection {}{1}{Purpose}}{4}
?
I'm writing a research paper with latex, and Purpose is the first section (the command I'm using is \section{Purpose}). It's saying line 1 has the error, which is \documentclass{article}. Can anyone help me with this error?

1) Most probably "l.1" refers to the first line of the TOC file, not of the TEX file. It's impossible to tell for sure from the little snippet you've shown.
2) First thing to try in this situation will be to delete (or better to move to some temp. place) all the TeX-generated files in your working folder. Usually this means that only TEX and BIB files should remain (and any figures if you have them). Then run the usual latex; bibtex; latex; latex sequence.
3) If you still get the same error, there is probably some package conflict. To diagnose that, we'll need all of your preamble.

Related

Undefined control sequence when using \includepdf

I'm new to LaTeX. I am trying to include a PDF file using Overleaf and I don't know why I got several errors: "undefined control sequence", "PDF not found". I think I have uploaded the PDF file right, I don't know what might be the problem.
I don't know how to copy the exact text of the error so I have attached some images.
I have read some posts about updating something in MiKTeX. I don't know what MiKTeX is and I don't know if I am using it.
This is the structure of my document:
\documentclass{article}
% General document formatting
\usepackage[margin=0.7in]{geometry}
\usepackage[parfill]{parskip}
\usepackage[utf8]{inputenc}
\usepackage[final]{pdfpages}
% Related to math
\usepackage{amsmath,amssymb,amsfonts,amsthm}
\begin{document}
Name, date, Exercise X
\section*{Part a}
\section*{Part b}
\includepdf[pages=1-2]{ProblemasPNG.pdf}
\end{document}
So as hinted by #samcarter_is_at_topanswers.xyz in the comment, you named the file wrong. Though you may use \includepdf[pages=1-2]{filename.pdf}, I think its best practice to use \includepdf[pages={1-2}]{filename.pdf}. This will also allow you to skip certain pages using \includepdf[pages={1-2,5}]{filename.pdf}, thus skipping pages 3 and 4.

latex: how to "\input" a file whose filename depends on "~"?

in a latex file called "main.tex" i can write the line
\input /home/user1/defs.tex
to input the conents of "defs.tex" at the position of that command.
now i want to generalize this, so that any user can compile the tex-document and "defs.tex" inside his home-directory is being inserted. my first guess
\input ~/defs.tex
didnt work. does anyone know how to solve this?
https://tex.stackexchange.com/questions/1728/accessing-environment-variables-within-a-document
Thus, it would seem that:
\documentclass{article}
\immediate\write18{echo $HOME >/tmp/foo.tex}
\begin{document}
\input{var}
\end{document}
might do the trick. Or some such.
NOTE: I'm not a TeX expert, so be sure to read the referenced article carefully, and be prepared to experiment.

How do I ref a figure in LaTeX before it occurs?

I always like my figures to be placed in between text as opposed to the top or bottom of the page. I also like to talk about the figure before it is shown. So I am trying to have something like this:
By looking at Figure~\ref{fig:VCO} you can see that blah blah blah.
\begin{figure}[h]
\caption{VCO test circuit}\label{fig:VCO}
\begin{center}
\includegraphics[width=0.9\columnwidth]{figures/VCO_circuit.eps}
\end{center}
\end{figure}
This doesn't seem to work because it I guess it is referencing something that hasn't occurred yet? Does anyone have some simple solution? I am still very new to LaTeX.
Generally LaTeX needs at least two passes to resolve all its references, the first time to write them to an auxiliary file and the second time to put them into the final ps/pdf/dvi file. So it does not matter where the reference is.
A third pass will be needed, for example, if your document has a long table-of-contents which will screw up page numbers.
It failed the first time because labeling and referencing are a two-pass process. The first time you processed your latex, all the labels were being indexed so the ref failed. The second time around, since the labels had been indexed the ref knew what it was actually referencing.
I would add that latexmk (link) has proven invaluable to me over the years. This is a LaTeX "build" script written in Perl that is designed to compile .tex source files the right number of times. It parses the output from the latex command and performs dependency checking to ensure that the output document is kept up-to-date with the minimum number of passes. It can also deal with BibTeX bibliography files. Generally speaking, I invoke latexmk from either an Ant or GNU Make makefile and treat it just like I'm compiling C++ code, for example.
I had same problem and I found this solution:
\graphicspath{{images/}}
\DeclareGraphicsExtensions{.jpg}
\makeatletter
\newenvironment{tablehere}
{\def\#captype{table}}
{}
\newenvironment{figurehere}
{\def\#captype{figure}}
{}
\makeatother
\begin{figurehere}
\includegraphics[height=5cm]{2-14aGa-Sur.jpg}
\caption{Hliněná destička s mapou severu Mezopotámie}
\label{fig:Ga-Sur}
\end{figurehere}
\graphicspath{{images/}} is there to declare your path to your pictures
\DeclareGraphicsExtensions{.jpg} is there for declare picture extension (multiple can be with comma (I think ;-))
\makeatletter
\newenvironment{tablehere}
{\def\#captype{table}}
{}
\newenvironment{figurehere}
{\def\#captype{figure}}
{}
\makeatother
is there for precise determination of position here
\begin{figurehere}
\includegraphics[height=5cm]{2-14aGa-Sur.jpg}
\caption{Hliněná destička s mapou severu Mezopotámie}
\label{fig:Ga-Sur}
\end{figurehere}
there is your picture with height specified and caption and label with it...
I hope it will help you ;-).

Problem in Latex: "There's no line here to end"

I'm using Lyx to produce a Latex document, and when i try to convert to pdf, it complains of the error: "there's no line to end", and description is "//".
My Latex document is like 200 lines without many line breaks. How am I supposed to debug this and get this darned pdf converted. I literally am stuck on this for hours, can't submit this pdf. And for 90% of the time while writing this document, the convert to pdf works fine, I don't know know since what point did it start to fail.
Someone give me a quick way to get rid of this error? Otherwise this Latex document is useless.
Thanks.
That may sound stupid, but sometimes Latex needs a sign before the \, therefore:
~\\
That very much depends on the distribution you chose. LyX btw. is kind of crazy, when it comes to LaTeX export. Try auctex if you've got a month or two to spare ;)
IMO this is the problem with LyX; when things go wrong it's hard to know where to look to fix the problem. This is a minimal document that shows an example of the error:
\documentclass{article}
\begin{document}
\\ there
\end{document}
I suggest exporting your LyX document to LaTeX, then compiling it "by hand" (with pdflatex mydoc or whatever) and see where in the document the error is appearing. You should then be able to correlate it with some misbehaving piece of the LyX document.
Do a binary search. Delete half the document, if it compiles then the problem was in the part you deleted. If not, then it's in the half you kept. Repeat the procedure on the offending portion and you should soon find which line is causing it.
Dear Saobi, please post the offending line. Probably you have a "\" in a single-line math environment. If you post the code for the complete environment, I can try to indicate how to prevent this error.
You can go to View -> View Source and click around until you find the offending line. In latex, line break is \\.
After doing that I realized the problem is you can't put a line break (Ctrl+Enter) at the start of a line (or cell). You can cheat by forcing a space (Ctrl+Space) before the line break. :)
My approach for locating compilation errors in LaTeX documents is based on a binary search approach. I suppose that a similar approach can be used in LyX.
The key idea is to divide your document in two parts of approximately the same size. At the boundary between these two parts a line containing \end{document} is inserted. If the document now can compile with no problems, the problem were located in the second half part of the document (otherwise it were in the first half part).
\documentclass{article}
\begin{document}
% First half part of the document
\section{Hello}
% Location for inserting \end{document}
% Second half part of the document
% in which the error is located
\section{World
\end{document}
In addition, check out that your LaTex lines already have content. I wrote an empty line, and It also causes error, from my experience.
\vspace{1cm}{ }\\

Why does using ledpar cause a document to fail?

Here is my minimal LaTeX document:
\documentclass{article}
\usepackage[polutonikogreek,english]{babel}
\newcommand{\Gk}[1]{\selectlanguage{polutonikogreek}#1\selectlanguage{english}}
\usepackage{ledmac}
\newcommand{\cn}[1]{\Afootnote{#1}}
\usepackage{ledpar}
\begin{document}
\beginnumbering
\pstart
\edtext{apostle}{\cn{\Gk{apostoloc}}}
\pend
\endnumbering
\end{document}
Executing latex test.tex produces the following error:
...
Section 1 (./test.1)
! Missing control sequence inserted.
<inserted text>
\inaccessible
l.15 \pend
?
Some notes:
The DVI produced looks fine despite the error.
Commenting out the \usepackage{ledpar} fixes the problem.
Not using the \Gk command also solves the problem. (But sort of defeats the purpose of having a footnote.)
What's going on here and how do I get around the error message?
According to the FAQ:
Sometimes LaTeX saves data it will reread later. These data are often the argument of some command; they are the so-called moving arguments. (‘Moving’ because data are moved around.) Candidates are all arguments that may go into table of contents, list of figures, etc.; namely, data that are written to an auxiliary file and read in later. Other places are those data that might appear in head- or footlines. Section headings and figure captions are the most prominent examples; there’s a complete list in Lamport’s book (see TeX-related books).
What’s going on really, behind the scenes? The commands in moving arguments are normally expanded to their internal structure during the process of saving. Sometimes this expansion results in invalid TeX code, which shows either during expansion or when the code is processed again. Protecting a command, using “\protect\cmd” tells LaTeX to save \cmd as \cmd, without expanding it at all.
So the \Gk command gets expanded too early in the process of TeXing the file and results in illegal code. The simplest solution is to declare the command robust:
\usepackage{makerobust}
\DeclareRobustCommand{\Gk}[1]{\selectlanguage{polutonikogreek}#1\selectlanguage{english}}
As to why using the ledpar package produces the error, I'm less certain. In order to facilitate notes in both the left and right side of parallel text, the ledpar package needs to redefine virtually every command provided by the ledmac package. Although I have not found the offending difference, one or more of the redefinitions must cause fragile commands to be expanded prematurely.

Resources