I'm looking for a command, which would take a text and print it with the first letter formatted differently:
\first{Hello, world!}
Should be turned into:
\textbf{\large H}ello, world!
Is there a package, which would do this?
I'm looking for a command, which would take a text and print it with the first letter formatted differently:
\first{Hello, world!}
Should be turned into:
\textbf{\large H}ello, world!
Is there a package, which would do this?
If the only aversion to lettrine is breaking your spell checker, then just bundle it inside another macro, \first.
PDFLATEX
Since the OP asked about pdflatex in another comment, I introduce \pervyy, which bundles the 2-byte letter sequence that makes up Cyrillic characters, for use in \lettrine.
\documentclass{article}
\usepackage{lettrine}
\usepackage[T2A]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[english, russian]{babel}
\newcommand\first[1]{\firstaux#1\relax}
\def\firstaux#1#2\relax{\lettrine{#1}{#2}}
\newcommand\pervyy[1]{\pervyyaux#1\relax}
\def\pervyyaux#1#2#3\relax{\lettrine{#1#2}{#3}}
\begin{document}
\first{This} is a test of using\\
lettrine without breaking \\
the spell-check features.
\pervyy{Привет,} мир!
\end{document}
LUALATEX OR XELATEX
If one wanted to use an engine other than pdflatex, then omit the T2A encoding, load an appropriate font supporting the Cyrillic alphabet, and just use \first, regardless of which alphabet is employed:
\documentclass{article}
\usepackage{fontspec}
\setmainfont{EB Garamond} % choose a suitable text font
\usepackage{lettrine}
\usepackage[utf8]{inputenc}
\usepackage[english, russian]{babel}
\newcommand\first[1]{\firstaux#1\relax}
\def\firstaux#1#2\relax{\lettrine{#1}{#2}}
\begin{document}
\first{This} is a test of using\\
lettrine without breaking \\
the spell-check features.
\first{Привет,} мир!
\end{document}
If you're willing and able to compile your document with LuaLaTeX, the following solution may be of interest to you.
% !TEX TS-program = lualatex
\documentclass{article}
\usepackage{fontspec}
\setmainfont{EB Garamond} % choose a suitable text font
\usepackage{luacode} % for "\luaexec" macro
\luaexec{
function first ( s )
local t
t = "\textbf{\large " .. unicode.utf8.sub(s,1,1) .. "}"
tex.sprint ( t .. unicode.utf8.sub(s,2) )
end
}
\newcommand\first[1]{\luaexec{ first ( "#1" ) }}
\begin{document}
\first{Hello, world!}
\first{Привет, мир!}
\end{document}
\first{Привет, мир!}. The main change, I think, consisted of loading the fontspec package and loading a text font that contains Cyrillic characters. :-)
– Mico
Sep 12 '21 at 13:06
\lettrine{H}{ello, world!}is not what I'm looking for, sinceello, world!will trigger my spell checker – yegor256 Sep 12 '21 at 11:45\newcommand\foo[1]{\textbf{\large #1}},,,,\foo Hello, world– David Carlisle Sep 12 '21 at 12:04