# section title with IfStrEq formula in \sethead

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

• 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

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}{
[\thepage]
[]
[%
\bottitlemarks
\let\botsectiontitle\sectiontitle
\toptitlemarks
\IfStrEq{\sectiontitle}{\botsectiontitle}{%
\sectiontitle
}{%
}%
]
{%
\bottitlemarks
\let\botsectiontitle\sectiontitle
\toptitlemarks
\IfStrEq{\sectiontitle}{\botsectiontitle}{%
\sectiontitle
}{%
}%
}
{}% centre
{\thepage}% right

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