Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

\nameref of hyperlink package #74

Closed
danielezambelli opened this issue May 2, 2022 · 12 comments
Closed

\nameref of hyperlink package #74

danielezambelli opened this issue May 2, 2022 · 12 comments

Comments

@danielezambelli
Copy link

Hi!

Is it possible to implement "\nameref" of the "hyperlink" package?

Mini-example:

%--8<-------------------------------------
`
\documentclass[10pt,a4paper]{memoir}
\usepackage[T1]{fontenc}
\usepackage{textcomp}
\usepackage[utf8]{inputenc}
\usepackage[italian]{babel}
\usepackage{lipsum}

\ifdefined\HCode % compilazione htlatex
\def\pgfsysdriver{pgfsys-dvisvgm4ht.def}
\newcommand{\url}[1]{\Link[#1]{}{} #1 \EndLink}
\newcommand{\href}[2]{\Link[#1]{}{} #2 \EndLink}
\newcommand{\hypertarget}[2]{\Link[]{}{#1} #2 \EndLink}
\else % compilazione pdflatex
\RequirePackage[colorlinks=true]{hyperref}
\fi

\newcommand{\numnameref}[1]{\ref{#1} \nameref{#1}}

\begin{document}

\chapter{Primo capitolo}

\section{Sezione a}
\label{sec:pri_a}

\lipsum[1-2]

\section{Sezione b}
\label{sec:pri_b}

\lipsum[3-6]

\section{Sezione c}
\label{sec:pri_c}

\lipsum[7-9]

\section{Esercizi}

\subsection{Esercizi dei singoli paragrafi}

\subsubsection*{\numnameref{sec:pri_a}}

\subsubsection*{\numnameref{sec:pri_b}}

\subsection{Esercizi di riepilogo}

\end{document}
`
%--8<-------------------------------------

Thank you very much!

@michal-h21
Copy link
Owner

It works, but it seems that inside sectioning commands, referencing commands don't produce links. But it still produces correct text. But when you use it in normal text, it produces even link. Try this:

\documentclass[10pt,a4paper]{memoir}
\usepackage[T1]{fontenc}
\usepackage{textcomp}
\usepackage[utf8]{inputenc}
\usepackage[italian]{babel}
\usepackage{lipsum}

