country with city if short

This commit is contained in:
Marc Wäckerlin
2025-11-08 19:11:43 +01:00
parent 0f802a02a8
commit 407c7eed2d
6 changed files with 54 additions and 4 deletions
+2 -1
View File
@@ -94,6 +94,7 @@ Layout options are set as options to the `\documentclass`, e.g.:
- `fill` or `nofill`: fill empty space between icon and text, default: `fill`
- `qrfirst` or `textfirst`: switch position of QR-Code and text block, default: `qrfirst`
- `https` or `www`: should links in the hints be prefixed with `https://` or `www.`, default: `https`
- `countryformat=`: how to format the country in address. Values: `auto` (default: inline with mdash if <4 chars and city/zip exists), `inline` (always inline with mdash), `below` (always separate line)
- `qreclevel=`: QR error correction level `L` (~7%), `M` (~15%), `Q` (~25%), or `H` (~30%), default: `Q`. Use `H` when `photoinqr=true`.
- `photoinqr` or `nophotoinqr`: place photo in the center of the QR code (`photoinqr`) instead of next to the name, default: `nophotoinqr`. **Requires `qreclevel=H` for reliable scanning**.
- `qrlogoscale=`: photo size in QR code as percentage of QR width (0-100), default: `25` (25% width = 6.25% area). Recommended values: Level H: 25-30%, Level Q: 20%, Level M: 15%, Level L: 10%. Higher values may reduce scannability.
@@ -133,7 +134,7 @@ See this example_
- `\city`: name of the address location
- `\region`: region of the address
- `\zip`: zip code of the address
- `\country`: full name of country of the address in the language of the card
- `\country`: full name of country of the address in the language of the card (short codes like `CH`, `USA`, `D` are automatically placed inline with mdash before city/zip, longer names on separate line)
- `\phone`: your phone number, the phone is marked as mobile, so to be used for voice and text (SMS)
- `\email`: your email address
- `\jabber`: your [jabber] or xmpp chat address
+36 -3
View File
@@ -42,6 +42,7 @@
\DeclareComplementaryOption{textfirst}{qrfirst}
\DeclareBoolOption[true]{https}
\DeclareComplementaryOption{www}{https}
\DeclareStringOption[auto]{countryformat} % auto: <4 chars inline with mdash, >=4 separate line; inline: always inline; below: always separate line
\DeclareDefaultOption{\@unknownoptionerror}
\ProcessKeyvalOptions*
@@ -68,6 +69,7 @@
\RequirePackage{fontawesome}
\RequirePackage[final]{qrcode}
\RequirePackage{etoolbox}
\RequirePackage{xstring} % for string length checking
\RequirePackage{DejaVuSans}
\RequirePackage[T1]{fontenc}
\RequirePackage{wrapfig}
@@ -145,7 +147,6 @@
\newcommand\cond[1]{\ifcsdef{#1}{\exec{#1}}{}}
\newcommand\heightscale{\dimexpr\textheight-\ifcsempty{name}{0em}{2em}-\ifcsdef{Xpgpfingerprint}{2em}{0em}-\ifcsdef{Xadditionalnames}{2em}{0em}\relax}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% name - assemble full name from the parts, such as Xgivennames and Xfamilynames
\newcommand\name{\ifexists{Xhonoricprefix}{\Xhonoricprefix\ }\ifexists{Xgivennames}{\Xgivennames\ }\ifexists{Xfamilynames}{\Xfamilynames}\ifexists{Xhonoricsuffix}{\ \Xhonoricsuffix}}
@@ -192,6 +193,38 @@ FN:\name\ifexists{Xadditionalnames}{\ifcsempty{name}{} { }\Xadditionalnames}\BCQ
END:VCARD\BCQ@nl}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% formatcountry - format country based on length and options
\newcommand\formatcountry{%
\ifcsdef{Xcountry}{%
\def\BCQ@shouldinline{false}%
% Check countryformat option
\ifdefstring{\BCQ@countryformat}{inline}{%
\def\BCQ@shouldinline{true}%
}{%
\ifdefstring{\BCQ@countryformat}{below}{%
\def\BCQ@shouldinline{false}%
}{%
% auto mode: check length
\StrLen{\Xcountry}[\BCQ@countrylen]%
\ifnum\BCQ@countrylen<4\relax%
% Short country code AND city/zip exists inline
\ifboolexpr{test {\ifcsdef{Xcity}} or test {\ifcsdef{Xzip}}}{%
\def\BCQ@shouldinline{true}%
}{}%
\fi%
}%
}%
% Output country
\ifdefstring{\BCQ@shouldinline}{true}{%
\Xcountry\ \textemdash\ %
}{%
\Xcountry
}%
}{}%
}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% address - the address as shown in the textbox
\newcommand\address{
@@ -202,9 +235,9 @@ END:VCARD\BCQ@nl}
\cond{Xstreet}
\cond{Xzip} \cond{Xcity}
\formatcountry\cond{Xzip} \cond{Xcity}
\cond{Xregion} \cond{Xcountry}
\cond{Xregion}
}
Binary file not shown.
Binary file not shown.
Binary file not shown.
+16
View File
@@ -0,0 +1,16 @@
% !TeX program = xelatex
\documentclass{businesscard-qrcode}
\type{home}
\givennames{Max}
\familynames{Muster}
\street{Beispielstrasse\ 42}
\city{Winterthur}
\zip{8400}
\country{CH}
\phone{+41 52 123 45 67}
\email{max@example.ch}
\begin{document}
\drawcard
\end{document}