1

How can I change the behavior of PDF view for only one \hypertarget, but others should stay unchanged.

I'm trying to make a link to the text, but I want exactly this link not to change X position of my viewer i.e the viewer's zoom level and X position should stay the same, but only Y position have to be modified (to perform the jumping to the text)

Here's the current behavior enter image description here

\documentclass[a5paper]{article}
%\usepackage{showframe}
\usepackage{hyperref}
\hypersetup{colorlinks=true,linkcolor=blue}

\begin{document}

\hypertarget{txt:link}{text}

\vspace{1cm}

\hfil \hyperlink{txt:link}{click}

\end{document}

My goal is to remove the horizontal shifting when following this exact link.

Bernard
  • 271,350
antshar
  • 4,238
  • 9
  • 30
  • I'm not sure if this is something TeX can do, it might have to do with configuring the viewer itself. Zathura has a configuration option called "link-hadjust" which seems relevant here (although it looks like you're not using zathura) – user202729 May 21 '22 at 12:59
  • @user202729 sure you can. Destination options can be set for every destination. – Ulrike Fischer May 21 '22 at 13:03
  • might be related https://tex.stackexchange.com/questions/59362/hyperref-link-placement-alignment-to-left-page-border-and-top-of-page . – user202729 May 21 '22 at 13:16
  • Okay looks like you can set the left property of pdfview/XYZ to null or something similar – user202729 May 21 '22 at 13:26
  • Actually same question as hyperref - Avoid page vertical re-alignment when clicking a hyperlink - TeX - LaTeX Stack Exchange but... (however I look at this it's horizontal alignment, the other title is misleading) – user202729 May 21 '22 at 13:29
  • I tried to change the value manually to null, but it appears that Firefox pdf.js does not respect the value. Try downloading this PDF file https://pybin.pw/AHm1X8V1XwEuqdGlo4MFRUor5EcU.pdf (← no virus here) and click the link in your PDF viewer to see if it works. – user202729 May 21 '22 at 13:46
  • @user202729 answer from this post isn't helpful at all. Accepted answer there produces errors for me. – antshar May 21 '22 at 14:22
  • @user202729 this post I also have seen, but it doesn't work for me either. No answers there unfortunately. But anyway, I'm trying to make changes locally, but passing pdfview as an option to the package or via \hypersetup applies changes globally. – antshar May 21 '22 at 14:24
  • @user202729 in your PDF definitely something happens, but not exactly what I want. In your file jumping to the link's source is anchored to the very left of the page, but I'd like to keep y-scrolling unchanged. – antshar May 21 '22 at 14:26
  • looking more closely at your question, you can't have both: see text after the jump and not move to the left. Depending on the zoom level, it has to move. – Ulrike Fischer May 21 '22 at 19:02
  • @UlrikeFischer I don't need to see text, I just want to jump to the same Y level as text – antshar May 21 '22 at 19:11
  • that won't either. Destination don't know anything about the current position and zoom factor. (well you could perhaps use javascript but that would work only in a view viewers. – Ulrike Fischer May 21 '22 at 19:17
  • @UlrikeFischer I use PDFXChange as my PDF viewer and editor. It allows to create links manually and it has inherit option for all X, Y and zoom. It doesn't use javascript for that I'm sure. So it's hyperref restriction then? – antshar May 21 '22 at 19:21
  • Every link/target you can create with pdfxchange I could create too, but currently I don't see which action fits to your description. If you have a small example put it somewhere for download. – Ulrike Fischer May 21 '22 at 19:29
  • @UlrikeFischer https://drive.google.com/file/d/1jHR-FA3ert6DvelymxKH4PrdC6jFK4RO – antshar May 21 '22 at 19:48
  • ah, a /D [ 8 0 R /XYZ null 467.716535 null ] destination. Well you can create that but you have to do it manually, the \pdfdest primitive doesn't create such null value. – Ulrike Fischer May 21 '22 at 21:12
  • With \pdfspecial or something like that, that is. (I also null out the left value in my pdf but it seems that it must not be named. Anyway it'll definitely take some time to figure out how to compute these coordinate values) – user202729 May 22 '22 at 13:12

0 Answers0