Setting up author or address string variables in LaTeX - latex

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.

Related

affiliations and corresponding author comment as footnotes on latex article

I am trying to use the LaTeX article document class to create a simple paper with the authors listed on the title page with their (potentially multiple repeating) affiliations as numeric footnotes and other author comments as symbolic footnotes. For example, I want something like
However, I haven't been able to make this happen despite trying multiple different solutions. Is there a simple way to do this?
I have tried using the bigfoot package to create multiple different types of footnotes combined with footmisc with the multiple option to get multiple footnote markers with commas between them, but I end up with superposed markers and no footnotes. My minimal latex document is:
\documentclass{article}
\title{My title}
\usepackage[multiple]{footmisc}
\usepackage{bigfoot}
\DeclareNewFootnote{AAffil}[arabic]
\DeclareNewFootnote{ANote}[fnsymbol]
\author{
David Kaplan\footnoteAAffil{A University}\footnoteAAffil{Another University}\footnoteANote{Corresponding author}\footnoteANote{Equal contributors}
\and
Prince Charming\FootnotemarkAAffil{2}\FootnotemarkANote{2}
}
\date{\today}
\begin{document}
\maketitle
\end{document}
And the output I get is:
One possibility is to switch to the amsart class and then using the amsaddr package:
\documentclass{amsart}
\title{My title}
\author{David Kaplan $^{1,2,\ast,\dagger}$}
\address{$^1$A University}
\address{$^2$Another University}
\address{$^{\ast}$Corresponding author}
\address{$^{\dagger}$Equal contributors}
\author{Prince Charming $^{1,\dagger}$}
\usepackage[foot]{amsaddr}
\begin{document}
\maketitle
\end{document}
With help from others, I posted a solution to this question here. For completeness, I am copying the solution below:
\documentclass{article} % <---- No titlepage
\title{My title}
%\usepackage[dont-mess-around]{fnpct} % <---- I decided not to use fnpct, but rather put in the commas by hand
\usepackage{bigfoot}
\DeclareNewFootnote{AAffil}[arabic]
\DeclareNewFootnote{ANote}[fnsymbol]
\usepackage{etoolbox}
\makeatletter
\patchcmd\maketitle{\def\#makefnmark{\rlap{\#textsuperscript{\normalfont\#thefnmark}}}}{}{}{}
\makeatother
% Hook into the \thanks command for the article class to print the footnotes
\makeatletter
\def\thanksAAffil#1{% <--- These %'s are necessary for spacing
\footnotemarkAAffil\protected#xdef\#thanks{\#thanks%
\protect\footnotetextAAffil[\the \c#footnoteAAffil]{#1}}%
}
\def\thanksANote#1{%
\footnotemarkANote%
\protected#xdef\#thanks{\#thanks%
\protect\footnotetextANote[\the \c#footnoteANote]{#1}}%
}
\makeatother
\author{% <---- Not sure if these %'s are necessary, but can't hurt
David Kaplan%
\thanksAAffil{A University}$^{,}$\thanksAAffil{Another University}$^{,}$%
\thanksANote{Corresponding author}$^{,}$\thanksANote{Equal contributors}%
, %
Prince Charming%
\footnotemarkAAffil[2]$^{,}$\thanksAAffil{Still another university}$^{,}$\footnotemarkANote[2]$^{,}$%
\thanksANote{Another note}%
, %
Mohamed Ali%
\thanksAAffil{I am the greatest U.}%
}
\date{\today}
\begin{document}
\maketitle
\begin{abstract}
This is the abstract.
\end{abstract}
\section{Introduction}
More Text
\end{document}

\maketitle to use several times with combine in LaTeX

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.

Undefined references using pagesel in Latex

Let's say I have some labels in a part of the document that I exclude using pagesel. However, I want to reference them in the part that I am including. How is that possible?
Below is a minimum example which should print "This is reference 1", but instead prints "This is reference ??".
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[files,2-]{pagesel}
\title{Pagesel problem}
\begin{document}
\maketitle
\section{Introduction}
This is label \label{ref:label1}.
\cleardoublepage
This is reference \ref{ref:label1}
\end{document}
You can retain the labels from pages not shown by first compiling your whole document without the pagesel package and then, in a second step, use the pagesel package with the default nofile option:
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[
%files,
2-]{pagesel}
\title{Pagesel problem}
\begin{document}
\maketitle
\section{Introduction}
This is label \label{ref:label1}.
\cleardoublepage
This is reference \ref{ref:label1}
\end{document}
Other possible approach: compile the complete document and then use a tool like pdftk to extract the pages you like.

Missing \begin{document}. \chapter{E Latex new blank page

I started to use Latex to write my notes and I've been having some problems when I start a new chapter or blank page
\chapter{ECS, Lambda, Batch, Lightsail}
\section{ECS}
\begin{enumerate}
\item first time
\end{enumerate}
and this is my main
\documentclass[a4paper,12pt]{book}
\usepackage[utf8]{inputenc}
\usepackage{graphicx}
\usepackage[margin=1.0in]{geometry}
\begin{document}
\author{José Santiago Molano Perdomo}
\title{Aws Cloud Practicioneer}
\date{}
\let\cleardoublepage\clearpage
\frontmatter
\maketitle
\tableofcontents
\mainmatter
\include{./TeX_files/chapter01}
\include{./TeX_files/chapter02}
\include{./TeX_files/chapter03}
\include{./Tex_files/chapter04}
\include{./Tex_files/chapter05}
\include{./Tex_files/chapter06}
\include{./Tex_files/chapter07}
\include{./Tex_files/chapter08}
\backmatter
% bibliography, glossary and index would go here.
\end{document}
I get this error when I try compile chaper 08
Undefined control sequence. \chapter
Missing \begin{document}. \chapter{E
Undefined control sequence. \section
Emergency stop.
Overfull \hbox (20.0pt too wide) in paragraph
The character é in the author name is invalid to UTF-8. Please change to \'{e}

How can I get page numbers to link to the table of contents in latex?

I've seen a pdf LaTeX document where the page numbers at the bottom of the page are hyperref links, and clicking them causes you to jump to the contents table. I don't have the tex file and couldn't work out how it's done from the hyperref package. Can anyone help?
You could set an anchor at the toc and redefine \thepage to link to it. Here's an example:
\documentclass{report}
\usepackage[colorlinks]{hyperref}
\renewcommand*{\contentsname}{\hyperlink{contents}{Contents}}
\renewcommand*{\thepage}{\hyperref[contents]{\arabic{page}}}
\begin{document}
\tableofcontents
\chapter{One}
Text
\end{document}
If you use babel and wish to redefine \contentsname, use the \addto command of babel or redefine \contentsname after \begin{document}.
Have you tried defining the page numbering using this?
\pagestyle{myheadings}
\markright{ ... }
where \markright specifies the page number with a link to the content page.
Here is how I did it
% !TEX encoding = UTF-8 Unicode
% !TEX TS-program = xelatex
\documentclass[UTF8, english]{article}
\usepackage{lipsum} %% produce dummy texts
\usepackage{hyperref}
\usepackage[pagestyles]{titlesec}
\newpagestyle{article}{
\setfoot
%% even pages
[]
[\footnotesize \hyperlink{toc}{\thepage}]
[]
%% odd pages
{}
{\footnotesize \hyperlink{toc}{\thepage}}
{}
}
\begin{document}
\title{example}
\date{}
\author{author}
\maketitle
\pagenumbering{roman}
\setcounter{tocdepth}{2}
\addtocontents{toc}{\protect\hypertarget{toc}{}}
\tableofcontents
\newpage
\pagenumbering{arabic}
\pagestyle{article}
\section{A}
\lipsum[1]
\subsection{a}
\lipsum[2]
\subsection{b}
\lipsum[3]
\subsection{c}
\lipsum[4]
\section{B}
\lipsum[5]
\subsection{d}
\lipsum[6]
\subsection{e}
\lipsum[7]
\section{C}
\lipsum[8]
\subsection{f}
\lipsum[9]
\subsection{g}
\lipsum[10]
\subsection{h}
\lipsum[11]
\end{document}
you can of course customize the link text back to table of contents however you like in the preamble, please read documentation of titlesec for more details.

Resources