[Tex/LaTex] Unresolvable QRcode with accented characters

accentsqrcode

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

Best Answer

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

Related Question