Featured Book

LaTeX Beginners Guide

Who is online

In total there are 13 users online :: 0 registered, 0 hidden and 13 guests (based on users active over the past 5 minutes)
Most users ever online was 1327 on Tue Nov 05, 2013 7:11 pm

Users browsing this forum: No registered users and 13 guests

Partner Sites

TeXwelt - Fragen und Antworten goLaTeX
TeXblog
TeXnicCenter
TeXample

What variable current section name?

Add tags LaTeX specific issues not fitting into one of the other forums of this category.

What variable current section name?

Postby dmader on Tue Nov 3rd, 2009

Hi,

I want to display the name of the section (also chapter, subsection) I'm currently in. (Section number doesn't do)

For instance:

\begin{document}
\section{asdf}
This is text in the section: ??? % and here I need something to display "asdf" without explicitly typing it)
\end{document}

Thanks a lot,
Daniel
dmader
 
Posts: 3
Joined: Tue Nov 3rd, 2009

Re: What variable current section name?

Postby stantestco on Tue Nov 3rd, 2009

I've spent countless hours trying to figure this out-- native Latex support is very lacking in this regard.

Here is what I did. Make a variable that stores the current section title.

ie


\definecommand{sectiontitle}{#1}
\definecommand{setsectiontitle}[1]{\renewcommand{sectiontitle}{#1}}

and use \sectiontitle inside the section...

Trust me on this-- I know exactly what you're trying to do, after investing literally 20 or so hours into this,


\section{Quadratic Equations}
\setsectiontitle{Quadratic Equations}
{

...
}
stantestco
 
Posts: 8
Joined: Tue Jul 21st, 2009

Re: What variable current section name?

Postby frabjous on Tue Nov 3rd, 2009

stantestco wrote:\section{Quadratic Equations}
\setsectiontitle{Quadratic Equations}


Wouldn't have been easier just to define a command like this:

\newcommand{\sectiontitle}{}
\newcommand{\newsection}[1]{\section{#1}\renewcommand{\sectiontitle}{#1}}

So that in the document you only need to do:

\newsection{Quadratic Equations}

which will both start the new section and redefine \sectiontitle?

But I think there should be a way to get around even doing that, but I think we'd need to know what document class and other packages were being used.
User avatar
frabjous
 
Posts: 2065
Joined: Fri Mar 6th, 2009
Location: Amherst, MA

Re: What variable current section name?

Postby dmader on Tue Nov 3rd, 2009

Thank you for the fast replies.

@frabjous: Documentclass is report and I can integrate all packages needed if it facilitates the solution.
dmader
 
Posts: 3
Joined: Tue Nov 3rd, 2009

Re: What variable current section name?

Postby prosper on Mon Apr 5th, 2010

frabjous,

this solved my problem. I could even easily extend the functionality to subsectiontitles ...

I don't quite grasp the exact syntax of the commands you gave, but I encountered those while searching on "\sectionmark" which was the closest I got to a "solution" after literally hours of searching. Everything I encountered was about headers and so on, but I didn't want some "fancy headers", just a title on my slides in the "beamer class" that would change automatically if I ever wanted to change the name of the section. It now also provides easier processing, since I can use the same lines over and over again.

Thanks a lot.

Prosper
prosper
 
Posts: 4
Joined: Wed Mar 24th, 2010

Re: What variable current section name?

Postby prosper on Wed Apr 7th, 2010

In fact, some rather odd problem remains:
When I use this snippet of code
Code: Select all  •  Open in writeLaTeX
\AtBeginSection[]
{
   \begin{frame}
       \frametitle{\sectiontitle}  
       \tableofcontents[currentsection,hideothersubsections,
]
   \end{frame}
}

LateX will not print the title of the new session that is about to begin, but rather the title of the previous session. "Current" session being highlighted is the upcoming session, as was intended.

Placing everything inside the brackets manually AFTER each session-start gives the intended result: correct sessiontitle and correct highlighted "upcoming" session.
Though this suits my needs, it is rather cumbersome...

BTW: document class is Beamer
prosper
 
Posts: 4
Joined: Wed Mar 24th, 2010

Re: What variable current section name?

Postby frabjous on Wed Apr 7th, 2010

Are you using this code snippet now?

Code: Select all  •  Open in writeLaTeX
\newcommand{\sectiontitle}{}
\newcommand{\newsection}[1]{\section{#1}\renewcommand{\sectiontitle}{#1}
}


?

If so, did you try changing it to:

Code: Select all  •  Open in writeLaTeX
\newcommand{\sectiontitle}{}
\newcommand{\newsection}[1]{\renewcommand{\sectiontitle}{#1}\section{#1}
}
User avatar
frabjous
 
Posts: 2065
Joined: Fri Mar 6th, 2009
Location: Amherst, MA

Re: What variable current section name?

Postby nlct on Thu Apr 8th, 2010

dmader wrote:I want to display the name of the section (also chapter, subsection) I'm currently in. (Section number doesn't do)


The nameref package will do this (but you need to label the section):

Code: Select all  •  Open in writeLaTeX
\documentclass{report}

\usepackage{nameref}

\begin{document}
\chapter{Sample}

\section{asdf}\label{sec:ex}
This is text in the section: \nameref{sec:ex}.
\end{document
}


With beamer, the current section title is given by \insertsectionhead:

Code: Select all  •  Open in writeLaTeX
\documentclass{beamer}

\AtBeginSection[]
{
   \begin{frame}
       \frametitle{\insertsectionhead}
       \tableofcontents[currentsection,hideothersubsections,
]
   \end{frame}
}

\begin{document}

\section{asdf}

\begin{frame}
 \frametitle{Sample}
\end{frame}

\end{document
}


Regards
Nicola Talbot
User avatar
nlct
 
Posts: 254
Joined: Thu Nov 6th, 2008


Return to General

Who is online

Users browsing this forum: No registered users and 13 guests