How can I attach a LaTeX marker to an arbitrary place in text? - latex

Is it possible to attach a marker to just a place in text, not to section, sub-section, etc.?
This is what I'm trying to achieve:
\begin{document}
Alex (see~\ref{alex}) is a boy,
Jessica (see~\ref{jessica}) is a girl.
[...]
\label{alex}\ref{alex}: Alex Johnson: 4 y.o.
\label{jessica}\ref{jessica}: Jessica D.: 5 y.o.
\end{document}
I want to get something like this:
Alex (see 1) is a boy,
Jessica (see 2) is a girl.
[...]
1: Alex Johnson: 4 y.o.
2: Jessica D.: 5 y.o.
Makes sense?

This is the solution:
\newcounter{foo}
Alex (see~\ref{alex}) is a boy,
Jessica (see~\ref{jessica}) is a girl.
[...]
\refstepcounter{foo}\thefoo\label{alex}: Alex Johnson: 4 y.o.
\refstepcounter{foo}\thefoo\label{jessica}: Jessica D.: 5 y.o.
Posted by Will at https://tex.stackexchange.com/questions/4021/how-to-set-a-marker-counter-label-to-an-arbitrary-piece-of-text

If you want to have a label, consider the following (from here);
\label{marker} You give the object you want to reference a marker, you can see it like a name.
\ref{marker} You can reference the object you have marked before. This prints the number that was assigned to the object.
\pageref{marker} It will print the number of the page where the object is.
Normally, if you reference to a label, LaTeX prints out the section, subsection, etc. But if you want to specify the exact place in text, you can use pageref. So with pageref you can exactly print out the page number of the "marker".
This is - as far as i know - the most exact possibility to tell the reader where in text a "marker" was, i.e. it is - as far as i know - impossible to tell LaTeX to print the exact line number or so.

