0

I want to include in \sethead the section title. I use \IfStrEq formula like this:

IfStrEq{\bottitlemarks\sectiontitle}{\firsttitlemarks\sectiontitle}{\firsttitlemarks \sectiontitle}{\firsttitlemarks \sectiontitle \:- \bottitlemarks \sectiontitle}

but it always return false. Even the bottom section title is equal first section title...

This is a short example of my tex file:

\documentclass[a4paper,12pt,twoside,notitlepage]{report}
\usepackage[T1]{fontenc} %system kodowania fontów
\usepackage[polish]{babel}
\usepackage{xifthen, xstring}
\usepackage{expl3}
\ExplSyntaxOn
\cs_set_eq:NN \IfStrEq \str_if_eq:nnTF
\ExplSyntaxOff
\newcommand{\bottomTitle}{\bottitlemarks\sectiontitle}
\newcommand{\topTitle}{\firsttitlemarks\sectiontitle}

\renewcommand{\thesection}{\arabic{section}}
\usepackage{titleps,lipsum}
\newpagestyle{main}{
\sethead
  [\thepage]
  []
  [\IfStrEq{\topTitle}{\bottomTitle}{\firsttitlemarks \sectiontitle}{\firsttitlemarks \sectiontitle \:- \bottitlemarks \sectiontitle}]
  {\IfStrEq{\firsttitlemarks \sectiontitle}{\bottitlemarks \sectiontitle}{\firsttitlemarks \sectiontitle}{\firsttitlemarks \sectiontitle \quad - \quad \bottitlemarks \sectiontitle}}
  {}% centre
  {\thepage}% right
  \setheadrule{.4pt}% Regular header rule
}
\pagestyle{main}
\begin{document}
    \section{blah}
    a
\end{document}

In headder is doubled section title but i create just one section so first section == botom section

  • 1
    Welcome to TeX.SX! Since you're not using standard LaTeX commands, but those offered by additional packages, it's necessary to show a short example of a document with the issue. – egreg Mar 31 '18 at 11:14
1

There are two problems: First your \IfStrEq is defined as \str_if_eq:nnTF, so it will not expand the strings before comparing them. So even if e.g. \topTitle and \bottomTitle would expand to the same value, they would be different in the eyes of \IfStrEq because the unexpanded text is different. This can be fixed by using \str_if_eq_x:nnTF instead, so replace

\cs_set_eq:NN \IfStrEq \str_if_eq:nnTF

with

\cs_set_eq:NN \IfStrEq \str_if_eq_x:nnTF

Second, the argument is only expanded but not executed by TeXs stomach, so commands like \bottitlemarks do not work there. So you have to call \bottilemarks / \firsttitlemarks outside of \IfStrEq. You can't have both active during the \IfStrEq call, but you can save one of the \sectiontitles in a macro:

\documentclass[a4paper,12pt,twoside,notitlepage]{report}
\usepackage[T1]{fontenc} %system kodowania fontów
\usepackage[polish]{babel}
\usepackage{xifthen, xstring}
\usepackage{expl3}
\ExplSyntaxOn
\cs_set_eq:NN \IfStrEq \str_if_eq_x:nnTF
\ExplSyntaxOff
\renewcommand{\thesection}{\arabic{section}}
\usepackage[extramarks]{titleps}
\usepackage{lipsum}
\makeatletter
\newpagestyle{main}{
  \sethead
  [\thepage]
  []
  [%
    \bottitlemarks
    \let\botsectiontitle\sectiontitle
    \toptitlemarks
    \IfStrEq{\sectiontitle}{\botsectiontitle}{%
      \sectiontitle
    }{%
      \sectiontitle \quad --\quad \botsectiontitle
    }%
  ]
  {%
    \bottitlemarks
    \let\botsectiontitle\sectiontitle
    \toptitlemarks
    \IfStrEq{\sectiontitle}{\botsectiontitle}{%
      \sectiontitle
    }{%
      \sectiontitle \quad --\quad \botsectiontitle
    }%
  }
  {}% centre
  {\thepage}% right
  \setheadrule{.4pt}% Regular header rule
}
\pagestyle{main}
\begin{document}
  \section{blah}
  \lipsum
  \section{blah2}
  \section{blah3}
\end{document}

This also uses the \topmark instead of the \firstmark. Output:

enter image description here

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.