% \ifdefined\HCode % compilazione htlatex
% \def\pgfsysdriver{pgfsys-dvisvgm4ht.def}
% \newcommand{\url}[1]{\Link[#1]{}{} #1 \EndLink}
% \newcommand{\href}[2]{\Link[#1]{}{} #2 \EndLink}
% \newcommand{\hypertarget}[2]{\Link[]{}{#1} #2 \EndLink}
% \else % compilazione pdflatex
\RequirePackage[colorlinks=true]{hyperref}
% \fi

\newcommand{\numnameref}[1]{\ref{#1} \nameref{#1}}

\begin{document}

\chapter{Primo capitolo}

\section{Sezione a}
\label{sec:pri_a}

\lipsum[1-2]

\section{Sezione b}
\label{sec:pri_b}

\lipsum[3-6]

\section{Sezione c}
\label{sec:pri_c}

\lipsum[7-9]

\section{Esercizi}

\subsection{Esercizi dei singoli paragrafi}

\subsubsection*{\numnameref{sec:pri_a}}

\subsubsection*{\numnameref{sec:pri_b}}

In text: \numnameref{sec:pri_b}

\subsection{Esercizi di riepilogo \url{https://google.com/}}

\end{document}

See the difference between \subsubsection*{\numnameref{sec:pri_b}} and In text: \numnameref{sec:pri_b}.

@danielezambelli
Copy link
Author

It works, but when I compile with:
make4ht numnameref.tex -c md_make4ht -l -u -s -d dist "mathjax"

I get the following error
[ERROR] htlatex: Compilation errors in the htlatex run
[ERROR] htlatex: Filename Line Message
[ERROR] htlatex: ./md_make4ht. 4 LaTeX Error: Missing \begin{document} in `md_make4ht.cfg'.:

My config file is:
md_make4ht.txt

Where is the error?

Thanks.

@michal-h21
Copy link
Owner

You can try to run make4ht with the -a debug option to get context of the error. In this case, your configuration file contains configurations for the ulem package, but your document don't use it, so all \Configure commands got interpreted. So adding \usepackage{ulem} to your document should fix it. But you also need updated TeX Live, as it needs the correct version of ulem.4ht.

@danielezambelli
Copy link
Author

The command:

make4ht numnameref.tex -l -u -s "mathjax"

make4ht does not compile your text correctly.

It does not display \nameref correctly.

Why?

Thank you for your attention.

@michal-h21
Copy link
Owner

Thanks for the report. This seems to be caused by Memoir, it redefines \nameref somehow. I will need to investigate it and try to find a fix for that.

@michal-h21
Copy link
Owner

This file, memhfixc.4ht should fix this issue:


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% memhfixc.4ht (2023-03-19-13:46), generated from tex4ht-4ht.tex
% Copyright 2023 TeX Users Group
% Copyright 2009-2023 TeX Users Group
%
% This work may be distributed and/or modified under the
% conditions of the LaTeX Project Public License, either
% version 1.3c of this license or (at your option) any
% later version. The latest version of this license is in
%   http://www.latex-project.org/lppl.txt
% and version 1.3c or later is part of all distributions
% of LaTeX version 2005/12/01 or later.
%
% This work has the LPPL maintenance status "maintained".
%
% The Current Maintainer of this work
% is the TeX4ht Project <http://tug.org/tex4ht>.
%
% If you modify this program, changing the
% version identification would be appreciated.
\@ifpackageloaded{nameref}{
\HLet\@mem@titlerefnolink\@namerefstar
\HLet\@mem@titleref\T@nameref
}{}

\Hinput{memhfixc}
\endinput


@danielezambelli
Copy link
Author

If the file memhfixc.4ht is in the same directory as the file to be compiled , it works, but if I copy it to the dir

/usr/share/texlive/texmf-dist/tex/generic/tex4ht/

it has no effect.

ll /usr/share/texlive/texmf-dist/tex/generic/tex4ht/mem*.*
Permissions Size User Group Date Modified Name
.rw-r--r-- 934 root 19 Mar 18:55 /usr/share/texlive/texmf-dist/tex/generic/tex4ht/memhfixc.4ht

What am I doing wrong?

Thank you.

@michal-h21
Copy link
Owner

Does the kpsewhich memhfixc.4ht command find the file? Maybe you need to run the texhash command, it should update the file database, and it may work then.

@danielezambelli
Copy link
Author

danielezambelli commented Mar 20, 2023

No, he can't find it.
Isn't it sufficient to copy the file to the directory?

@michal-h21
Copy link
Owner

I think it isn't, as TeX uses database of files for faster access. At least it used to do, I am not sure if it still does that. You can also can try to put the file in ~/texmt/tex/generic/tex4ht (and validate if it is accessible with kpsewhich).

@danielezambelli
Copy link
Author

Unfortunately, our project is quite complex also uses tcolorbox, and this complicates things.

I modified the minimal example to make it more like the document in production.

The references are stoned.

\documentclass[10pt,a4paper]{memoir}
\RequirePackage[italian]{babel}

\RequirePackage[usenames, dvipsnames]{xcolor}   % gestione colori
\RequirePackage[colorlinks, hyperindex, pagebackref,
                linkcolor=RoyalBlue, filecolor=RoyalBlue,
                citecolor = black, urlcolor=RoyalBlue]{hyperref}

\RequirePackage{amsmath, amssymb, amsthm}
\RequirePackage{tikz}
\RequirePackage[most]{tcolorbox}

\usepackage{iftex}
\ifpdftex\typeout{************* PDFTeX*****************}
  \RequirePackage[T1]{fontenc}
  \RequirePackage[utf8]{inputenc}% non più necessario, ma non disturba
  \RequirePackage{stix2} % font

\else
  \ifluatex\typeout{************* LuaLaTeX *****************}
    \usepackage{fontspec}
    \setmainfont{STIX}[Ligatures=TeX]
    \usepackage[math-style=ISO]{unicode-math}
    \setmathfont{STIX Two Math}
  \fi
\fi

\usepackage{lipsum}

\newcommand{\numnameref}[1]{\ref{#1} \nameref{#1}}

\newcommand{\colortheo}{green}
\newcommand{\colortit}{green}

\theoremstyle{plain}
\tcbset{
theostyle/.style={fonttitle=\bfseries\upshape, fontupper=\slshape,
colback=\colortheo!5!white, colframe=\colortheo!50!black,
theorem style=plain, coltitle=\colortit!30!black}
}

\newtcbtheorem[number within=chapter]{teorema}{Teorema}
              {theostyle}{th}

\begin{document}

\chapter{Primo capitolo}

\section{Sezione a}
\label{sec:pri_a}

\begin{teorema}{di Euclide}{}
I numeri primi sono infiniti.
\end{teorema}


\lipsum[1-2]

\section{Sezione b}
\label{sec:pri_b}

\begin{teorema}{di Pitagora}{}
\(i^2 = c_1^2 +c_2^2\).
\end{teorema}

\lipsum[3-6]

\section{Sezione c}
\label{sec:pri_c}

\lipsum[7-9]

\section{Esercizi}

\subsection{Esercizi dei singoli paragrafi}

\subsubsection*{\numnameref{sec:pri_a}}

\subsubsection*{\numnameref{sec:pri_b}}

\subsubsection*{\numnameref{sec:pri_c}}

In text: \numnameref{sec:pri_b}

\subsection{Esercizi di riepilogo \url{https://google.com/}}

\end{document}
%--8<-------------------------------------

Thank you for your attention and competence.

@michal-h21
Copy link
Owner

This example seems to work with TeX4ht sources, but TeX Live 2023 wasn't updated yet.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants