Working version

This commit is contained in:
Olaf
2026-07-02 00:38:01 +02:00
parent 75ab49751f
commit eca60fef9f
7 changed files with 325 additions and 1 deletions
+2
View File
@@ -0,0 +1,2 @@
example.log
example.aux
+119 -1
View File
@@ -1,2 +1,120 @@
# foldable-namecard
This repo contains a quick and easy style file for creating foldable name cards from a CVS input file. A LaTeX package for printing A4 foldable namecards with a name, country, and logo.
## Requirements
### Compiler
**This package requires XeLaTeX.** It will produce a hard error and abort if compiled
with `pdflatex` or `lualatex`. The package uses `fontspec` and `xeCJK` for advanced font handling, which are only fully supported by XeLaTeX.
Compile with:
```
xelatex example.tex
```
### LaTeX Packages
The following packages are required (most are part of a standard TeX Live or MiKTeX installation):
- `geometry` - Page layout
- `graphicx` - Image handling
- `keyval` - Key-value options
- `iftex` - Conditional compilation based on engine
- `tikz` and `pgf` - Drawing and positioning
- `xcolor` - Color support
- `fontspec` - Font configuration (XeTeX)
- `xeCJK` - CJK character support (for Chinese, Japanese, Korean)
### System Fonts
You must install the following fonts on your system:
| Font | Purpose | Notes |
|------|---------|-------|
| **Hind** | Primary font for names and text | Download from [Google Fonts](https://fonts.google.com/specimen/Hind) |
| **Liberation Sans** or **DejaVu Sans** | Fallback for extended Latin characters (accents, diacritics like ǐ) | Usually pre-installed on Linux/macOS; use one if Hind lacks certain glyphs |
| **Noto Sans CJK SC** (or system CJK font) | Chinese character support | For rendering Chinese names |
#### Installation Instructions
**macOS:**
```bash
# Download Hind from Google Fonts, then:
cp ~/Downloads/Hind-*.otf ~/Library/Fonts/
```
**Linux (Ubuntu/Debian):**
```bash
# Install system fonts
sudo apt-get install fonts-hind fonts-dejavu fonts-noto-cjk
# Or manually copy to ~/.fonts/ and run:
fc-cache -fv
```
**Windows:**
```
# Download Hind from Google Fonts
# Right-click .otf files → Install
```
If any font is missing, the package will attempt to use fallbacks or emit a warning.
## Usage
### Single card
```latex
\documentclass{article}
\usepackage{foldable-namecard}
\namecardsetup{
name=Alex Johnson,
country=Sweden,
logo=mylogo.png
}
\begin{document}
\makefoldablenamecard
\end{document}
```
### Batch printing from a CSV file
```latex
\documentclass{article}
\usepackage{foldable-namecard}
\namecardsetup{logo=mylogo.png}
\begin{document}
\makefoldablenamecardsfromfile{names.csv}
\end{document}
```
The CSV file must contain one `name,country` pair per line. Blank lines are skipped.
The package supports international characters including accented Latin letters and Chinese characters.
```
Alex Johnson,Sweden
Mina Patel,India
Sofia Garcia,Spain
Valgerður Ólafsdóttir,Iceland
李明 (Lǐ Míng),China
王芳,中国
```
## Options (`\namecardsetup`)
| Key | Default | Description |
|----------------|--------------|------------------------------------------|
| `name` | `Your Name` | Name printed on the card |
| `country` | `Country` | Country printed below the name |
| `logo` | *(none)* | Path to logo image file |
| `logowidth` | `2cm` | Width of the logo |
| `logoheight` | `10mm` | Height constraint for the logo |
| `debugboxes` | *(on)* | Show bounding boxes for layout debugging |
| `nodebugboxes` | — | Hide bounding boxes |
BIN
View File
Binary file not shown.
+11
View File
@@ -0,0 +1,11 @@
% Compile with: xelatex example.tex
\documentclass{article}
\usepackage{foldable-namecard}
\namecardsetup{
logo=isoclogo.png
}
\begin{document}
\makefoldablenamecardsfromfile{names.csv}
\end{document}
+185
View File
@@ -0,0 +1,185 @@
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{foldable-namecard}[2026/07/01 A4 foldable namecard]
\RequirePackage[a4paper,margin=0mm]{geometry}
\RequirePackage{graphicx}
\RequirePackage{keyval}
\RequirePackage{iftex}
\RequirePackage{tikz}
\usetikzlibrary{calc}
\RequirePackage{xcolor}
\ifXeTeX\else
\PackageError{foldable-namecard}{%
This package requires XeLaTeX.\MessageBreak
Please compile with xelatex instead of lualatex or pdflatex%
}{%
Compilation will abort. Re-run with: xelatex <your-file>.tex%
}%
\stop
\fi
\tracinglostchars=0 % Suppress warnings about missing glyphs
\RequirePackage{fontspec}
\IfFontExistsTF{Hind}{%
\setmainfont{Hind}[
BoldFont = Hind-Bold,
UprightFont = Hind-Regular,
SemiBoldFont = Hind-SemiBold,
]%
% Try multiple font options for fallback support
\IfFontExistsTF{Liberation Sans}{%
\newfontfamily\NC@namefont{Liberation Sans}[
BoldFont = Liberation Sans Bold,
]%
}{%
\IfFontExistsTF{DejaVu Sans}{%
\newfontfamily\NC@namefont{DejaVu Sans}[
BoldFont = DejaVu Sans Bold,
]%
}{%
\let\NC@namefont\relax
}%
}%
}{%
\PackageWarningNoLine{foldable-namecard}{Hind font not found; using default font}%
}
\ifXeTeX
\RequirePackage{xeCJK}
\setCJKmainfont[
BoldFont = RODE Noto Sans CJK SC B,
]{RODE Noto Sans CJK SC R}
\fi
\makeatletter
\newsavebox{\NC@namebox}
\newcommand\NC@name{Your Name}
\newcommand\NC@country{Country}
\newcommand\NC@logo{}
\newlength\NC@logoheight
\newlength\NC@logowidth
\newif\ifNC@debugboxes
%\NC@debugboxestrue
\setlength\NC@logoheight{10mm}
\setlength\NC@logowidth{2cm}
\define@key{NC}{name}{\renewcommand\NC@name{#1}}
\define@key{NC}{country}{\renewcommand\NC@country{#1}}
\define@key{NC}{logo}{\renewcommand\NC@logo{#1}}
\define@key{NC}{logoheight}{\setlength\NC@logoheight{#1}}
\define@key{NC}{logowidth}{\setlength\NC@logowidth{#1}}
\define@key{NC}{debugboxes}[true]{\NC@debugboxestrue}
\define@key{NC}{nodebugboxes}[true]{\NC@debugboxesfalse}
\newcommand{\namecardsetup}[1]{%
\setkeys{NC}{#1}%
}
\newcommand{\NC@dbgbox}[1]{%
\ifNC@debugboxes
\fbox{#1}%
\else
#1%
\fi
}
\newcommand{\NC@renderlogo}{%
\ifx\NC@logo\@empty
% No logo configured.
\else
\begingroup
\edef\NC@logofile{\NC@logo}%
\IfFileExists{\NC@logofile}{%
\NC@dbgbox{\includegraphics[width=\NC@logowidth,keepaspectratio]{\NC@logofile}}%
}{%
\fbox{\parbox[c][\NC@logoheight][c]{5cm}{\centering Logo file not found}}%
}%
\endgroup
\fi
}
\newcommand{\NC@panelcontent}{%
\NC@dbgbox{%
\begin{minipage}[c][0.92\paperwidth][c]{0.98\paperheight}
\centering
% Measure height of name resized to 25cm width
\savebox{\NC@namebox}{%
\resizebox{0.95\linewidth}{!}{\bfseries\ifx\NC@namefont\relax\NC@name\else{\NC@namefont\NC@name}\fi}%
}%
% If height > 4cm, scale down to 4cm; otherwise use 25cm version
\ifdim\ht\NC@namebox>4cm
{\NC@dbgbox{\makebox[0.95\linewidth][c]{\resizebox{!}{4cm}{\bfseries\ifx\NC@namefont\relax\NC@name\else{\NC@namefont\NC@name}\fi}}}}%
\else
{\NC@dbgbox{\makebox[0.95\linewidth][c]{\usebox{\NC@namebox}}}}%
\fi\par
\vspace{5mm}
{\NC@dbgbox{\makebox[0.9\linewidth][c]{\resizebox{!}{7.5mm}{\large \NC@country}}}\par}
\end{minipage}%
}%
}
\ExplSyntaxOn
\seq_new:N \l_nc_fields_seq
\ior_new:N \l_nc_input_ior
\cs_new_protected:Npn \NC_process_csv_line:n #1
{
\tl_set:Nn \l_tmpa_tl {#1}
\tl_trim_spaces:N \l_tmpa_tl
\tl_if_blank:VTF \l_tmpa_tl
{ }
{
\seq_set_split:NnV \l_nc_fields_seq { , } \l_tmpa_tl
\seq_pop_left:NN \l_nc_fields_seq \l_tmpa_tl
\tl_trim_spaces:N \l_tmpa_tl
\seq_pop_left:NN \l_nc_fields_seq \l_tmpb_tl
\tl_trim_spaces:N \l_tmpb_tl
\typeout{===\ Printing\ namecard:\ \l_tmpa_tl,\ \l_tmpb_tl\ ===}
\namecardsetup{name=\l_tmpa_tl,country=\l_tmpb_tl}
\NC@renderpage
\newpage
}
}
\NewDocumentCommand{\makefoldablenamecard}{ }
{
\NC@renderpage
\newpage
}
\NewDocumentCommand{\makefoldablenamecardsfromfile}{m}
{
\ior_open:Nn \l_nc_input_ior {#1}
\ior_map_inline:Nn \l_nc_input_ior
{ \NC_process_csv_line:n {##1} }
\ior_close:N \l_nc_input_ior
}
\ExplSyntaxOff
\newcommand{\NC@renderpage}{%
\thispagestyle{empty}%
\begin{tikzpicture}[remember picture,overlay]
% Fold guide at the center of the A4 page (parallel to long edge).
\draw[dashed,gray!70,line width=0.4pt]
([xshift=0.5\paperwidth]current page.south west) --
([xshift=0.5\paperwidth]current page.north west);
% Left panel with text parallel to the long edge.
\node[anchor=center] at ([xshift=0.30\paperwidth]current page.west) {\rotatebox{270}{\NC@panelcontent}};
% Right panel with opposite orientation for the folded side.
\node[anchor=center] at ([xshift=0.70\paperwidth]current page.west) {\rotatebox{90}{\NC@panelcontent}};
% Logos at the outer edges of the page.
\node[anchor=west] at ([xshift=10mm]current page.west) {\rotatebox{270}{\NC@renderlogo}};
\node[anchor=east] at ([xshift=-10mm]current page.east) {\rotatebox{90}{\NC@renderlogo}};
\end{tikzpicture}%
\null
}
\makeatother
BIN
View File
Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

+8
View File
@@ -0,0 +1,8 @@
Alex Johnson,Sweden
Mina Patel,India
Sofia Garcia,Spain
Jan van den Heuvel tot Beichlingen, Netherlands
Valgerður Ólafsdóttir, Iceland
李明 (Lǐ Míng), China
王芳,中国
O.K., NL
1 Alex Johnson Sweden
2 Mina Patel India
3 Sofia Garcia Spain
4 Jan van den Heuvel tot Beichlingen Netherlands
5 Valgerður Ólafsdóttir Iceland
6 李明 (Lǐ Míng) China
7 王芳 中国
8 O.K. NL