3

I'm trying to code czech names in QRcode using qrcode package and luaLaTeX engine. Some accents are encoded in QRcode and the reader (QR Code Reader or QR Extrme, both run on Xperia L1) is unable to decode them and tries refocus. Correct QR code with same size is decoded within second.

Is there a way how to repair such malfunctioning characters? The QR code is capable of encoding such characters.

MWE based on Alan Munn's answer:

\documentclass{article}
\usepackage{fontspec}
\usepackage[english,french,czech]{babel}
\usepackage[]{qrcode}
\begin{document}

\qrcode[]{í}% produces no error, resolved

\bigskip
\qrcode[]{š}% produces no error, unresolved

\bigskip
%Dummy text containing all the weird czech characters.
\qrcode[]{Příliš žluťoučký kůň úpěl ďábelské ódy}% Unresolvable

\end{document}

Resolvable dummy text generated by goqr.me containing the weird characters:
Příliš žluťoučký kůň úpěl ďábelské ódy

And same text encoded by MWE resulting in unresolvable code:
enter image description here

2

2 Answers 2

3

You can use expl3 to convert the input to bytes:

 \documentclass{article}
 \usepackage{fontspec}
 \usepackage{expl3}
 \usepackage[]{qrcode}
 \begin{document}
 \ExplSyntaxOn 
  \str_set_convert:Nnnn \l_tmpa_str {Příliš~žluťoučký~kůň~úpěl~ďábelské~ódy}{}{utf8/bytes}
  \exp_args:No\qrcode{\l_tmpa_str}
 \ExplSyntaxOff 
 \end{document}

enter image description here

Addition

The following works with pdflatex and lualatex. It assumes that the file is utf8 encoded and that the input doesn't contain commands. There are two special inputs: \\ forces a newline and \% gives a percentchar.

\documentclass{article}
 \usepackage{xparse}
 \usepackage[forget]{qrcode}
 \makeatletter
 % for pdftex is it needed to suppress the writing of arbitrary bytes to the aux:
 \def\qr@writebinarymatrixtoauxfile#1{}%
 \makeatletter

 \ExplSyntaxOn
  \cs_generate_variant:Nn \str_set_convert:Nnnn {Nnno}
  \tl_new:N\g__ufqr_convert_method_tl
  \seq_new:N\l__ufqr_tmpa_seq
  \seq_new:N\l__ufqr_tmpb_seq
  \sys_if_engine_pdftex:TF
   {
    \tl_gset:Nn\g__ufqr_convert_method_tl {}
   }
   {
    \tl_gset:Nn\g__ufqr_convert_method_tl {utf8/bytes}
   }
 \NewDocumentCommand \unicodeqrcode { m }
    {
      \tl_set:Nn \l_tmpa_tl { #1 }
      \regex_replace_all:nnN {\c{\%}}{\cO\%} \l_tmpa_tl

      \seq_clear:N \l__ufqr_tmpa_seq
      \seq_clear:N \l__ufqr_tmpb_seq
      \exp_args:NNno\seq_set_split:Nnn \l__ufqr_tmpa_seq { \\ } { \l_tmpa_tl}
      \seq_map_inline:Nn \l__ufqr_tmpa_seq
       {
        \str_set_convert:Nnno \l_tmpa_str { ##1 } {}{\g__ufqr_convert_method_tl}
        \seq_put_right:No\l__ufqr_tmpb_seq {\l_tmpa_str}
       }
     \exp_args:Nx\qrcode{ \seq_use:Nn \l__ufqr_tmpb_seq {\tl_to_str:N \? } }
    }

\ExplSyntaxOff
 \begin{document}
 \unicodeqrcode{Umlaute: äüö\\Zweite &$_\^\% Zeile\\Grüße und ❤ und eine 🦆}
 \end{document}

enter image description here

1

qrcode.tex says:

Non-ASCII characters

If you are using csplain with pdfTeX (no XeTeX, no LuaTeX) then UTF-8 input is correctly interpreted from \qrcode parameter.

The technical background: the encTeX's \mubyte is set to zero during scanning the \qrcode parameter, so the parameter is rawly UTF-8 encoded and this is correct for QR codes.

Problems:

  1. You cannot use \qrcode{parameter} inside another macro, bacause UTF-8 encoded parameter is reencoded already.
  2. You cannot use XeTeX or LuaTeX because UTF-8 encoded parameter is reencoded to Unicode already. And the backward conversion from Unicode to UTF-8 isn't implemented here at macro level.

Both problems are in my particullar case unaviodable.

same code, except for a \usepackage{fontspec} line produces following result:

enter image description here

3
  • Is that the kind of thing that should be reported to the package maintainer, as a bug? After all, utf-8, luatex, and xetex have been around for awhile.
    – user139954
    Apr 25, 2018 at 21:38
  • @RobtAll the quote comes from the qrcode.tex located directly in package folder. I suppose mainainer is aware of such behaviour.
    – Crowley
    Apr 26, 2018 at 8:30
  • Ah. That was obvious, but I missed it. The package should detect compiler and issue direct error.
    – user139954
    Apr 26, 2018 at 13:54

You must log in to answer this question.

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