6

In a memoir class document, I am using the following mdtheorem definition to provide a heading inside an mdframe, which has the effect of providing an increasing count(er) to each new reference to `{discuss}

    \mdtheorem{discuss}{Discuss Topic}[chapter]

Within the body of the document, I've inserted begin{discuss}[\rightmark] (following this page, http://glurl.co/dFD), which has taken me some of the way.

It outputs: Discuss Topic 1: 1 TITLE. I.e., it repeats the discussion (topic/section) number and places the title in CAPS. I would like to only include the counter once AND have the topic title in normal case.

Further to discuss with Gonzalo, it is clear that the following macro, which produces two different types of section (\section and \osection) headings, is effecting the output:

    \usepackage{titlesec}
\usepackage{tikz}\usetikzlibrary{shapes.misc}
\makeatletter
\newcommand\titlebar@{%sections
\tikz[baseline,trim left=3.1cm,trim right=3.0cm] {
    \fill [black!15] (2.5cm,-1ex) rectangle (\textwidth+3.1cm,2.5ex);
    \node [
        fill=black!100!white,
        anchor= base east,
        rounded rectangle,
        minimum height=3.75ex] at (3cm,0.01) {
        \color{white}\textbf{T\thesection}
            };
}}
\newcommand\titlebar@@{%osections
\tikz[baseline,trim left=3.1cm,trim right=3.15cm] {
    \fill [black!15] (2.5cm,-1ex) rectangle (\textwidth+3.1cm,2.5ex);
    \node [
        fill=black!100!white,
        anchor= base east,
        rounded rectangle,
        minimum height=3.75ex] at (3cm,0.15) {
    };
}}
\newcommand\titlebar{\@ifstar\titlebar@@\titlebar@}
\titleformat{\section}{\large\bfseries}{\titlebar}{0.1cm}{}
\renewcommand*{\thesection}{\arabic{section}}
\newcommand{\osection}[1]{\section*{\titlebar*#1}}
\makeatother
  • Will you need to include the name of the current section on every discussion environment or just in some of them? – Gonzalo Medina Apr 8 '14 at 14:54
  • yes, each time I use the discussion environment, I want to insert the current section title. – johnbrc Apr 8 '14 at 15:22
5

You could use memoir's \currenttitle:

\documentclass{memoir}
\usepackage{mdframed}

\mdtheorem[style=mpdframe]{discuss}{Discuss Topic}[chapter]

\begin{document}

\chapter{Test chapter}
\section{Test section}
\label{sec:test}
\begin{discuss}[\currenttitle]
test text
\end{discuss}

\end{document}

enter image description here

The problem with the above code is that \currenttitle stores the last sectional unit used, which might not be a section; in this case, some additional work will do; a patch to \M@sect was used to store the name of the current section in \currentsectionname:

\documentclass{memoir}
\usepackage{mdframed}

\mdtheorem[style=mpdframe]{discuss}{Discuss Topic}[chapter]
\makeatletter
\let\currentsectiontitle\relax
\patchcmd{\M@sect}
  {\ifheadnameref}
  {\ifnum#2=1\relax
  \gdef\currentsectiontitle{#9}
  \fi
  \ifheadnameref}
  {}
  {}
\makeatother

\begin{document}

\chapter{Test chapter}
\section{Test section}
\label{sec:test}
\begin{discuss}[\currentsectiontitle]
test text
\end{discuss}

\end{document}

The definition for the mpdframe style was missing in the question.

As mentioned in a comment to the question, since this is going to be used for every discuss environment, I think it's better to use \newmdtheoremenv with a custom theorem style to automatically provide the current section title; something along these lines:

\documentclass{memoir}
\usepackage{amsthm}
\usepackage{mdframed}

\newtheoremstyle{mystyle}
  {\topsep}
  {\topsep}
  {}
  {}
  {\bfseries}
  {\newline}
  {.5em}
  {\thmname{#1}~\thmnumber{#2}: \currentsectiontitle}
\theoremstyle{mystyle}
\newmdtheoremenv{discuss}{Discuss Topic}[chapter]

\makeatletter
\let\currentsectiontitle\relax
\patchcmd{\M@sect}
  {\ifheadnameref}
  {\ifnum#2=1\relax
  \gdef\currentsectiontitle{#9}
  \fi
  \ifheadnameref}
  {}
  {}
\makeatother

\begin{document}

\chapter{Test chapter}
\section{Test section one}
\subsection{Test subsection}
\label{sec:test}
\begin{discuss}
test text
\end{discuss}
\section{Test section two}
\subsection{Test subsection}
\label{sec:test}
\begin{discuss}
test text
\end{discuss}

\end{document}

enter image description here

Update after the edit to the question

The above suggestions won't work since the titlesec package is used (which might be not a good idea with the memoir class; see About memoir and titlesec incompatibility). In this case you can use:

\documentclass{memoir}
\usepackage{mdframed}
\usepackage[explicit]{titlesec}
\usepackage{tikz}
\usetikzlibrary{shapes.misc}

\mdtheorem[style=mpdframe]{discuss}{Discuss Topic}[chapter]

\makeatletter

\let\currentsectiontitle\relax

\newcommand\titlebar@{%sections
\tikz[baseline,trim left=3.1cm,trim right=3.0cm] {
    \fill [black!15] (2.5cm,-1ex) rectangle (\textwidth+3.1cm,2.5ex);
    \node [
        fill=black!100!white,
        anchor= base east,
        rounded rectangle,
        minimum height=3.75ex] at (3cm,0.01) {
        \color{white}\textbf{T\thesection}
            };
}}
\newcommand\titlebar@@{%osections
\tikz[baseline,trim left=3.1cm,trim right=3.15cm] {
    \fill [black!15] (2.5cm,-1ex) rectangle (\textwidth+3.1cm,2.5ex);
    \node [
        fill=black!100!white,
        anchor= base east,
        rounded rectangle,
        minimum height=3.75ex] at (3cm,0.15) {
    };
}}
\newcommand\titlebar{\@ifstar\titlebar@@\titlebar@}
\titleformat{\section}
  {\large\bfseries}
  {\titlebar}
  {0.1cm}
  {\gdef\currentsectiontitle{#1}#1}
\renewcommand*{\thesection}{\arabic{section}}
\newcommand{\osection}[1]{\section*{\titlebar*#1}}
\makeatother

\begin{document}

\chapter{Test chapter}
\section{Test section}
\label{sec:test}
\begin{discuss}[\currentsectiontitle]
test text
\end{discuss}

\end{document}

enter image description here

Or with the automatic inclussion via a new theorem style:

\documentclass{memoir}
\usepackage{amsthm}
\usepackage{mdframed}
\usepackage[explicit]{titlesec}
\usepackage{tikz}
\usetikzlibrary{shapes.misc}

\newtheoremstyle{mystyle}
  {\topsep}
  {\topsep}
  {}
  {}
  {\bfseries}
  {\newline}
  {.5em}
  {\thmname{#1}~\thmnumber{#2}: \currentsectiontitle}
\theoremstyle{mystyle}
\newmdtheoremenv{discuss}{Discuss Topic}[chapter]

\makeatletter

\let\currentsectiontitle\relax

\newcommand\titlebar@{%sections
\tikz[baseline,trim left=3.1cm,trim right=3.0cm] {
    \fill [black!15] (2.5cm,-1ex) rectangle (\textwidth+3.1cm,2.5ex);
    \node [
        fill=black!100!white,
        anchor= base east,
        rounded rectangle,
        minimum height=3.75ex] at (3cm,0.01) {
        \color{white}\textbf{T\thesection}
            };
}}
\newcommand\titlebar@@{%osections
\tikz[baseline,trim left=3.1cm,trim right=3.15cm] {
    \fill [black!15] (2.5cm,-1ex) rectangle (\textwidth+3.1cm,2.5ex);
    \node [
        fill=black!100!white,
        anchor= base east,
        rounded rectangle,
        minimum height=3.75ex] at (3cm,0.15) {
    };
}}
\newcommand\titlebar{\@ifstar\titlebar@@\titlebar@}
\titleformat{\section}
  {\large\bfseries}
  {\titlebar}
  {0.1cm}
  {\gdef\currentsectiontitle{#1}#1}
\renewcommand*{\thesection}{\arabic{section}}
\newcommand{\osection}[1]{\section*{\titlebar*#1}}
\makeatother

\begin{document}

\chapter{Test chapter}
\section{Test section one}
\subsection{Test subsection}
\begin{discuss}
test text
\end{discuss}
\section{Test section two}
\subsection{Test subsection}
\begin{discuss}
test text
\end{discuss}

\end{document}

enter image description here

|improve this answer|||||
  • This goes a long way. It's actually the \thesection title I'm wanting to insert. This inserts \thechapter title… – johnbrc Apr 8 '14 at 14:47
  • @johnbrc did you see the title of your question? You asked to include the chapter name. Please correct the title. – Gonzalo Medina Apr 8 '14 at 14:48
  • @johnbrc please see my updated answer. Is it something like that what you need? – Gonzalo Medina Apr 8 '14 at 14:51
  • Thanks, @Gonzalo, I'm not sure this is what I'm looking for. It works in the example, because the label is defined. My section label is being defined automatically each time, because I'm writing in MultiMarkdown and exporting into LaTex, before compiling to pdf. I don't want to have to manually insert a label to each section. I liked your previous solution, only for the section, rather than chapter. Can it be adapted? – johnbrc Apr 8 '14 at 15:10
  • @johnbrc please see my updated answer. – Gonzalo Medina Apr 8 '14 at 15:21

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.