5

I'm trying to generate a QR code from a text file using the qrcode package.

Using \qrcode{\input{file.txt}} fails with this error message:

! Undefined control sequence.
\in@ #1#2->\begingroup \def \in@@
##1#1{}\toks@ \expandafter {\in@@ #2{}{}#1...
l.20 \qrcode{\input{file.txt}}

Using the catchfile package:

\CatchFileDef\filecontent{file.txt}{}
\expandafter\qrcode\expandafter{\filecontent}

Fails with this error:

! Paragraph ended before \qrcode@in was complete.

Is there any way to generate a scalable QR code in LaTeX from a text file input?

Edit: complete example

main.tex

\documentclass[10pt,a4paper]{letter}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}
\usepackage[T1]{fontenc}
\usepackage{qrcode}
\begin{document}
\qrcode{\input{file.txt}}
\end{document}

file.txt

this file has
multiple lines

may even ^ contain an empty line
contains --- hyphens
and ends with a newline
3
  • please make a complete example that people can run and debug Sep 28, 2017 at 15:58
  • the second error (with catchfile package) may be caused by an empty line in file.txt. But without knowing the file it's hard to tell.
    – Mike
    Sep 28, 2017 at 16:01
  • @Mike yeah it probably is caused by an empty line. When the file doesn't contain an empty line though, what I get is a QR code with the text without spaces and without linebreaks
    – Sorashi
    Sep 28, 2017 at 16:12

1 Answer 1

9

You cannot have empty lines in the input file without taking special precautions. The following should work:

\CatchFileDef\filecontent{file.txt}{\endlinechar=`\^^J \catcode32=12 }
\expandafter\qrcode\expandafter{\filecontent}

provided you have no special characters such as # or & (some similar trick as above might do also for these).

Here’s what I get (scanned, copied and pasted from my phone)

this file has
multiple lines

may even ^ contain an empty line
contains --- hyphens
and ends with a newline
2
  • It works, but the resulting QR code contains the contents of file.txt without spaces and without linebreaks
    – Sorashi
    Sep 28, 2017 at 16:12
  • 3
    @Sorashi Try the current version
    – egreg
    Sep 28, 2017 at 17:33

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .