Beamer:使用自定义 TOC 指向超目标

Beamer:使用自定义 TOC 指向超目标

我正在尝试制作一个 toc(todo 的命名列表),列出句子,用自定义命令突出显示\todo,在通过 allowframebreaks 创建的一系列框架之前。希望 MWE 能更好地说明这一点:

\makeatletter%%! TEX root = asd-beamer.tex
\let\@starttocorig\@starttoc
\makeatother%%

\documentclass[t,10pt,xcolor={usenames},fleqn]{beamer}

\usepackage{lipsum}
%% colors
\definecolor{todo}{rgb}{0.75, 0.0, 0.2}

%define \mycontentsline
\makeatletter
\protected\def\Hy@toclinkstart{\hyper@linkstart{link}{\Hy@tocdestname}}
\protected\def\Hy@toclinkend{\hyper@linkend}
\def\mycontentsline#1#2#3#4{%
    
  \begingroup
    \Hy@safe@activestrue
  \edef\x{\endgroup
    \def\noexpand\Hy@tocdestname{#4}%
  }\x
  \ifx\Hy@tocdestname\ltx@empty
    \csname l@#1\endcsname{#2}{#3}%
  \else
    \ifcase\Hy@linktoc % none
      \csname l@#1\endcsname{#2}{#3}%
    \or % section
      \csname l@#1\endcsname{%
          \Hy@toclinkstart{#2}\Hy@toclinkend
      }{#3}%
    \or % page
      \def\Hy@temp{#3}%
      \ifx\Hy@temp\ltx@empty
        \csname l@#1\endcsname{#2}{#3}%
      \else
        \csname l@#1\endcsname{{#2}}{%
            \Hy@toclinkstart{#3}\Hy@toclinkend
        }%
      \fi
    \else % all
      \def\Hy@temp{#3}%
      \ifx\Hy@temp\ltx@empty
        \csname l@#1\endcsname{%
            \Hy@toclinkstart{#2}\Hy@toclinkend
        }{}%
      \else
        \csname l@#1\endcsname{%
            \Hy@toclinkstart{#2}\Hy@toclinkend
        }{%
            \Hy@toclinkstart{#3}\Hy@toclinkend
        }%
      \fi
    \fi
  \fi
  }

\makeatother
%%%
\makeatletter%%see https://tex.stackexchange.com/questions/411987/how-to-fix-hypertargets-directing-links-to-the-line-after-the-target-it-looks-l
%\newcommand{\linkdest}[2][][]{\phantomsection\Hy@raisedlink{\hypertarget{#1}{#2}}\label{sec:#1}}
\newcommand{\linkdest}[2][\@empty]{%
    \hypertarget{\@empty}{#1}
\Hy@raisedlink{%1
\hypertarget{#2}{}
}%1
%\phantomsection\label{#2}
}
\makeatother

\newcounter{todokey}%conta i todo totali per auto ref
\newcounter{todosectionlist}% conta i todo prima di keywordlist

\newcommand\todo[2][todo-\thetodokey]{%todo
    \addtocounter{todokey}{1}
    \noindent{%
    \phantomsection% comment out if hyperref is not used
    \linkdest[\protect\color{todo}{#2}]{#1}%
    }%
    \addtocontents{todo-\thetodosectionlist}{\protect\mycontentsline{subsection}{\parbox{0.4\textwidth}{#2}}{}{#1}}
%\addcontentsline{todo-\protect\thetodosectionlist}{subsubsection}{\textbullet\protect\hyperlink{#1}{#2}\protect\hspace{1mm}}%
}

\makeatletter
\newcommand{\listoftodosbasic}{%listoftodos
    \@starttocorig{todo-\thetodosectionlist}
}
\makeatother

\newcommand\listtodosname{TODO}%listoftodo
\newcommand\listoftodos{%
    \addtocounter{todosectionlist}{1}
    \listtodosname\phantomsection: \listoftodosbasic}

% Let's get started
\begin{document}
\begin{frame}[allowframebreaks,fragile]{TOC}
\tableofcontents
\end{frame}

\part{A part}%\linkdest{intro}%
\section{Things to do}

\begin{frame}[allowframebreaks,fragile]{List of todos}\linkdest{rl20todo}
\listoftodos
\end{frame}

\begin{frame}[allowframebreaks,fragile]{Lista di todos}
\begin{itemize}
    \item\lipsum[1-2]%
    \item monday: \todo{monday-todo}%
        \lipsum[1-4]%
    \item tuesday: \todo{tuesday-todo}%
        \lipsum[1-3]%
    \item wednesday: \todo{wednesday-todo}%
        \lipsum[1-3]%
    \item thursday: \todo{thursday-todo}%
        \lipsum[1-3]%
    \item friday: \todo{friday-todo}%
        \lipsum[1-3]%
    \item saturday: \todo{saturday-todo}%
        \lipsum[1-3]%
    \item sunday: \todo{sunday-todo}%
        \lipsum[1-3]%

\end{itemize}
    
\end{frame}

\end{document}

还需要定义\mycontentsline以摆脱一些奇怪的问题(我想删除\mycontentsline要使用的宏\mycontentsline,因为似乎与这个问题无关,但链接不起作用)。

我的问题是:

  1. todo 的 TOC 链接指向下面一行:参见如何修复超目标将链接指向目标后的行?这看起来像是一个错误。我发现的解决方案是在里面使用两次超目标,\linkdest因为如果我只使用一个超目标,目标就会在页面中的位置发生位移。
  2. 可选:我想看看 todo 的目录在两列上是否看起来更好,但对我来说似乎很难。

希望看起来不会太混乱。

此致。

相关内容