Why does LaTeX start a new line when making a reference - latex

I just created a LaTeX document and compile it to a PDF using pdftex. Every time I make a reference using the \ref command, the reference is put on a new line. Why does this happen and how do I prevent this?

Are you by any chance using \\ in URLs instead of //? \\ is used as a linebreak in TeX.
Try to localize the problem: create a new file which initializes hyperref the same way, uses no other packages, and has some text and a reference. Check if references still start on new lines. If they do, you can show it here (and on LaTeX forums); if not, add more of your report's preamble until you get a file which exhibits the problem.

Can you prepare a minimum example demonstrating your problem?
I've tried with:
\documentclass{report}
\usepackage[pdftex,breaklinks=true,bookmarks=true,bookmarksopen= true,pdfpagemode=UseNone,plainpages=false,pdfpagelabels,pdfstartview=FitH,olorlinks=true,citecolor=blue]{hyperref}
\begin{document}
Test \url{http://test.com} \ref{http://someother.com}.
\end{document}
And the whole output is a single line in PDF.
BTW \ref is used to produce internal document links (like in "As described in chapter \ref{chapter:second}...").

It was my own fault, I used \par for the paragraph sign instead of \P. This is one of my first LaTeX documents, so I overlooked it. Thanks for the quick responses/answers though.

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.

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 ;-).

Example for a simple LaTeX glossary

I'm trying to include a simple glossary to my LaTeX document,
I already searched for something like that on google, but never got it running.
I would like to use glossary or glossaries.
how to write it in the text?
how to print it?
what to execute on which position?
Well, there is a glossaries package on CTAN. Read the pdf documentation.
Check if you already have it in your installation, if not install it, and put \usepackage{glossaries} in the preamble of you document and it will be available to you.
It looks like you need \usepackage{glossaries} and \makeglossaries in the preamble, and some number of \newglossaryentry and \newacronym calls (it is not immediately clear to me if these only go in the premble or can go in the document text). Finally, you will need one or more \printglossary calls in the text. Use \gsl to connect glossary entries on the argument with the pages they occur on.
Processing the file will have to include a call to makeglossaries followed by at least one more invokation of latex.
In addition to the samples mentioned in the documentation there is a Stack Overflow question which includes a minimal file making use of glossaries. You may be particularly interested in the acronym glossary.
There is a nice blog for beginners: LaTeX glossary and list of acronyms
Here is an example:
\documentclass{article}
% Load the package
\usepackage{glossaries}
% Generate the glossary
**\makeglossaries**
\begin{document}
%Term definitions
\newglossaryentry{utc}{name=UTC, description={Coordinated Universal Time}}
\newglossaryentry{adt}{name=ADT, description={Atlantic Daylight Time}}
\newglossaryentry{est}{name=EST, description={Eastern Standard Time}}
% Use the terms
\gls{utc} is 3 hours behind \gls{adt} and 10 hours ahead of \gls{est}.
%Print the glossary
\printglossaries
\end{document}

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}{ }\\

glossaries package and footnote in LaTeX

I am currently stuck, having two separate glossaries: main & acronyms. Acronyms glossary prints footnotes on first use in the text, but main glossary does not. Is there any way to make any other glossary than acronyms to print footnote on first use of the term? I don't get how to do it.
Here is the code example compiled with TeXnic Center and MiKTeX 2.7:
\documentclass{article}
\usepackage{index}
\usepackage[toc,style=long3colheaderborder,footnote,acronym]{glossaries}
\makeindex
\makeglossaries
\newglossaryentry{appdomain}{name={application domain}, description={app Domain Description...}}
\newglossaryentry{sample}{name={[has been inserted aaa]},description={testing testing 123}}
\newacronym{aca}{aca}{a contrived acronym}
\begin{document}
\section{this is a test section}
This is the test line... a \gls{sample} \gls{appdomain}
\index{entry} and \gls{aca}
\thispagestyle{empty}\cleardoublepage
\printglossary[type=main,title={Glossary},toctitle={Glossary}]
\thispagestyle{empty}\cleardoublepage
\printglossary[type=\acronymtype,title={List of Abbreviations},toctitle={List of Abbreviations}]
\printindex
\thispagestyle{empty}\cleardoublepage
\end{document}
I want sample and appdomain either contain a footnote with description or a footnote stating: please refer to Glossary
Many thanks,
Ovanes
In short, with the glossaries package, you can't get footnotes on the first use for non-acronym glossaries.
However, you can redefine some commands in the preamble (after you \usepackage{glossaries}) to get what you want:
\makeatletter
\renewcommand{\gls#main#displayfirst}[4]{
#1#4\protect\footnote{#2}
}
\makeatother
But that will be really fragile.
I think there is an easier way of doing this. Maybe it's new, but
\defglsdisplayfirst[main]{#1#4\protect\footnote{#2}}
appears to achieve the exact same thing (correct me if I'm wrong). See the glossaries manual, version 2.03, subsection 2.4.1 changing the format of the text.
Unfortunately, it appears commands like \gls or \autoref does not work in those footnotes.
Following is a good technique, to put a footnote stating where the definitions are:
\label{nom} %put this on the page your term appears, so that it can collect page number
\newcommand{\g}{\footnote{For all abbreviations see the glossary on page \pageref{nom}.}}
I've found this from here.

Resources