Skip to content

Create links to local files #2695

Closed
Closed

Description

@ede1998

Description

I tried to include a video in my typst presentation (based on the polylux package). I found out that this isn't supported (yet?) in #955.

So I tried to settle for a link to the local file instead but I couldn't get it to work. In the output pdf, there is no link

#link("https://www.google.de")[This works]

#link("file://demo.mp4")[This does not work]
#link("file:///demo.mp4")[This does not work]
#link("./demo.mp4")[This does not work]

Use Case

I want to quickly open a local file from the generated pdf. For instance, when creating a presentation and I want to show a video or demonstrate something, I want to have a clickable link in the pdf that opens the linked file with the default program for its type, e.g. video player for video, folder explorer for folders.

Activity

  1. added
    feature request
    on Nov 15, 2023
  2. bastienvoirin commented on Nov 16, 2023

    @bastienvoirin
    SponsorContributor

    This feature would be awesome on its own, but even more so in conjunction with HTML export, in particular for Typst's integration into note-taking apps #114 (comment) which rely heavily on internal/local links to create a network of notes. But then it would be preferable not to achieve such links using embedding/self-contained attachments to avoid overly redundant data storage and exponential file sizes.

    If it is possible to implement local links this way, I find that

    #link("./filename.ext")[...]

    feels more "natural" on the scale of user-friendliness and makes it easier to specify both absolute (filename.ext) and relative (./filename.ext) paths.

  3. Atreyu-94 commented on Nov 21, 2023

    @Atreyu-94

    @bastienvoirin Great! I got it with your syntax, this really saves a lot of time! I didn't think it was included.

    #link("img/image.gif")[press here]

    Should this issue be closed?

  4. Atreyu-94 commented on Nov 21, 2023

    @Atreyu-94

    I attempted to nest the image within the link, so that the image was the clickable element. It worked flawlessly and was also quite intuitive.

    #link("img/anim_fps15.gif")[
    #figure(
        image("img/anim_fps15.gif", width: 100%),
        caption: "Some caption",
      )
    ]

    well, this made me very happy :P

    Edit: Grammar :(

  5. laurmaedje commented on Nov 21, 2023

    @laurmaedje
    Member

    Interesting that it just works. Typst just forwards the link to the PDF reader, so I guess PDF supports this. It might not have the exact same semantics as paths in Typst, e.g. with absolute paths.

  6. Atreyu-94 commented on Nov 21, 2023

    @Atreyu-94

    Now I tried something new. In the previous code, the entire block (including the caption) was clickable. It is more desirable that only the image was clickable.

    #figure(
        link("img/anim_fps15.gif")[image("img/anim_fps15.gif", width: 100%)],
        caption: "Some caption",
      )

    However, this time it did not work, perhaps because the link content does not support images.

    So I only get instead of the image, the text corresponding to the command and it is effectively clickable:
    image

  7. Atreyu-94 commented on Nov 21, 2023

    @Atreyu-94

    Ok, I got it adding #image(...) instead of image(...), sorry :P

    #figure(
        link("img/anim_fps15.gif")[#image("img/anim_fps15.gif", width: 100%)],
        caption: "Some caption",
      )
  8. added
    model
    and removed on Nov 24, 2023
  9. ede1998 commented on Dec 1, 2023

    @ede1998
    Author

    Closing this as it turns out that this already works. Not sure what I did wrong when I tried the first time.

    The behavior depends on the pdf viewer I use.

    For okular all of the following work and seem to open with the default program I configured for the given file type (e.g. VLC for videos, dolphin as file manager, gwenview for images). For pdfpc, the video and image also opens but uses some other programs (e.g. mkv for the video) and the folder fails to open for me.

    	#link("./demo.mp4", image("demo_still.png", height:87%))
    	#link(".", "Clickable text"))
    	#link("/home/user/Pictures/landscapes/jf6uSBC.jpg", "Clickable1"))

    This does not work it seems as the pdf viewer does not expand the tilde.

    	#link("~/Pictures/landscapes/jf6uSBC.jpg", "Clickable2"))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    feature requestmodel

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions