LaTeX forum ⇒ GeneralWhat variable current section name?

LaTeX specific issues not fitting into one of the other forums of this category.
dmader
Posts: 3
Joined: Tue Nov 03, 2009 12:33 pm

What variable current section name?

Postby dmader » Tue Nov 03, 2009 12:44 pm

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

Link:
BBcode:
HTML:
Hide post links
Show post links

stantestco
Posts: 8
Joined: Tue Jul 21, 2009 12:13 pm

Postby stantestco » Tue Nov 03, 2009 2:00 pm

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

...
}

Link:
BBcode:
HTML:
Hide post links
Show post links

User avatar
frabjous
Posts: 2064
Joined: Fri Mar 06, 2009 12:20 am
Location: Amherst, MA

Postby frabjous » Tue Nov 03, 2009 2:47 pm

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.

Link:
BBcode:
HTML:
Hide post links
Show post links

dmader
Posts: 3
Joined: Tue Nov 03, 2009 12:33 pm

Postby dmader » Tue Nov 03, 2009 4:44 pm

Thank you for the fast replies.

@frabjous: Documentclass is report and I can integrate all packages needed if it facilitates the solution.

Link:
BBcode:
HTML:
Hide post links
Show post links

prosper
Posts: 4
Joined: Wed Mar 24, 2010 7:42 pm

Postby prosper » Mon Apr 05, 2010 2:50 am

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

Link:
BBcode:
HTML:
Hide post links
Show post links

prosper
Posts: 4
Joined: Wed Mar 24, 2010 7:42 pm

Postby prosper » Wed Apr 07, 2010 9:04 pm

In fact, some rather odd problem remains:
When I use this snippet of code
  1. \AtBeginSection[]
  2. {
  3. \begin{frame}
  4. \frametitle{\sectiontitle}
  5. \tableofcontents[currentsection,hideothersubsections,]
  6. \end{frame}
  7. }

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

Link:
BBcode:
HTML:
Hide post links
Show post links

User avatar
frabjous
Posts: 2064
Joined: Fri Mar 06, 2009 12:20 am
Location: Amherst, MA

Postby frabjous » Wed Apr 07, 2010 9:33 pm

Are you using this code snippet now?

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


?

If so, did you try changing it to:

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

Link:
BBcode:
HTML:
Hide post links
Show post links

User avatar
nlct
Posts: 263
Joined: Thu Nov 06, 2008 11:15 am
Contact:

Postby nlct » Thu Apr 08, 2010 1:36 pm

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):

  1. \documentclass{report}
  2.  
  3. \usepackage{nameref}
  4.  
  5. \begin{document}
  6. \chapter{Sample}
  7.  
  8. \section{asdf}\label{sec:ex}
  9. This is text in the section: \nameref{sec:ex}.
  10. \end{document}


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

  1. \documentclass{beamer}
  2.  
  3. \AtBeginSection[]
  4. {
  5. \begin{frame}
  6. \frametitle{\insertsectionhead}
  7. \tableofcontents[currentsection,hideothersubsections,]
  8. \end{frame}
  9. }
  10.  
  11. \begin{document}
  12.  
  13. \section{asdf}
  14.  
  15. \begin{frame}
  16. \frametitle{Sample}
  17. \end{frame}
  18.  
  19. \end{document}


Regards
Nicola Talbot

Link:
BBcode:
HTML:
Hide post links
Show post links


Return to “General”

Who is online

Users browsing this forum: Google [Bot] and 4 guests