How can I make the section-text in a Table of Contents clickable, but keep the section-number...

What does it mean to describe someone as a butt steak?

Email Account under attack (really) - anything I can do?

In Japanese, what’s the difference between “Tonari ni” (となりに) and “Tsugi” (つぎ)? When would you use one over the other?

Is this a crack on the carbon frame?

The Two and the One

What are the differences between the usage of 'it' and 'they'?

Example of a continuous function that don't have a continuous extension

Mathematical cryptic clues

Theorems that impeded progress

How did the USSR manage to innovate in an environment characterized by government censorship and high bureaucracy?

Why does Kotter return in Welcome Back Kotter?

Why was the small council so happy for Tyrion to become the Master of Coin?

Do VLANs within a subnet need to have their own subnet for router on a stick?

Today is the Center

Arthur Somervell: 1000 Exercises - Meaning of this notation

Is it unprofessional to ask if a job posting on GlassDoor is real?

Why can't I see bouncing of a switch on an oscilloscope?

Accidentally leaked the solution to an assignment, what to do now? (I'm the prof)

Approximately how much travel time was saved by the opening of the Suez Canal in 1869?

Show that if two triangles built on parallel lines, with equal bases have the same perimeter only if they are congruent.

How much RAM could one put in a typical 80386 setup?

Why don't electron-positron collisions release infinite energy?

How do we improve the relationship with a client software team that performs poorly and is becoming less collaborative?

Service Entrance Breakers Rain Shield



How can I make the section-text in a Table of Contents clickable, but keep the section-number *unclickable*?


Hyperlinks from chapter and section headings back to the table of contentsRemove hyperlink from table (figure) number in LOT (LOF)Disable hyperlinks in the titles of the sections but keep it in the section numbering and pagesRepeating a block of text until it fills a pageRemove “chapter #” from the chapter title but keep chapter number in the table of contentsHow can I make a clickable Table of Contents?How to make an article's table of contents clickable so it can redirect to a section?Proper way to section a textHide section number but keep in table of contentsHow to Keep Section Numbering but Not Include in Table of ContentsHow to change the first page (layout + geometry) of each chapter in a report?How do I make my section uncounted but listed in the table of contents?Paragraph title in ConTeXt (similar to LaTeX paragraph{})













2















I recently found this thread on how to make section titles clickable/return to their entry in the Table of Contents -- only problem is, the title text of the section headers are clickable, but the numbers are not. I simply want to make the Table of Contents mirror this style.



Here is a template document:



documentclass[11pt]{article}
usepackage[margin=0.5in,footskip=0.4in]{geometry}
usepackage[T1]{fontenc}
usepackage{hyperref}
hypersetup{
colorlinks=true,
linkcolor=blue,
linktoc=all,
}

% For clickable section headers
% See https://tex.stackexchange.com/a/251964/73149
makeatletter
lethypersectionsection
defsection{@ifstarstarsectionmysection}
defstarsection{hypersection*}
newcommand{mysection}[2][@empty]% #1=optional (toc), #2=title
{ifx#1@empty hypersection[#2]{hyperlink{toc.section.thesection}{#2}}
else hypersection[#1]{hyperlink{toc.section.thesection}{#2}}
fi}
lethypersubsectionsubsection
defsubsection{@ifstarstarsubsectionmysubsection}
defstarsubsection{hypersubsection*}
newcommand{mysubsection}[2][@empty]% #1=optional (toc), #2=title
{ifx#1@empty hypersubsection[#2]{hyperlink{toc.subsection.thesubsection}{#2}}
else hypersubsection[#1]{hyperlink{toc.subsection.thesubsection}{#2}}
fi}
makeatother
lethypercontentsline=contentsline
renewcommand{contentsline}[4]{hypertarget{toc.#4}{}hypercontentsline{#1}{#2}{#3}{#4}}

% Body
begin{document}
title{This is a Title}
date{}
maketitle
tableofcontents
section{A Section}
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
section{Another One}
subsection{Hello}
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
subsection{Goodbye}
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
section{Final Section}
Peace out.
end{document}









share|improve this question

























  • Why not mirror the other way?

    – cfr
    Jan 30 '18 at 0:05











  • Got the impression that would be more difficult. Check out the comment thread in the answer from the thread I linked.

    – Luke Davis
    Jan 30 '18 at 3:02











  • One involves trying to separate numberline from the title, the other involves replacing @sect.

    – John Kormylo
    Jan 30 '18 at 4:45
















2















I recently found this thread on how to make section titles clickable/return to their entry in the Table of Contents -- only problem is, the title text of the section headers are clickable, but the numbers are not. I simply want to make the Table of Contents mirror this style.



Here is a template document:



documentclass[11pt]{article}
usepackage[margin=0.5in,footskip=0.4in]{geometry}
usepackage[T1]{fontenc}
usepackage{hyperref}
hypersetup{
colorlinks=true,
linkcolor=blue,
linktoc=all,
}

% For clickable section headers
% See https://tex.stackexchange.com/a/251964/73149
makeatletter
lethypersectionsection
defsection{@ifstarstarsectionmysection}
defstarsection{hypersection*}
newcommand{mysection}[2][@empty]% #1=optional (toc), #2=title
{ifx#1@empty hypersection[#2]{hyperlink{toc.section.thesection}{#2}}
else hypersection[#1]{hyperlink{toc.section.thesection}{#2}}
fi}
lethypersubsectionsubsection
defsubsection{@ifstarstarsubsectionmysubsection}
defstarsubsection{hypersubsection*}
newcommand{mysubsection}[2][@empty]% #1=optional (toc), #2=title
{ifx#1@empty hypersubsection[#2]{hyperlink{toc.subsection.thesubsection}{#2}}
else hypersubsection[#1]{hyperlink{toc.subsection.thesubsection}{#2}}
fi}
makeatother
lethypercontentsline=contentsline
renewcommand{contentsline}[4]{hypertarget{toc.#4}{}hypercontentsline{#1}{#2}{#3}{#4}}

% Body
begin{document}
title{This is a Title}
date{}
maketitle
tableofcontents
section{A Section}
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
section{Another One}
subsection{Hello}
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
subsection{Goodbye}
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
section{Final Section}
Peace out.
end{document}









share|improve this question

























  • Why not mirror the other way?

    – cfr
    Jan 30 '18 at 0:05











  • Got the impression that would be more difficult. Check out the comment thread in the answer from the thread I linked.

    – Luke Davis
    Jan 30 '18 at 3:02











  • One involves trying to separate numberline from the title, the other involves replacing @sect.

    – John Kormylo
    Jan 30 '18 at 4:45














2












2








2


0






I recently found this thread on how to make section titles clickable/return to their entry in the Table of Contents -- only problem is, the title text of the section headers are clickable, but the numbers are not. I simply want to make the Table of Contents mirror this style.



Here is a template document:



documentclass[11pt]{article}
usepackage[margin=0.5in,footskip=0.4in]{geometry}
usepackage[T1]{fontenc}
usepackage{hyperref}
hypersetup{
colorlinks=true,
linkcolor=blue,
linktoc=all,
}

% For clickable section headers
% See https://tex.stackexchange.com/a/251964/73149
makeatletter
lethypersectionsection
defsection{@ifstarstarsectionmysection}
defstarsection{hypersection*}
newcommand{mysection}[2][@empty]% #1=optional (toc), #2=title
{ifx#1@empty hypersection[#2]{hyperlink{toc.section.thesection}{#2}}
else hypersection[#1]{hyperlink{toc.section.thesection}{#2}}
fi}
lethypersubsectionsubsection
defsubsection{@ifstarstarsubsectionmysubsection}
defstarsubsection{hypersubsection*}
newcommand{mysubsection}[2][@empty]% #1=optional (toc), #2=title
{ifx#1@empty hypersubsection[#2]{hyperlink{toc.subsection.thesubsection}{#2}}
else hypersubsection[#1]{hyperlink{toc.subsection.thesubsection}{#2}}
fi}
makeatother
lethypercontentsline=contentsline
renewcommand{contentsline}[4]{hypertarget{toc.#4}{}hypercontentsline{#1}{#2}{#3}{#4}}

% Body
begin{document}
title{This is a Title}
date{}
maketitle
tableofcontents
section{A Section}
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
section{Another One}
subsection{Hello}
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
subsection{Goodbye}
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
section{Final Section}
Peace out.
end{document}









share|improve this question
















I recently found this thread on how to make section titles clickable/return to their entry in the Table of Contents -- only problem is, the title text of the section headers are clickable, but the numbers are not. I simply want to make the Table of Contents mirror this style.



Here is a template document:



documentclass[11pt]{article}
usepackage[margin=0.5in,footskip=0.4in]{geometry}
usepackage[T1]{fontenc}
usepackage{hyperref}
hypersetup{
colorlinks=true,
linkcolor=blue,
linktoc=all,
}

% For clickable section headers
% See https://tex.stackexchange.com/a/251964/73149
makeatletter
lethypersectionsection
defsection{@ifstarstarsectionmysection}
defstarsection{hypersection*}
newcommand{mysection}[2][@empty]% #1=optional (toc), #2=title
{ifx#1@empty hypersection[#2]{hyperlink{toc.section.thesection}{#2}}
else hypersection[#1]{hyperlink{toc.section.thesection}{#2}}
fi}
lethypersubsectionsubsection
defsubsection{@ifstarstarsubsectionmysubsection}
defstarsubsection{hypersubsection*}
newcommand{mysubsection}[2][@empty]% #1=optional (toc), #2=title
{ifx#1@empty hypersubsection[#2]{hyperlink{toc.subsection.thesubsection}{#2}}
else hypersubsection[#1]{hyperlink{toc.subsection.thesubsection}{#2}}
fi}
makeatother
lethypercontentsline=contentsline
renewcommand{contentsline}[4]{hypertarget{toc.#4}{}hypercontentsline{#1}{#2}{#3}{#4}}

% Body
begin{document}
title{This is a Title}
date{}
maketitle
tableofcontents
section{A Section}
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
section{Another One}
subsection{Hello}
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
subsection{Goodbye}
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
section{Final Section}
Peace out.
end{document}






macros table-of-contents sectioning hyperref hyperlink






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited 8 hours ago







Luke Davis

















asked Jan 29 '18 at 23:10









Luke DavisLuke Davis

1658




1658













  • Why not mirror the other way?

    – cfr
    Jan 30 '18 at 0:05











  • Got the impression that would be more difficult. Check out the comment thread in the answer from the thread I linked.

    – Luke Davis
    Jan 30 '18 at 3:02











  • One involves trying to separate numberline from the title, the other involves replacing @sect.

    – John Kormylo
    Jan 30 '18 at 4:45



















  • Why not mirror the other way?

    – cfr
    Jan 30 '18 at 0:05











  • Got the impression that would be more difficult. Check out the comment thread in the answer from the thread I linked.

    – Luke Davis
    Jan 30 '18 at 3:02











  • One involves trying to separate numberline from the title, the other involves replacing @sect.

    – John Kormylo
    Jan 30 '18 at 4:45

















Why not mirror the other way?

– cfr
Jan 30 '18 at 0:05





Why not mirror the other way?

– cfr
Jan 30 '18 at 0:05













Got the impression that would be more difficult. Check out the comment thread in the answer from the thread I linked.

– Luke Davis
Jan 30 '18 at 3:02





Got the impression that would be more difficult. Check out the comment thread in the answer from the thread I linked.

– Luke Davis
Jan 30 '18 at 3:02













One involves trying to separate numberline from the title, the other involves replacing @sect.

– John Kormylo
Jan 30 '18 at 4:45





One involves trying to separate numberline from the title, the other involves replacing @sect.

– John Kormylo
Jan 30 '18 at 4:45










1 Answer
1






active

oldest

votes


















2














This both adds the section number to the back link, and removes the section number from the toc line. The latter was definitely harder.



documentclass[11pt]{article}
usepackage[margin=0.5in,footskip=0.4in]{geometry}
usepackage[T1]{fontenc}
usepackage{etoolbox}
usepackage{hyperref}
hypersetup{
colorlinks=true,
linkcolor=blue,
linktoc=all,
}

% For clickable section headers
% See https://tex.stackexchange.com/a/251964/73149
makeatletter
def@sect#1#2#3#4#5#6[#7]#8{%
ifnum #2>c@secnumdepth
let@svsec@empty
else
refstepcounter{#1}%
protected@edef@svsec{@seccntformat{#1}relax}%
fi
@tempskipa #5relax
ifdim @tempskipa>z@
begingroup
#6{sbox0{@svsec}% measure width
interlinepenalty @M
hangindent=dimexpr wd0+#3relax
noindenthskip #3relax
hyperlink{toc.#1.csname the#1endcsname}%
{@svsec #8}%
@@par}%
endgroup
csname #1markendcsname{#7}%
addcontentsline{toc}{#1}{%
ifnum #2>c@secnumdepth else
protectnumberline{csname the#1endcsname}%
fi
#7}%
else
def@svsechd{%
#6{hskip #3relax
@svsec #8}%
csname #1markendcsname{#7}%
addcontentsline{toc}{#1}{%
ifnum #2>c@secnumdepth else
protectnumberline{csname the#1endcsname}%
fi
#7}}%
fi
@xsect{#5}}
makeatother

%lethypercontentsline=contentsline
%renewcommand{contentsline}[4]{hypertarget{toc.#4}{}hypercontentsline{#1}{#2}{#3}{#4}}

% begin code to remove section numbers from the TOC
makeatletter
newcommand{@savenumber}{}% reserve global names
newcommand{@savetitle}{}

defcontentsline#1#2#3#4{%
hypertarget{toc.#4}{}% set up backlin
bgroup% separate numberline from title
renewcommand{numberline}[1]{xdef@savenumber{##1}}%
sbox0{#2}%
letnumberline=@gobble
xdef@savetitle{#2}%
egroup
begingroup
Hy@safe@activestrue
edefx{endgroup
defnoexpandHy@tocdestname{#4}%
}x
ifxHy@tocdestnameltx@empty
csname l@#1endcsname{#2}{#3}%
else
ifcaseHy@linktoc % none
csname l@#1endcsname{#2}{#3}%
or % section
csname l@#1endcsname{numberline{@savenumber}%
hyper@linkstart{link}{Hy@tocdestname}{@savetitle}hyper@linkend
}{#3}%
or % page
defHy@temp{#3}%
ifxHy@templtx@empty
csname l@#1endcsname{#2}{#3}%
else
csname l@#1endcsname{{#2}}{%
hyper@linkstart{link}{Hy@tocdestname}{#3}hyper@linkend
}%
fi
else % all
defHy@temp{#3}%
ifxHy@templtx@empty
csname l@#1endcsname{numberline{@savenumber}%
hyper@linkstart{link}{Hy@tocdestname}{@savetitle}hyper@linkend
egroup}{}%
else
csname l@#1endcsname{numberline{@savenumber}%
hyper@linkstart{link}{Hy@tocdestname}{@savetitle}hyper@linkend
}{%
hyper@linkstart{link}{Hy@tocdestname}{#3}hyper@linkend
}%
fi
fi
fi
}
makeatother

% Body
begin{document}
title{This is a Title}
date{}
maketitle
tableofcontents
section{A Section}
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
section{Another One}
subsection{Hello}
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
subsection{Goodbye}
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
section{Final Section}
Peace out.
end{document}





share|improve this answer


























  • Thanks a lot! This is utterly black magic to me. Might want to mention also that the lethypercontentsline seems to make the backlinks point to specific items in the Table of Contents; they point to the head of the document without those lines. At least this is the case when I tried it.

    – Luke Davis
    Jan 31 '18 at 3:49











  • It worked for me. Both redefinitions of contentsline add hypertarget{toc.#4}{} at the start. The source for @sect comes from source2e.pdf (CTAN) and the source for contentsline comes from hyperref.sty.

    – John Kormylo
    Jan 31 '18 at 4:05












Your Answer








StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "85"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f412773%2fhow-can-i-make-the-section-text-in-a-table-of-contents-clickable-but-keep-the-s%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









2














This both adds the section number to the back link, and removes the section number from the toc line. The latter was definitely harder.



documentclass[11pt]{article}
usepackage[margin=0.5in,footskip=0.4in]{geometry}
usepackage[T1]{fontenc}
usepackage{etoolbox}
usepackage{hyperref}
hypersetup{
colorlinks=true,
linkcolor=blue,
linktoc=all,
}

% For clickable section headers
% See https://tex.stackexchange.com/a/251964/73149
makeatletter
def@sect#1#2#3#4#5#6[#7]#8{%
ifnum #2>c@secnumdepth
let@svsec@empty
else
refstepcounter{#1}%
protected@edef@svsec{@seccntformat{#1}relax}%
fi
@tempskipa #5relax
ifdim @tempskipa>z@
begingroup
#6{sbox0{@svsec}% measure width
interlinepenalty @M
hangindent=dimexpr wd0+#3relax
noindenthskip #3relax
hyperlink{toc.#1.csname the#1endcsname}%
{@svsec #8}%
@@par}%
endgroup
csname #1markendcsname{#7}%
addcontentsline{toc}{#1}{%
ifnum #2>c@secnumdepth else
protectnumberline{csname the#1endcsname}%
fi
#7}%
else
def@svsechd{%
#6{hskip #3relax
@svsec #8}%
csname #1markendcsname{#7}%
addcontentsline{toc}{#1}{%
ifnum #2>c@secnumdepth else
protectnumberline{csname the#1endcsname}%
fi
#7}}%
fi
@xsect{#5}}
makeatother

%lethypercontentsline=contentsline
%renewcommand{contentsline}[4]{hypertarget{toc.#4}{}hypercontentsline{#1}{#2}{#3}{#4}}

% begin code to remove section numbers from the TOC
makeatletter
newcommand{@savenumber}{}% reserve global names
newcommand{@savetitle}{}

defcontentsline#1#2#3#4{%
hypertarget{toc.#4}{}% set up backlin
bgroup% separate numberline from title
renewcommand{numberline}[1]{xdef@savenumber{##1}}%
sbox0{#2}%
letnumberline=@gobble
xdef@savetitle{#2}%
egroup
begingroup
Hy@safe@activestrue
edefx{endgroup
defnoexpandHy@tocdestname{#4}%
}x
ifxHy@tocdestnameltx@empty
csname l@#1endcsname{#2}{#3}%
else
ifcaseHy@linktoc % none
csname l@#1endcsname{#2}{#3}%
or % section
csname l@#1endcsname{numberline{@savenumber}%
hyper@linkstart{link}{Hy@tocdestname}{@savetitle}hyper@linkend
}{#3}%
or % page
defHy@temp{#3}%
ifxHy@templtx@empty
csname l@#1endcsname{#2}{#3}%
else
csname l@#1endcsname{{#2}}{%
hyper@linkstart{link}{Hy@tocdestname}{#3}hyper@linkend
}%
fi
else % all
defHy@temp{#3}%
ifxHy@templtx@empty
csname l@#1endcsname{numberline{@savenumber}%
hyper@linkstart{link}{Hy@tocdestname}{@savetitle}hyper@linkend
egroup}{}%
else
csname l@#1endcsname{numberline{@savenumber}%
hyper@linkstart{link}{Hy@tocdestname}{@savetitle}hyper@linkend
}{%
hyper@linkstart{link}{Hy@tocdestname}{#3}hyper@linkend
}%
fi
fi
fi
}
makeatother

% Body
begin{document}
title{This is a Title}
date{}
maketitle
tableofcontents
section{A Section}
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
section{Another One}
subsection{Hello}
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
subsection{Goodbye}
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
section{Final Section}
Peace out.
end{document}





share|improve this answer


























  • Thanks a lot! This is utterly black magic to me. Might want to mention also that the lethypercontentsline seems to make the backlinks point to specific items in the Table of Contents; they point to the head of the document without those lines. At least this is the case when I tried it.

    – Luke Davis
    Jan 31 '18 at 3:49











  • It worked for me. Both redefinitions of contentsline add hypertarget{toc.#4}{} at the start. The source for @sect comes from source2e.pdf (CTAN) and the source for contentsline comes from hyperref.sty.

    – John Kormylo
    Jan 31 '18 at 4:05
















2














This both adds the section number to the back link, and removes the section number from the toc line. The latter was definitely harder.



documentclass[11pt]{article}
usepackage[margin=0.5in,footskip=0.4in]{geometry}
usepackage[T1]{fontenc}
usepackage{etoolbox}
usepackage{hyperref}
hypersetup{
colorlinks=true,
linkcolor=blue,
linktoc=all,
}

% For clickable section headers
% See https://tex.stackexchange.com/a/251964/73149
makeatletter
def@sect#1#2#3#4#5#6[#7]#8{%
ifnum #2>c@secnumdepth
let@svsec@empty
else
refstepcounter{#1}%
protected@edef@svsec{@seccntformat{#1}relax}%
fi
@tempskipa #5relax
ifdim @tempskipa>z@
begingroup
#6{sbox0{@svsec}% measure width
interlinepenalty @M
hangindent=dimexpr wd0+#3relax
noindenthskip #3relax
hyperlink{toc.#1.csname the#1endcsname}%
{@svsec #8}%
@@par}%
endgroup
csname #1markendcsname{#7}%
addcontentsline{toc}{#1}{%
ifnum #2>c@secnumdepth else
protectnumberline{csname the#1endcsname}%
fi
#7}%
else
def@svsechd{%
#6{hskip #3relax
@svsec #8}%
csname #1markendcsname{#7}%
addcontentsline{toc}{#1}{%
ifnum #2>c@secnumdepth else
protectnumberline{csname the#1endcsname}%
fi
#7}}%
fi
@xsect{#5}}
makeatother

%lethypercontentsline=contentsline
%renewcommand{contentsline}[4]{hypertarget{toc.#4}{}hypercontentsline{#1}{#2}{#3}{#4}}

% begin code to remove section numbers from the TOC
makeatletter
newcommand{@savenumber}{}% reserve global names
newcommand{@savetitle}{}

defcontentsline#1#2#3#4{%
hypertarget{toc.#4}{}% set up backlin
bgroup% separate numberline from title
renewcommand{numberline}[1]{xdef@savenumber{##1}}%
sbox0{#2}%
letnumberline=@gobble
xdef@savetitle{#2}%
egroup
begingroup
Hy@safe@activestrue
edefx{endgroup
defnoexpandHy@tocdestname{#4}%
}x
ifxHy@tocdestnameltx@empty
csname l@#1endcsname{#2}{#3}%
else
ifcaseHy@linktoc % none
csname l@#1endcsname{#2}{#3}%
or % section
csname l@#1endcsname{numberline{@savenumber}%
hyper@linkstart{link}{Hy@tocdestname}{@savetitle}hyper@linkend
}{#3}%
or % page
defHy@temp{#3}%
ifxHy@templtx@empty
csname l@#1endcsname{#2}{#3}%
else
csname l@#1endcsname{{#2}}{%
hyper@linkstart{link}{Hy@tocdestname}{#3}hyper@linkend
}%
fi
else % all
defHy@temp{#3}%
ifxHy@templtx@empty
csname l@#1endcsname{numberline{@savenumber}%
hyper@linkstart{link}{Hy@tocdestname}{@savetitle}hyper@linkend
egroup}{}%
else
csname l@#1endcsname{numberline{@savenumber}%
hyper@linkstart{link}{Hy@tocdestname}{@savetitle}hyper@linkend
}{%
hyper@linkstart{link}{Hy@tocdestname}{#3}hyper@linkend
}%
fi
fi
fi
}
makeatother

% Body
begin{document}
title{This is a Title}
date{}
maketitle
tableofcontents
section{A Section}
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
section{Another One}
subsection{Hello}
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
subsection{Goodbye}
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
section{Final Section}
Peace out.
end{document}





share|improve this answer


























  • Thanks a lot! This is utterly black magic to me. Might want to mention also that the lethypercontentsline seems to make the backlinks point to specific items in the Table of Contents; they point to the head of the document without those lines. At least this is the case when I tried it.

    – Luke Davis
    Jan 31 '18 at 3:49











  • It worked for me. Both redefinitions of contentsline add hypertarget{toc.#4}{} at the start. The source for @sect comes from source2e.pdf (CTAN) and the source for contentsline comes from hyperref.sty.

    – John Kormylo
    Jan 31 '18 at 4:05














2












2








2







This both adds the section number to the back link, and removes the section number from the toc line. The latter was definitely harder.



documentclass[11pt]{article}
usepackage[margin=0.5in,footskip=0.4in]{geometry}
usepackage[T1]{fontenc}
usepackage{etoolbox}
usepackage{hyperref}
hypersetup{
colorlinks=true,
linkcolor=blue,
linktoc=all,
}

% For clickable section headers
% See https://tex.stackexchange.com/a/251964/73149
makeatletter
def@sect#1#2#3#4#5#6[#7]#8{%
ifnum #2>c@secnumdepth
let@svsec@empty
else
refstepcounter{#1}%
protected@edef@svsec{@seccntformat{#1}relax}%
fi
@tempskipa #5relax
ifdim @tempskipa>z@
begingroup
#6{sbox0{@svsec}% measure width
interlinepenalty @M
hangindent=dimexpr wd0+#3relax
noindenthskip #3relax
hyperlink{toc.#1.csname the#1endcsname}%
{@svsec #8}%
@@par}%
endgroup
csname #1markendcsname{#7}%
addcontentsline{toc}{#1}{%
ifnum #2>c@secnumdepth else
protectnumberline{csname the#1endcsname}%
fi
#7}%
else
def@svsechd{%
#6{hskip #3relax
@svsec #8}%
csname #1markendcsname{#7}%
addcontentsline{toc}{#1}{%
ifnum #2>c@secnumdepth else
protectnumberline{csname the#1endcsname}%
fi
#7}}%
fi
@xsect{#5}}
makeatother

%lethypercontentsline=contentsline
%renewcommand{contentsline}[4]{hypertarget{toc.#4}{}hypercontentsline{#1}{#2}{#3}{#4}}

% begin code to remove section numbers from the TOC
makeatletter
newcommand{@savenumber}{}% reserve global names
newcommand{@savetitle}{}

defcontentsline#1#2#3#4{%
hypertarget{toc.#4}{}% set up backlin
bgroup% separate numberline from title
renewcommand{numberline}[1]{xdef@savenumber{##1}}%
sbox0{#2}%
letnumberline=@gobble
xdef@savetitle{#2}%
egroup
begingroup
Hy@safe@activestrue
edefx{endgroup
defnoexpandHy@tocdestname{#4}%
}x
ifxHy@tocdestnameltx@empty
csname l@#1endcsname{#2}{#3}%
else
ifcaseHy@linktoc % none
csname l@#1endcsname{#2}{#3}%
or % section
csname l@#1endcsname{numberline{@savenumber}%
hyper@linkstart{link}{Hy@tocdestname}{@savetitle}hyper@linkend
}{#3}%
or % page
defHy@temp{#3}%
ifxHy@templtx@empty
csname l@#1endcsname{#2}{#3}%
else
csname l@#1endcsname{{#2}}{%
hyper@linkstart{link}{Hy@tocdestname}{#3}hyper@linkend
}%
fi
else % all
defHy@temp{#3}%
ifxHy@templtx@empty
csname l@#1endcsname{numberline{@savenumber}%
hyper@linkstart{link}{Hy@tocdestname}{@savetitle}hyper@linkend
egroup}{}%
else
csname l@#1endcsname{numberline{@savenumber}%
hyper@linkstart{link}{Hy@tocdestname}{@savetitle}hyper@linkend
}{%
hyper@linkstart{link}{Hy@tocdestname}{#3}hyper@linkend
}%
fi
fi
fi
}
makeatother

% Body
begin{document}
title{This is a Title}
date{}
maketitle
tableofcontents
section{A Section}
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
section{Another One}
subsection{Hello}
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
subsection{Goodbye}
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
section{Final Section}
Peace out.
end{document}





share|improve this answer















This both adds the section number to the back link, and removes the section number from the toc line. The latter was definitely harder.



documentclass[11pt]{article}
usepackage[margin=0.5in,footskip=0.4in]{geometry}
usepackage[T1]{fontenc}
usepackage{etoolbox}
usepackage{hyperref}
hypersetup{
colorlinks=true,
linkcolor=blue,
linktoc=all,
}

% For clickable section headers
% See https://tex.stackexchange.com/a/251964/73149
makeatletter
def@sect#1#2#3#4#5#6[#7]#8{%
ifnum #2>c@secnumdepth
let@svsec@empty
else
refstepcounter{#1}%
protected@edef@svsec{@seccntformat{#1}relax}%
fi
@tempskipa #5relax
ifdim @tempskipa>z@
begingroup
#6{sbox0{@svsec}% measure width
interlinepenalty @M
hangindent=dimexpr wd0+#3relax
noindenthskip #3relax
hyperlink{toc.#1.csname the#1endcsname}%
{@svsec #8}%
@@par}%
endgroup
csname #1markendcsname{#7}%
addcontentsline{toc}{#1}{%
ifnum #2>c@secnumdepth else
protectnumberline{csname the#1endcsname}%
fi
#7}%
else
def@svsechd{%
#6{hskip #3relax
@svsec #8}%
csname #1markendcsname{#7}%
addcontentsline{toc}{#1}{%
ifnum #2>c@secnumdepth else
protectnumberline{csname the#1endcsname}%
fi
#7}}%
fi
@xsect{#5}}
makeatother

%lethypercontentsline=contentsline
%renewcommand{contentsline}[4]{hypertarget{toc.#4}{}hypercontentsline{#1}{#2}{#3}{#4}}

% begin code to remove section numbers from the TOC
makeatletter
newcommand{@savenumber}{}% reserve global names
newcommand{@savetitle}{}

defcontentsline#1#2#3#4{%
hypertarget{toc.#4}{}% set up backlin
bgroup% separate numberline from title
renewcommand{numberline}[1]{xdef@savenumber{##1}}%
sbox0{#2}%
letnumberline=@gobble
xdef@savetitle{#2}%
egroup
begingroup
Hy@safe@activestrue
edefx{endgroup
defnoexpandHy@tocdestname{#4}%
}x
ifxHy@tocdestnameltx@empty
csname l@#1endcsname{#2}{#3}%
else
ifcaseHy@linktoc % none
csname l@#1endcsname{#2}{#3}%
or % section
csname l@#1endcsname{numberline{@savenumber}%
hyper@linkstart{link}{Hy@tocdestname}{@savetitle}hyper@linkend
}{#3}%
or % page
defHy@temp{#3}%
ifxHy@templtx@empty
csname l@#1endcsname{#2}{#3}%
else
csname l@#1endcsname{{#2}}{%
hyper@linkstart{link}{Hy@tocdestname}{#3}hyper@linkend
}%
fi
else % all
defHy@temp{#3}%
ifxHy@templtx@empty
csname l@#1endcsname{numberline{@savenumber}%
hyper@linkstart{link}{Hy@tocdestname}{@savetitle}hyper@linkend
egroup}{}%
else
csname l@#1endcsname{numberline{@savenumber}%
hyper@linkstart{link}{Hy@tocdestname}{@savetitle}hyper@linkend
}{%
hyper@linkstart{link}{Hy@tocdestname}{#3}hyper@linkend
}%
fi
fi
fi
}
makeatother

% Body
begin{document}
title{This is a Title}
date{}
maketitle
tableofcontents
section{A Section}
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
section{Another One}
subsection{Hello}
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
subsection{Goodbye}
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
section{Final Section}
Peace out.
end{document}






share|improve this answer














share|improve this answer



share|improve this answer








edited Jan 30 '18 at 16:52

























answered Jan 30 '18 at 15:23









John KormyloJohn Kormylo

46.5k22672




46.5k22672













  • Thanks a lot! This is utterly black magic to me. Might want to mention also that the lethypercontentsline seems to make the backlinks point to specific items in the Table of Contents; they point to the head of the document without those lines. At least this is the case when I tried it.

    – Luke Davis
    Jan 31 '18 at 3:49











  • It worked for me. Both redefinitions of contentsline add hypertarget{toc.#4}{} at the start. The source for @sect comes from source2e.pdf (CTAN) and the source for contentsline comes from hyperref.sty.

    – John Kormylo
    Jan 31 '18 at 4:05



















  • Thanks a lot! This is utterly black magic to me. Might want to mention also that the lethypercontentsline seems to make the backlinks point to specific items in the Table of Contents; they point to the head of the document without those lines. At least this is the case when I tried it.

    – Luke Davis
    Jan 31 '18 at 3:49











  • It worked for me. Both redefinitions of contentsline add hypertarget{toc.#4}{} at the start. The source for @sect comes from source2e.pdf (CTAN) and the source for contentsline comes from hyperref.sty.

    – John Kormylo
    Jan 31 '18 at 4:05

















Thanks a lot! This is utterly black magic to me. Might want to mention also that the lethypercontentsline seems to make the backlinks point to specific items in the Table of Contents; they point to the head of the document without those lines. At least this is the case when I tried it.

– Luke Davis
Jan 31 '18 at 3:49





Thanks a lot! This is utterly black magic to me. Might want to mention also that the lethypercontentsline seems to make the backlinks point to specific items in the Table of Contents; they point to the head of the document without those lines. At least this is the case when I tried it.

– Luke Davis
Jan 31 '18 at 3:49













It worked for me. Both redefinitions of contentsline add hypertarget{toc.#4}{} at the start. The source for @sect comes from source2e.pdf (CTAN) and the source for contentsline comes from hyperref.sty.

– John Kormylo
Jan 31 '18 at 4:05





It worked for me. Both redefinitions of contentsline add hypertarget{toc.#4}{} at the start. The source for @sect comes from source2e.pdf (CTAN) and the source for contentsline comes from hyperref.sty.

– John Kormylo
Jan 31 '18 at 4:05


















draft saved

draft discarded




















































Thanks for contributing an answer to TeX - LaTeX Stack Exchange!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f412773%2fhow-can-i-make-the-section-text-in-a-table-of-contents-clickable-but-keep-the-s%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Paper upload error, “Upload failed: The top margin is 0.715 in on page 3, which is below the required...

Emraan Hashmi Filmografia | Linki zewnętrzne | Menu nawigacyjneGulshan GroverGulshan...

How can I write this formula?newline and italics added with leqWhy does widehat behave differently if I...