# define url as variable and use inside \href

I am creating a script in python that automatically creates a a pdf using LaTeX. To make the automation easier I define variables in a file called Variables.tex which I load using

\input{variables}


This works fine usually, however now I want to create a variable with a web address inside. The file looks something like this:

\def \MOParameters{A, B, C}
\def \MOTitle{Measurements at location X}
\def \MORawDataURL{https://location/to/the/file}
\def \MOCountry{Countryname}


I then use these variables (it works fine without the variable with the web-address) like such:

Parameters: & \MOParameters{}\\


This however gives an error (undefined control sequence), does anybody know why?

\documentclass[a4paper,oneside,10pt]{report}
\input{Variables}

\begin{document}
\pagestyle{plain}
\setcounter{page}{1}

\chapter{Data information}
\section{Meta data}
\begin{tabular}{p{4cm} p{7cm}}
Title:              & \MOTitle{}\\
Source:             & \MOSource{}\\
Parameters:         & \MOParameters{}\\
\end{tabular}
\end{document}


Variables.tex:

\def \MOParameters{A, B, C}
\def \MOTitle{Measurements at location x}
\def \MORawDataURL{https://localhost-108/subdir/Data/CT 2015.011/Pars}
\def \MOSource{Data}

• Where is \MOParameters defined? That's the undefined macro the compilation complains about. The rest works, if it is put in a compilable document, which is your task, actually ;-) – user31729 Oct 9 '17 at 14:55
• No, give a document, not just fragments here ... – user31729 Oct 9 '17 at 14:59
• you should put \usepackage{hyperref} below your documentclass. – Marijn Oct 9 '17 at 15:09
• This is a classic example of why providing a complete minimal example (or see here) is almost always so useful. The problem would've been detected instantly. – jon Oct 9 '17 at 15:13
• Be aware that some input in an url (e.g. # and %) will need special care. – Ulrike Fischer Oct 9 '17 at 15:20

For using \href you need to load the hyperref package.

MWE:

\documentclass{article}
\usepackage{hyperref}
\begin{document}
\def \MOParameters{A, B, C}
\def \MOTitle{Measurements at location X}
\def \MORawDataURL{https://location/to/the/file}
\def \MOCountry{Countryname}

Parameters: \MOParameters{}