When I include \overline{x} or other special characters in the caption text of a table, the whole caption text won't appear at all. When I put simple text without special characters, the caption works fine. How can I include special characters in the caption?
Are you putting $ around the maths? I.e.:
\caption{This is a caption with maths $\overline{x}$ in it.}
Apparently your real problem was that TeX's fancy error correction mechanism prevented you from knowing that there was a syntax error in the document. Back in 1982 or so, running TeX on a long document would take so much time that Knuth didn't want TeX to just quit when it ran into an error. Instead, TeX tries to guess what you meant and go on typesetting the document, so that you can fix a bunch of errors before you run it again; for example, when it spots a math-mode command outside math mode, it assumes that you forgot a dollar sign and inserts it. No automatic error-correction mechanism is perfect, so syntax errors often cause some part of text to be lost, or typeset in a wrong way.
TeX does try to tell you that it has found errors, but I suppose current IDEs make it easy to ignore the output. Try running latex on the document from the command line and pay attention to what it says. For example, the short document
\documentclass{article}
\begin{document}
It seems \sqrt{2} I forgot some dollar signs.
\end{document}
causes TeX to prompt you with
! Missing $ inserted.
<inserted text>
$
l.3 It seems \sqrt{
2} I forgot some dollar signs.
?
The 2009 way of dealing with this is to type X to quit, fix the source document, and run latex again - but you can actually enter other commands at the prompt to edit the input that TeX sees. If you just type Q (to run quietly - same as specifying \batchmode, which Emacs or whatever IDE you are using probably does for you) you get a typeset document as a result, and it might not be obvious that there are in fact syntax errors in it.
If you looking for how to insert any special character in Latex in a table then this may help you. Check this out...
\documentclass{article}
\begin{document}
\begin{tabular}{|l|r|r|}
Item & Quality & Price(\$)\\
Nails & 500 & 34\\
Wooden boards & 100 & 4\\
Bricks & 240 & 11\\
\end{tabular}
\end{document}
Related
Page 167 of "The TeXBook", line 5
... $F_n=F_{n-1}+F_{n-2}$, \ $n\ge2$.}$$
I tried to write the omitted part completely, as I understand it should be written:
$${\rm The\ Fibonacci\ numbers\ satisfy\ $F_n=F_{n-1}+F_{n-2}$, \ $n\ge2$.}$$
But the above code can't be compiled under plain TeX (error hint: "Missing } inserted.")
Is it not possible to insert $...$ in a $$...$$?
Environment: macOS, TexShop 5.03 (with plain TeX selected), MacTeX 2022
What is the correct way to complete it?
Thanks for your comment.
I found that the following code compiles successfully, but I'm not sure whether this is the author's intention, and I don't quite understand the meaning of using $$...$$ here, is it just for more vertical whitespace?
$$\centerline{The Fibonacci numbers satisfy $F_n=F_{n-1}+F(n-2)$, \ $n\ge2$.}$$
If you look into the source code of the TeXbook, you will find that this line was typset like this:
\begindisplay
The ^{Fibonacci} numbers satisfy $F_n=F_{n-1}+F_{n-2}$, \ $n\ge2$.
\enddisplay
Indeed, the use of $$ is not a good idea in this case, since this will introduce display math mode, which not only adds some whitespace, but also switches to math mode (just like $ does) and additionally typesets the part between $$ and the next $$ centered on a separate line. Since $$ already introduces math mode, TeX will complain if it encounters a single $.
Now, the above example consists only of a short math part while the rest is non-math. Therefore, not the whole sentence should not be typeset in math mode, but only the math part of it. Hence, the use of $$ would not make much sense here.
I don't know why it is stated on page 167 that the sentence was printed using $$ which is obviously wrong. Maybe it is just a mistake.
As for your last example: If you use \centerline, you essentially step out of math mode. Since the stuff inside the argument of \centerline is not typeset in math mode, another single $ is not a problem here. This is why your example compiles just fine. But it is probably not the best idea to place \centerline inside $$...$$.
I know one of LaTeX's bragging points is that it doesn't have this Microsoftish behavior. Nevertheless, it's sometimes useful.
LaTeX already adds an extra space after you type a (non-backslashed) period, so it should be possible to make it automatically capitalize the following letter as well.
Is there an obvious way to write a macro that does this, or is there a LaTeX package that does it already?
The following code solves the problem.
\let\period.
\catcode`\.\active
\def\uppercasesingleletter#1{\uppercase{#1}}
\def.{\period\afterassignment\periodx\let\next= }
\def \periodx{\ifcat\space\next \next\expandafter\uppercasesingleletter \else\expandafter\next\fi}
First. second.third. relax.relax. up
\let\period. save period
\catcode\.\active make all periods to be active symbol (like macro).
\def\uppercasesingleletter#1{\uppercase{#1}} defines macro \uppercasesingleletter to make automatically capitalize the following letter.
\def.{\period\afterassignment\periodx\let\next= } writes saved period and checkes the next symbol.
\def \periodx{\ifcat\space\next \next\expandafter\uppercasesingleletter \else\expandafter\next\fi} If the next letter is a space then \uppercasesingleletter is inserted.
ages ago there was discussion of this idea on comp.text.tex, and the general conclusion was you can't do it satisfactorily. satisfactory, in my book, involves not making characters active, but i can't see how that could work at all.
personally, i would want to make space active, and have it then look at \spacefactor and \MakeUppercase the following character if the factor is 3000.
something like
\catcode\ \active % latex already has a saved space character -- \space
\def {\ifhmode% \spacefactor is invalid
% (or something) in vertical mode
\ifnum\spacefactor<3000\else% note: with space active,
% even cs-ended lines need %-termination
\expandafter\gobbleandupper\fi}%
\def\gobbleandupper#1{\def\tempa{#1}\def\tempb{ }%
\ifx\tempa\tempb% can''t indent the code, either :-(
% here, we have another space
\expandafter\gobbleandupper% try again
\else\space% insert a "real" space to soak up the
% space factor
\expandafter\MakeUppercase\fi}%
this doesn't really do the job -- there are enough loose ends to knit a fairisle jumper. for example, given that we can't rely on \everypar in latex, how do you uppercase the first letter of a paragraph?
no ... however much it hurts (which is why i avoid unnecessary key operations) we need to type latex "properly" :-(
I decided to solve it in the following way:
Since I always compile the LaTeX code three times before i okular the result (to get pagination and references right), I decided to build the capitalization of sentences into that process.
Thus, I now have a shell script that calls my capitalization script (written in CRM114) first, then pdflatex three times, and then okular. This way, all the stuff happens as the result of a single command.
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}{ }\\
My intuition was
Lorem ipsum\footnote{long footnote
that spans a whole
bunch of
lines.
}
But regardless of where I put the { and } in relation to the footnote text, I get the following error:
Latex Error: ./mydoc.tex:142 Package inputenc Error: Unicode char \u8:― not set up for use with LaTeX.
Footnotes are filled in the availible space just like any other paragraph: you just write
\footnote{
a whole lot of text that goes on and on and on and...
...
and may consists of multiple sentences. But after a while
...
it finally comes to a stop.
}
That is not your problem. looking at the error message (which I don't recognize from personal experience), I'd say your problem is character set or font related.
Is you editor using unicode?
The error you're getting indicates there's a coding setup issue. Googling the error message suggests you may be running TexShop, or you need to install latex unicode support. use
apt-get latex-ucs
or something similar and try it again.
I get this error a lot when I cut text from another document and paste into LaTeX. My plain text editor doesn't warn me that I pasted in some bad character. Although it is tedious, you can
comment out the entire text of your footnote, replace it by XX, and confirm that now your document runs
retype the entire text of your footnote by hand.
This always works for me. As a shortcut, you may be able to see a punctuation mark that is the culprit and simply fix that.
In the example you gave, it looks like maybe you got an em-dash character that needs to be replaced by the standard LaTeX construction of two or three hyphens.
I'm using LaTeX's "listings" package to format source code. Unfortunately I get curly quotes instead of straight quotes. Since the curly quotes don't always point in the right direction, it looks bad. How can I get straight quotes instead?
I'd prefer not to change or filter the source code itself. Filtering the code to properly change " to `` or '' would work, but this is easier done than said with multiple quotes on a line, or quotes spanning multiple lines. Or you could use symbol or a host of other things. But I'd really like to keep the source unchanged.
Example LaTeX:
\documentclass{article}
\usepackage{listings}
\begin{document}
\begin{lstlisting}
Fahrenheit=input("What is the Fahrenheit temperature?")
Celsius=(5.0/9.0)*(Fahrenheit-32)
print"The temperature is",Celsius,"degrees Celsius"
\end{lstlisting}
\end{document}
Example output (using Miktex on windows):
(Direct link to image of incorrect output)
I see in the documentation (which should have been distributed with the packge, but is available at http://www.ctan.org/tex-archive/macros/latex/contrib/listings/listings.pdf) for listings that there is a settable property called upquote to take care of this.
From the documentation:
upquote=⟨true|false⟩ false
determines whether the left and right quote are printed ‘’ or `'. This
key requires the textcomp package if true.
Do something like
\lstset{upquote=true}
before begining the list environment, or use
\begin{lstlisting}[upquote=true]
...
\end{lstlisting}
It is also possible that tis property is already set for you in the appropriate language
definition (see the docs again, big list of predefined languages on page 12).
Use:
\lstloadlanguages{<dialects you need>}
in the header. And then set the language using either of the above conventions for choosing options.
Have you considered using a monospaced (typewriter) font for the listing? The following example works:
\documentclass{article}
\usepackage{listings}
\lstset{basicstyle=\ttfamily} % <<< This line added
\begin{document}
\begin{lstlisting}
Fahrenheit=input("What is the Fahrenheit temperature?")
Celsius=(5.0/9.0)*(Fahrenheit-32)
print"The temperature is",Celsius,"degrees Celsius"
\end{lstlisting}
\end{document}
dmckee's answer above probably works. If you drop your last condition, i.e. you permit changes to the code, then there is a more generic solution, which I tend to use whenever (La)TeX renders a character somehow differently than I expect it to do is to use the \symbol command. I list it here because it can be useful in other situations as well:
\newcommand{\qq}{\symbol{34}} % 34 is the decimal ascii code for "
And then your example:
\begin{lstlisting}
...
print{\qq}The temperature is{\qq},Celsius,{\qq}degrees Celsius{\qq}
...
\end{lstlisting}
Note the curly braces which supposedly take listings back to LaTeX mode (see escapechars option of the package.)
Here is a solution
\usepackage[T1]{fontenc}
\usepackage{textcomp}
\usepackage{lmodern}
% in the listings package configuration, try:
literate={"}{\textquotedbl}1,
I had the same problem, using fontspec, and the solution was to not set \defaultfontfeatures{Mapping=tex-text}, but instead setting Mapping=tex-text specifically on only the main and sans font, and leaving the tt font to it's own devices. :)
Maybe it's because I installed listings early as a LaTeX user, but I'm surprised to learn that without the listings package the behaviour is any different.
My solution was similar to David Hanak's, but I used the symbols for double-quote as described in the LaTeX Cheat Sheet (http://stdout.org/~winston/latex)
\newcommand{\QQ}[1]{``#1''}