fmarotta / kaobook

A LaTeX class for books, reports or theses based on https://github.com/kenohori/thesis and https://github.com/Tufte-LaTeX/tufte-latex.
https://github.com/fmarotta/kaobook
LaTeX Project Public License v1.3c
861 stars 185 forks source link

Formatting problem when there are sidenotes in section titles #156

Closed cgosorio closed 3 years ago

cgosorio commented 3 years ago

Prerequisites

Description

The sidenotes in section titles appear also in the minitoc, this has two consequences, first the sidenote is duplicated (it appears both realated to the title and to the minitoc), second the minitoc sidenote may overlap with another sidenote in main text, as it is shown in this image:

image

The section titles causing the problem is:

\section[Boxes \& Environments]{Boxes \& Custom Environments
\sidenote[][*1.8]{Notice that in the table of contents and in the 
    header, the name of this section is \enquote{Boxes \& Environments}; 
    we achieved this with the optional argument of the \texttt{section} 
    command.}}

Where the optional argument with the titles without the sidenot is given. So the problem may be due to the fact that in the minitoc the optional argument is not used, but instead the mandatory argument of the section (with the sidenote) is used.

cgosorio commented 3 years ago

This problem seems related to the changes introduced in issue #101. One way to avoid the problem is to use the new optional argument:

\section[Boxes \& Environments]{Boxes \& Custom Environments
\sidenote[][*1.8]{Notice that in the table of contents and in the 
    header, the name of this section is \enquote{Boxes \& Environments}; 
    we achieved this with the optional argument of the \texttt{section} 
    command.}}[Boxes \& Environments]

Anyway, this is a bit cumbersome, when the new additional optional argument (for the minitoc) is not provided, I think the behaviour should be to use the first optional argument (for the toc) if provided. So, for example, for the case of the new section command, instead of the suggested:

\RenewDocumentCommand\section{s o m o}{%
    \IfBooleanTF{#1}{%
        \oldsection*{#3}
        \IfNoValueF{#2}{% if TOC arg is given create a TOC entry
            \addxcontentsline{toc}{section}[\thesection]{#2}%
        }%
    }{% no star given
        \IfNoValueTF{#2}{%
            \oldsection{#3}%
        }{% no TOC arg
            \oldsection[#2]{#3}%
        }%
        \IfNoValueTF{#4}{% optional label given, if not we do nothing
            \mtocsection{#3}%
        }{%
            \mtocsection{#4}%
        }%
    }%
}

This could be used:

\RenewDocumentCommand\section{s o m o}{%
    \IfBooleanTF{#1}{%
        \oldsection*{#3}
        \IfNoValueF{#2}{% if TOC arg is given create a TOC entry
            \addxcontentsline{toc}{section}[\thesection]{#2}%
        }%
    }{% no star given
        \IfNoValueTF{#2}{%
            \oldsection{#3}%
        }{% no TOC arg
            \oldsection[#2]{#3}%
        }%
        \IfNoValueTF{#4}{% optional label given, if not we do nothing
            % \mtocsection{#3}%
            \IfNoValueTF{#2}{% 
                \mtocsection{#3}% when no optional toc title, use main title
            }{% no TOC arg
                \mtocsection{#2}% when toc optional title is given, use it
            }%
        }{%
            \mtocsection{#4}%
        }%
    }%
}

Similarly, for the subsection command.

I think the issue could be close, but I prefer the author of the package closes it after accepting the changes and incorporating them to kao.sty.

fmarotta commented 3 years ago

I incorporated the suggested changes. Thanks! For future reference, I don't dislike pull requests :}

cgosorio commented 3 years ago

Yes, sorry, next time I will prepare a PR. I have done this and other small corrections to the sources on the fly while preparing a document, and everything was a bit messy. This was one of the few substantial changes I though could be urgent to incorporate. Now I need to meet the deadline to finish and send the document. But as soon as I have more time, I will prepare a proper PR with all those small changes.

Very nice book format, by the way, keep up your good work.