Search code examples
latex

Latex interprets an [x] at the start of a new line as a unit of measurment with x being a number. How do I Stop it from doing it?


So I have a simple text I want to render in latex:\

\section{Source}
[1] Some text\\
[2] \href{A Text}{A Link to a Website}\\
[3] \href{Another Text}{Another Link to a Website}\\
[4] \href{A 3rd Text}{A 3rd Link to a Website}

The compiler throws the error "Illegal unit of measure (pt inserted)" for the 2nd and 4th line and compiles only the line with [1] correctly and leave away the [2], [3] and [4] at the following lines. I know that with {} I can use \{ and \} to get them but how can I make that for [] now?


Solution

  • You really shouldn't abuse \\ for line breaks (with the exception of tabulars etc.)

    In your case this is not only bad style but causes an error because latex interprets the [] after it as optional argument and expects the amount of vertical space to be inserted instead of just a plain number.

    You could either use proper paragraphs by leaving empty lines:

    \documentclass{article}
    \usepackage{hyperref}
    \usepackage{indentfirst}
    
    \begin{document}
    
    \section{Source}
    [1] Some text
    
    [2] \href{A Text}{A Link to a Website}
    
    [3] \href{Another Text}{Another Link to a Website}
    
    [4] \href{A 3rd Text}{A 3rd Link to a Website}
    
    
    \end{document}
    

    or if your whole document consists of such lines, you could make latex respect them:

    \documentclass{article}
    \usepackage{hyperref}
    \usepackage{indentfirst}
    
    
    \begin{document}
    
    \obeylines
    
    \section{Source}
    [1] Some text
    [2] \href{A Text}{A Link to a Website}
    [3] \href{Another Text}{Another Link to a Website}
    [4] \href{A 3rd Text}{A 3rd Link to a Website}
    
    \end{document}