4

How to encode the string [)>\x1e06\x1dKRUA144OZHIAIU.433642.034REH\x1e\x04 in pst-barcode, where \x1e is ASCII character 001E, \x1d is ASCII character 001D, and \x04 is ASCII character 004.

\documentclass{article}
\usepackage{fontspec}
\usepackage{pst-barcode}
\usepackage{auto-pst-pdf}

\begin{document}
\begin{pspicture}(1in,1in)
    %\psbarcode{[)>\x1e06\x1dKRUA144OZHIAIU.433642.034REH\x1e\x04}{width=1.0 height=1.0}
{qrcode}
\end{pspicture}
\end{document}

Compiling using the command

 xelatex.exe -synctex=1 -interaction=nonstopmode "document"

It gives an error:

MiKTeX GPL Ghostscript 9.25: Unrecoverable error, exit code 1

I read the documentation; on page 58 there is an example, but it's for a different type of code, and I specifically need to compile a QR code in XeLaTeX.

Thank you in advance.

0

2 Answers 2

5

With option parse you can input the ASCII control characters GS, RS and EOT using the ^NNN syntax. NNN in this case has to be a decimal not a hexadecimal! See section 5.2.10 of the pst-barcode example for more information. Some extra effort is needed to have the ) in the text:

\documentclass{article}
\usepackage{fontspec}
\usepackage{pst-barcode}
\usepackage{auto-pst-pdf}

\begin{document}
Complicated:

\begin{pspicture}(1in,1in)
\expandafter\psbarcode\expandafter{\detokenize{[\)>^03006^029KRUA144OZHIAIU.433642.034REH^030^004}}
  {width=1.0 height=1.0 parse}{qrcode}
\end{pspicture}

Easy:

\begin{pspicture}(1in,1in)
  \psbarcode{[^041>^03006^029KRUA144OZHIAIU.433642.034REH^030^004}
  {width=1.0 height=1.0 parse}{qrcode}
\end{pspicture}
\end{document}

qrcode as expected

BTW: As you say, you are using XeLaTeX (which is not recommended any longer), you won't need auto-pst-pdf.

3
  • Apparently, I didn't read the documentation carefully enough. Indeed, everything is described in section 5.2.10. Thank you very much for pointing that out to me. Commented Oct 7 at 19:29
  • 2
    Could you tell me where I can read about XeLaTeX no longer being recommended, and what should be used instead of XeLaTeX? Commented Oct 7 at 19:33
  • 2
    @АнтонБрюзгин See, e.g., tex.stackexchange.com/questions/752081/… or texdev.net/2024/11/05/engine-news-from-the-latex-project. You should switch to LuaLaTeX. If you have problems with the change, you can ask questions. Commented Oct 8 at 6:38
5

You could use the qrcode package:

\documentclass{article}
\usepackage{fontspec}
\usepackage{qrcode}

\begin{document}
\qrcode{qrcode}
\end{document}

\qrcode{<contents>} will encode <contents> as a QR code.


To encode your string you can use ^^ (this is a rot64 in TeX, so ^^@ becomes NUL), so your \x1e in that notation is ^^^. However \qrcode tries to be clever and reads its argument somewhat verbatimly so it tries to break the ^^-notation. We can circumvent that by tokenizing the input before \qrcode reads it. Then we get errors because ^^^ etc. are invalid characters, which we can fix by changing their category codes.

\documentclass{article}
\usepackage{fontspec}
\usepackage{qrcode}

\begin{document}
\begingroup
\catcode`\^^^=12
\catcode`\^^]=12
\catcode`\^^D=12
\unexpanded{%
  \endgroup
\qrcode{[)>^^^06^^]KRUA144OZHIAIU.433642.034REH^^^^^D}}
\end{document}

enter image description here

4
  • @Teepeemm see edit. Commented Oct 7 at 12:21
  • I cannot use the qrcode package. I need pdf417, datamatrix, QR-code and possibly other types of codes in one file. Thank you very much for the solution. Where only QR-Code can be used, I will use this solution. Commented Oct 7 at 12:23
  • 1
    @АнтонБрюзгин you should be able to continue using pst-barcode for the non-QR-codes. Commented Oct 7 at 12:28
  • Yes, I understand that I can use pst-barcode for other codes and qrcode for QR codes, but I wanted to minimize dependencies. However, if that's not possible, I will use both packages. Commented Oct 7 at 12:46

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.