Im trying to use the hyperref package for creating a link to a website with a dynamic url. I have a script that outputs an id that should be used in the url.
I have been trying to wrap my head around this for hours trying to figure how to achieve this but as a fairly new user of TeX I must admit defeat now.
Here is an example of what I want to do:
\newcommand{\getid}[0]
{
\input{|"get-id.sh"}
}
\newcommand{\createlink}[0]
{
\getid \\ % Just for debugging
\href{https://www.website.com/\getid}{MyLink}
}
This produces the id correctly but on the next line there is nothing remotely what I want, more exactly just "\let\reserved@d=\bgroup\def{\@@par}".
I have also tried \edef\getid{\input{|"get-id.sh"}} with the same result even though I feel like that should evaluate the input before I try to use the variable.
Using \def\getid{MyStaticID} works just fine so the problem only appears when using \input.
Possible workarounds could be to write the value with TeX code to a file and then import it, alternatively pass it to the code using pdftex. I would however prefer to do it in the TeX file as I am trying to do but is it even possible or a limitation somewhere I will have to live with?
Thanks in advance.
Edit
I build the pdf with pdfTeX from the TeX Live system installed with MacTeX. I use latexmk for building and in my .latexmkrc I have the line
$pdflatex = 'pdflatex --shell-escape -synctex=1 -interaction=nonstopmode';
which should enable input from commands (which it does successfully at times, just not with URLs).
My main document looks like this (stripped from irrelevant stuff for ease of reading but with all packages):
\documentclass[a4paper, 11pt]{report}
\usepackage[utf8]{inputenc}
\usepackage{graphicx}
\usepackage{epstopdf}
\usepackage{enumitem}
\usepackage{hyperref}
\usepackage{ifthen}
\usepackage{pdfsync}
\usepackage{titlesec}
\usepackage{tocloft}
\newcommand{\getid}[0]
{
\input{|"get-id.sh"}
}
\newcommand{\createlink}[0]
{
\getid \\ % Just for debugging
\href{https://www.website.com/\getid}{MyLink}
}
\newcommand{\wordcount}[0]
{
\input{|"texcount -sum -1 content/chapters/*"}
}
\begin{document}
\wordcount{}
\createlink{}
\end{document}
and the get-id.sh is currently just echoing git rev-parse HEAD.
The wordcount and first part of createlink works just fine so there must be something in the url or hyperref packages that breaks (or just doesn't work the way I want/expect it to).
get-id.shdo something likeecho "\def\getid{$(git rev-parse HEAD)}\input fileand then usepdflatex $(get-id.sh). Now\href{https://www.website.com/\getid}{MyLink}will work as expected insidefile.tex. – Feb 14 '18 at 06:14\begingroup\makeatletter\endlinechar=\m@ne\everyeof{\noexpand} \edef\x{\endgroup\def\noexpand\gitid{\@@input|"./get-id.sh" }}\x. This comes from https://tex.stackexchange.com/questions/16790/write18-capturing-shell-script-output-as-command-variable, which also has an explanation. There are also other solutions using various packages given on this page. – Feb 14 '18 at 10:28