I'm trying to save some text inside an environment for later use. The smallest test case I could come up with is this. The saved text in the sbox isn't available after the environment is closed. How can I work around that? Thanks.
\documentclass{article}
\begin{document}
\newsavebox{\somebox}
\begin{itemize}
\item hello1
\item hello1 \sbox{\somebox}{Some text}
\end{itemize}
This should show something, but does not: "\usebox{\somebox}"
\end{document}
What you're running into here is a scoping issue. In (La)TeX, you can introduce scopes with { ... }, \bgroup ... \egroup, or \begingroup ... \endgroup. The former two are roughly the same, as \bgroup and \egroup are defined by \let\bgroup{ and \let\egroup}; the last one is slightly different. But the scoping property is the same: any commands, boxen, etc., created or modified within those scopes are not visible outside. And in LaTeX, all environments \begin{env} ... \end{env} implicitly wrap their contents in \begingroup ... \endgroup. This means that your\sbox{\somebox}{Some text} modification is only visible until the \end{itemize}; after that, the modification is undone. To get around this, prepend any command like \newcommand, \def, \newsavebox, \sbox, etc., with \global, which forces the definition to take place at the global scope and be visible everywhere.
Also, to use quotes in (La)TeX, write ``double quoted'', ``double quoted", or `single quoted'; the " character is only for closing quotes, not opening quotes. Putting this all together gives you the revised snippet
\documentclass{article}
\begin{document}
\newsavebox{\somebox}
\begin{itemize}
\item hello1
\item hello1 \global\sbox{\somebox}{Some text}
\end{itemize}
This should show something, and in fact does: ``\usebox{\somebox}''
\end{document}
I think I can work around this by using \def. like so:
\documentclass{article}
\begin{document}
\begin{itemize}
\item hello1
\item hello1
\global \def \somebox {Some text}
\end{itemize}
This should show something: \somebox
\end{document}
Related
In latex, I need to start an item in an enumerate list with an align* environment, but this environment starts with a new line, leaving an ugly empty space.
What I'm trying to achieve:
e^{ix}=cos x+i sin x
e^{i\pi} = -1
e^{i\pi}+1=0
What I'm trying:
\begin{enumerate}
\item \begin{align*}
e^{ix}&=\cos x+i\sin x\\
e^{i\pi}&=-1\\
e^{i\pi}+1&=0
\end{align*}
\end{enumerate}
Is there some other environment for this?
(I know that it is not recommended to start an item with a displayed math formula, but in this case I need to.)
As a workaround:
\documentclass{article}
\usepackage{mathtools}
\begin{document}
\begin{enumerate}
\item \hfill$\begin{aligned}[t]
e^{ix}&=\cos x+i\sin x\\
e^{i\pi}&=-1\\
e^{i\pi}+1&=0
\end{aligned}$\hfill\mbox{}
\end{enumerate}
\end{document}
A hack similar to the one in the accepted answer: the environment matrix needs no package to work and has no visible delimiters:
\documentclass{article}
\begin{document}
\begin{enumerate}
\item $\begin{matrix}
e^{ix}&=\cos x+i\sin x\\
e^{i\pi}&=-1\\
e^{i\pi}+1&=0
\end{matrix}$
\end{enumerate}
\end{document}
The output seems to me similar to the one you wanted to achieve:
I am trying to make a .tex template for a book of abstracts for the conference. I want the template to be compilable, so the participants are able to see their abstracts separately before submitting. Moreover I want to use the files to compile the book of abstracts with table of contents and titles.
So, I have master file
\documentclass[12pt]{combine}
\usepackage{authblk}
\begin{document}
\tableofcontents
\begin{papers}
\coltocauthor{Crist\'{o}bal Josevich Junta, Fyodor Simeonovich Kivrin}
\coltoctitle{Title of the first abstract}
\import{first}
\coltocauthor{Roman Oyra-Oyra}
\coltoctitle{Title of the second abstract}
\import{second}
\end{papers}
\end{document}
And two imported files are:
\documentclass{article}
\usepackage{authblk}
\title{Title of the first abstract}
\author[1]{Crist\'{o}bal Josevich Junta}
\author[2]{Fyodor Simeonovich Kivrin}
\affil[1]{Department of the Meaning of Life}
\affil[2]{Department of Linear Happiness}
\begin{document}
\maketitle
Text of the first abstract.
\end{document}
and
\documentclass{article}
\usepackage{authblk}
\title{Title of the second abstract}
\author[1]{Roman Oyra-Oyra}
\affil[1]{Laboratory of the most unexpected sciences}
\begin{document}
\maketitle
Text of the second abstract.
\end{document}
The problem is the second \maketitle does not print authors names and their affiliation.
I have tried using redefined \settitle instead of \maketitle
\makeatletter
\newcommand{\settitle}{\#maketitle}
\makeatother
it did not help.
Also, I tried titling package, which led to no change.
I want \maketitle to print the names and affiliations or to find out the better way to automatically make titles for each abstract.
Hi I'm new to LaTeX and I'm having some troubles in write a Use Case Specification using the style in this picture.I've tried using listings but i can't succeed in underlying some words.Anyone can help me?
I made a command so you can easily without much typing make multiple usecases, this is the complete latex code with 1 example, you can modify the command, it takes 5 parameters and you can access them with the #:
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{enumitem}
\newcommand{\spec}[5]{
\begin{description}
\item[\underline{SpecificaUseCase}] #1 \\
#2
\begin{itemize}[noitemsep,topsep=-8pt]
\item[] \underline{pre}: #3
\item[] \underline{post}: #4
\end{itemize}
\item[\underline{FinalSecifica}] #5 \\
\end{description}
}
\begin{document}
\spec{usecasename}{method}{pre stuff}{post stuff}{final}
\end{document}
The result of this code is somthing like this:
I'm using enumitem to enumerate my variables list.
I have a variable list like:
\begin{enumerate}
\item My First Cool Variable \label{var:myvar1}
\item My Second not so Cool Variable \label{var:myvar2}
\item My Third so so \label{var:myvar3}
\end{enumerate}
When I cross-reference one of these items, I get the list key. For example,
Let us reference \ref{var:myvar2} and then my other variable \ref{var:myvar3}
Gives:
Let us reference 2 and then my other variable 3
What I'd like is to not only be able to obtain the list key, but also the whole item text, so the output could be like:
Let us reference My Second not so Cool Variable and then my other variable My Third so so
The goal is to be able to write the variable name only once, and not changing everywhere if ever the variable name is modified to something more specific.
Any ideas? I've taken a look into enumitem-zref but I couldn't find what I was looking for :/
Using some ideas from Macro to capture until end-of-line as argument, you can capture the contents following an \item:
\documentclass{article}
\usepackage{environ}
% https://tex.stackexchange.com/q/127005/5764
\makeatletter
\NewEnviron{wordenumerate}{%
\begin{enumerate}
\let\olditem\item
\def\item##1\item{\dosomething{##1}}%
\expandafter\#empty\BODY\item
\end{enumerate}%
}
\let\oldlabel\label
\newcommand{\dosomething}[1]{%
\def\elvitaluz#arg{#1}%
\ifx\elvitaluz#arg\elvitaluz#stop
\end{enumerate}
\expandafter\env#ignore % to end the recursion
\else
\def\label##1{\def\#textlabel{##1}\let\label\relax}% Capture \label
\olditem #1
\ifx\label\relax
\def\label##1{\#bsphack\#esphack}%
\edef\#currentlabel{#1}% % what to do with #1
\expandafter\oldlabel\expandafter{\#textlabel}%
\fi
\expandafter\item % to continue the recursion
\fi}
\edef\elvitaluz#stop{\noexpand\end{enumerate}\noexpand\env#ignore\space}
\makeatother
\begin{document}
\begin{wordenumerate}
\item First
\item Second\label{second}
\item \label{third}Last
\end{wordenumerate}
Item~2 is \ref{second}. Item~3 is \ref{third}.
\end{document}
The use of a new environment wordenumerate is suggested, as an entirely different \label-\ref is at play. I would not suggest nesting this environment in anything else (also because of the use of environ).
LaTeX is a wonderful language for writing documents. With the hyperref package and pdflatex, you easily generate documents with metadata, a nice feature to get your documents referenced right on the web.
I often use templates like:
\documentclass[11pt]{article}
\usepackage[pdftex, pdfusetitle,colorlinks=false,pdfborder={0 0 0}]{hyperref}%
\hypersetup{%
pdftitle={My title},%
pdfauthor={My name},%
pdfkeywords={my first keyword, my second keyword, more keywords.},%
}%
\begin{document}
\title{My title}
\author{My name}
\date{}
\maketitle
{\bf Keywords:} my first keyword, my second keyword, more keywords.%
My text is here...
\end{document}
So far, it's well. My question pops out from the example: is there a way to define string variables in the header so that they can be passed as arguments to hyperref and then to the frontmatter or to the text. Something like:
\documentclass[11pt]{article}
%-------definitions-----
\def\Author{My name}
\def\Title{My title}
\def\Keywords{my first keyword, my second keyword, more keywords.}
%--------------------------
\usepackage[pdftex, pdfusetitle,colorlinks=false,pdfborder={0 0 0}]{hyperref}%
\hypersetup{%
pdftitle={\Title},%
pdfauthor={\Author},%
pdfkeywords={\Keywords},%
}%
\begin{document}
\title{\Title}
\author{\Author}
\date{}
\maketitle
{\bf Keywords:} \Keywords %
My text is here...
\end{document}
This fails for the \maketitle part and for the hyperref metadata with ! Use of \Title doesn't match ! Argument of \let has an extra }.but also for including the keywords.
The correct template should look like:
\documentclass[11pt]{article}
%-------definitions-----
\newcommand{\Author}{My name}
\newcommand{\Title}{My title}
\newcommand{\Keywords}{my first keyword, my first keyword, more keywords.}
%--------------------------
\usepackage[pdftex, pdfusetitle,colorlinks=false,pdfborder={0 0 0}]{hyperref}%
\hypersetup{%
pdftitle={\Title},%
pdfauthor={\Author},%
pdfkeywords={\Keywords},%
}%
\begin{document}
\title{\Title}
\author{\Author}
\date{}
\maketitle
{\bf Keywords:} \Keywords %
My text is here...
\end{document}
Compiles fine and the metadata shows fine in the pdf reader.
Try using \newcommand{\Author}{My name} instead of \def.