You can use \label anywhere, including in the body of the text, but the thing labelled will be (roughly) the 'current labellable thing', that is the last \*section, or the current equation or table.
If you want to label something else (what is it you're after?) then you'll have to roll your own (not trivial), and have something which, if I recall correctly, sets \#currentlabel.
Edited, to add:
\begin{document}
\section{Hello}
Here is some text
\label{l1}
More text.
\newpage
Further text, on page 2
\label{l2}
This is section~\ref{l1} on page~\pageref{l1}.
And section~\ref{l2} on page~\pageref{l2}.
\end{document}
In both cases, the \ref refers to section 1, though the \pageref refers to pages 1 and 2 respectively. In both cases, the 'thing being labelled' is the section, and the text that goes in the label, and which appears in the \ref, is the section number.
So if you want to refer to an 'arbitrary place in the text', you have to ask yourself 'what is the text that would be produced by the \ref?'

Related

How do I use \renewcommand to get BACK my greek letters?

I'm a LaTeX newbie, but I've been doing my homework, and now I have a question that I can't seem to find the answer to.
I create the definition of an equation, let's just say it's this one:
The potential is characterized by a length $\sigma$ and an energy $\epsilon$.
In reality, this equation is more complex, which is why I wanted to try a shortcut. If my equation were this simplistic, I wouldn't try my substitution technique.
I use the \renewcommand to save me some time:
\renewcommand{\sigma}{1}
And this works fabulously and will replace all instances of sigma with 1. Unfortunately though, since \sigma has a global scope, I need to reset it.
I tried a couple different ways:
Attempt 1: -deadlock due to circular reference?
\newcommand{\holdsigma}{\sigma}
\renewcommand{\sigma}{1}
The potential is characterized by a length $\sigma$ and an energy $\epsilon$.
\renewcommand{\sigma}{\holdsigma}
I would think to reset the command, it should look something like this:
\renewcommand{\sigma}{\greek{\sigma}}
but that obviously hasn't worked out for me.
Any idea about how the greek letters are originally defined in the language?
I have to admit that I don't understand why you want to do what you're asking, but this should work:
\documentclass{article}
\begin{document}
Before redefinition, \verb|\sigma| looks like $\sigma$.
% Copy the current definition of \sigma to \oldsigma
\let\oldsigma\sigma
% Redefine \sigma to be '1'
\renewcommand{\sigma}{1}
After redefinition, \verb|\sigma| looks like $\sigma$.
You can still use \verb|\oldsigma| if you want to use the original definition $\oldsigma$.
% Restore the original definition of \sigma
\let\sigma\oldsigma
Now \verb|\sigma| is back to its normal appearance $\sigma$.
\end{document}
To find out how \sigma or any other command is originally defined, you can use \show\sigma. (The answer is that \sigma is defined as \mathchar"11B.) You can type this either in your document itself — compilation will pause and you can type Enter after reading the reply — or you can type this in TeX/LaTeX's interactive mode.
Example with a document:
\documentclass{article}
\begin{document}
What is $\sigma$? % Prints "What is σ" in the DVI/PS/PDF.
\show\sigma % Prints "> \sigma=\mathchar"11B." in the compilation.
Now that we know, let us redefine it.
\renewcommand{\sigma}{1}
Now it is: $\sigma$. % Prints "Now it is: 1." in the DVI/PS/PDF.
OK, let's go back.
\renewcommand{\sigma}{\mathchar"11B}
We again have: $\sigma$. %Prints "We again have: σ." in the DVI/PS/PDF.
\end{document}
Or else at the command prompt, type latex, then type \relax, then type \show\sigma, read what it says, then type x to exit.

Including a decimal in a Latex section number

I'm trying to get my latex sections to be labeled 1.0, 2.0 instead of 1, 2. Is there an easy way to do this or some way to define the specific numbers I want sections to be numbered?
EDIT:
I have this basic outline:
\documentclass[12pt]{article}
\begin{document}
\section{first}
\subsection{second}
\end{document}
I currently see:
1 first
1.1 second
I would like:
1.0 first
1.1 second
This should do the trick for you. Add the following lines to the preamble:
\renewcommand*\thesection{\arabic{section}.0}
\renewcommand*\thesubsection{\arabic{section}.\arabic{subsection}}
EDIT:
Changed from document type book to document type article. i.e. chapter replaced with section and section replaced with subsection.
EDIT:
Thanks for pointing out the \arabic command! I edited my answer accordingly.

Insert lecture number and page number of lecture in footline

I am dividing a semester's worth of lectures via the \lecture command.
I'd like to have in the footline (among other things) the lecture
number, date, and page number of the current lecture. I would also
like to use the default style footline, with the black box on the left
and the blue on the right. So I define a lecture with e.g.
\lecture{January 28, 2010}{lecture01}
with
\title[Lecture \insertlecturenumber{}(\insertlecture)\quad{}Page \insertframenumber]{Course Title}
in the preamble, I get an error; it will not accept \insertlecture
there. If I remove \insertlecture, it does what I want, except that
the page number is counted from the start of the semester, not the
lecture. Is there any way to do this? Thank you.
Liam
OK, I've finally found a solution to this. First, define
\newcounter{lectureframe}
\newcounter{lectureframestart} % The last frame number of the previous lecture
\newcommand{\lect}[2]{
\setcounter{lectureframestart}{\value{framenumber}}
\date{#1}
\lecture{#1}{#2}
}
and then I add a couple lines to the footline template, which is modified from CambridgeUS:
\setbeamertemplate{footline}
{
\setcounter{lectureframe}{\value{framenumber}}
\addtocounter{lectureframe}{-\value{lectureframestart}}
\leavevmode%
\hbox{%
\begin{beamercolorbox}[wd=.333333\paperwidth,ht=2.25ex,dp=1ex,center]{author in head/foot}%
\usebeamerfont{author in head/foot}\insertshortauthor
\end{beamercolorbox}%
\begin{beamercolorbox}[wd=.333333\paperwidth,ht=2.25ex,dp=1ex,center]{title in head/foot}%
\usebeamerfont{title in head/foot}\insertshorttitle
\end{beamercolorbox}%
\begin{beamercolorbox}[wd=.333333\paperwidth,ht=2.25ex,dp=1ex,right]{date in head/foot}%
\usebeamerfont{date in head/foot}\insertshortdate{}\hspace*{2em}
\insertframenumber{} / \inserttotalframenumber\hspace*{2ex}
\end{beamercolorbox}}%
\vskip0pt%
}
with the title:
\title[Classname\quad{}Lecture \insertlecturenumber
\quad{}Page \thelectureframe{}]{Classname Lecture}
Instead of using \lecture, I use \lect:
\lect{April 13, 2010}{lecture16}
Now the title appears appears in the center segment of the footline, and
the date on the right. This is what I was after.
Here's an answer to one of my questions. To reset the
page number at each section, use
\setcounter{framenumber}{0}
after (or before) the \lecture command.

Latex Multiple Linebreaks

I use LaTeX to type up programming homeworks for classes. I need to do this:
my line of text blah blah blah
new line of text with blank line between
I know I can use double slash to break lines \\, but LaTeX will only take the first line break (complains about more) and starts a new line, it produces this :
my line of text blah blah blah
new line of text with blank line between
How can I get that extra line break in there so I can have space between my lines of text?
Line break accepts an optional argument in brackets, a vertical length:
line 1
\\[4in]
line 2
To make this more scalable with respect to font size, you can use other lengths, such as \\[3\baselineskip], or \\[3ex].
Do you want more space between paragraphs? Then you can change the parameter \parskip.
For example, try
\setlength{\parskip}{10pt plus 1pt minus 1pt}
This means that the space between paragraphs is usually 10pt, but can grow or shrink by up to 1pt. This means you give LaTeX the ability to change it up to one 1pt in order to achieve a better page layout. You can remove the plus and minus parts to make it always your specified length.
If you are trying to display source code, try the listings package or use verbatim. If you are trying to typeset pseudocode, try the algorithm package.
Insert some vertical space
blah blah blah \\
\vspace{1cm}
to scale to the font, use ex (the height of a lowercase "x") as the unit, and there are various predefined lengths related to the line spacing available, you might be particularly interested in baselineskip.
You can use the setspace package which gives you spacing environments, e.g.:
\documentclass{article}
\usepackage{setspace}
\begin{document}
\doublespace
my line of text blah blah blah
new line of text with blank line between
\end{document}
Or use a verbatim environment to control the layout of your code precisely.
For programs you are really better off with a verbatim or alltt environment, but if you want a blank line that LaTeX will not bitch about, try
my line of text blah blah blah\\
\mbox{ }\\ %% space followed by newline
new line of text with blank line between
While verbatim might be the best choice, you can also try the commands \smallskip , \medskip or guess what, \bigskip .
Quoting from this page:
These commands can only be used after
a paragraph break (which is made by
one completely blank line or by the
command \par). These commands output
flexible or rubber space,
approximately 3pt, 6pt, and 12pt high
respectively, but these commands will
automatically compress or expand a
bit, depending on the demands of the
rest of the page
I find that when I include a blank line in my source after the \\ then I also get a blank line in my output. Example:
It's time to recognize the income tax as another horrible policy mistake like banning beer, and to return to the tax policies that were correct in the Constitution in the first place. Our future depends on it.
\\
Wherefore the 16th Amendment must forthwith be repealed.
However you are correct that LaTeX only lets you do this once. For a more general solution allowing you to make as many blank lines as you want, use \null to make empty paragraphs. Example:
It's time to recognize the income tax as another horrible policy mistake like banning beer, and to return to the tax policies that were correct in the Constitution in the first place. Our future depends on it.
\null
\null
\null
Wherefore the 16th Amendment must forthwith be repealed.
\\\\
This works on pdfLatex. It creates 2 new lines for you.
Maybe try inserting lines with only a space?
\ \\
\ \\
This just worked for me:
I was trying to leave a space in the Apple Pages new LaTeX input area. I typed the following and it left a clean line.
\mbox{\phantom{0}}\\

How does one change the \paragraph formatting in LaTeX

This stems out of How can one number paragraphs in LaTeX?, which I asked earlier today:
Running with Brent.Longborough's suggestion for how to number paragraphs in a document:
\setcounter{secnumdepth}{5}
...
\paragraph{If we want to}
\paragraph{do something}
This results in LaTeX producing something likeso:
0.0.0.1 If we want to
0.0.0.2 do something
How can one change the numbering scheme of \paragraph{} to produce something like:
1. If we want to
2. do something
or alternatively
A. If we want to
B. do something
Thank you.
To change the number referenced when referring to paragraphs, you want to change \theparagraph. Here's an example:
\documentclass[12pt]{article}
\setcounter{secnumdepth}{5}
\renewcommand\theparagraph{\roman{paragraph}}
\usepackage{lipsum}
\begin{document}
\paragraph{foo} \lipsum[1]
\paragraph{bar} \lipsum[2]
\end{document}
Instead of \roman you can also use \Roman, \arabic, \alph, \Alph. Although if you have lots of paragraphs you'll want to use the alphalph package and use \alphalph to get more than 26 paragraphs.
Note that \paragraph takes an argument for the "paragraph title". If you never want that, you'll probably want to define your own command to simplify things:
\newcommand\PARA{\paragraph{}}
You'll also probably want to remove the way that paragraphs are numbered "within" sections; i.e., they reset from "1" for every new section. You can get around this with something like
\usepackage{remreset}
\makeatletter
\#removefromreset{paragraph}{section}
\makeatother

Resources