TikZ:包含几种用途各异的字体的示例文档?

TikZ:包含几种用途各异的字体的示例文档?

有没有使用 TikZ 与非常不同的字体的示例,比如https://tug.org/FontCatalogue/

字体类型似乎有很大差异。例如,我成功地使用了“calligra”,但其他字体似乎具有不同的结构,我认为必须有一种简单的方法可以在一个文档中使用其中的几种字体。例如,这些字体的用法似乎有很大差异(参见“用法”段落):

我怎样才能获得包含所有这些内容的文本?

\documentclass{article}
\usepackage{tikz}
\usepackage{calligra}
\begin{document}
\begin{tikzpicture}
\node[draw] at (5,5) {\Huge \calligra Some text};
\end{tikzpicture}
\end{document}

答案1

即使你打算使用 Ti 字体Z,我看不出你为什么需要用它来生成字体采样器/样本文档。

在这里,我使用 ConTeXt 列出系统上的所有字体,检查它们是否包含字符,如果包含,则输出一个包含格鲁吉亚 Unicode 块中所有字符的页面。要运行它,请将其另存为<filename>.cld,然后运行context <filename>.cld以处理文件。

#!/usr/bin/env -S context --once --forcecld

---------------------
--- Configuration ---
---------------------

local target_characters = {
    "ა", "ბ", "გ", "დ", "ე", "ვ", "ზ", "თ", "ი", "კ", "ლ", "მ", "ნ",
    "ო", "პ", "ჟ", "რ", "ს", "ტ", "უ", "ფ", "ქ", "ღ", "ყ", "შ", "ჩ",
    "ც", "ძ", "წ", "ჭ", "ხ", "ჯ", "ჰ", "ჱ", "ჲ", "ჳ", "ჴ", "ჵ", "ჶ",
    "ჷ", "ჸ", "ჹ", "ჺ", "჻", "ჼ", "ჽ", "ჾ", "ჿ", "Ⴀ", "Ⴁ", "Ⴂ", "Ⴃ",
    "Ⴄ", "Ⴅ", "Ⴆ", "Ⴇ", "Ⴈ", "Ⴉ", "Ⴊ", "Ⴋ", "Ⴌ", "Ⴍ", "Ⴎ", "Ⴏ", "Ⴐ",
    "Ⴑ", "Ⴒ", "Ⴓ", "Ⴔ", "Ⴕ", "Ⴖ", "Ⴗ", "Ⴘ", "Ⴙ", "Ⴚ", "Ⴛ", "Ⴜ", "Ⴝ",
    "Ⴞ", "Ⴟ", "Ⴠ", "Ⴡ", "Ⴢ", "Ⴣ", "Ⴤ", "Ⴥ", "Ⴧ", "Ⴭ",
}
local size = tex.sp("1cm")


------------
--- Code ---
------------

-- Generic wrapper so that we can use `context.step()`
context.stepwise(function() print(xpcall(function()

-- The character that we'll test each font for
local target_character = utf8.codepoint(target_characters[1])

-- Reload the font names database
if not os.getenv("OSFONTDIR") then
    os.setenv(
        "OSFONTDIR",
        "/usr/share/fonts:" .. os.getenv("HOME") .. "/.local/share/fonts/"
    )
end
fonts.names.load(true, true)

-- Get a list of all fonts on the system
local all_fonts = fonts.names.list("", true, true)

-- Configure the page layout
context.setupbodyfont { (0.75 * size) .. "sp" }
context.setupTABLE( { frame = "off" })
context.setupTABLE(
    { "row" }, { "each" },
    { align = "low, center", style = "tt" }
)
context.setupTABLE( { "row" }, { "first" }, { style = "ttbf" })
context.setupTABLE( { "column" }, { "each" }, { width = (1.5 * size) .. "sp" })
context.setupalign { "lesshyphenation", "verytolerant" }

-- Iterate over all the fonts
context.starttext()
for _, font in table.sortedpairs(all_fonts) do
    -- Get the full path to the font file
    local path = resolvers.findfile(font.filename)
    local hashed_path = sha2.hash256(path)

    if path:match("Fontmap") then
        -- Skip the fontmap files (not actual fonts)
        goto continue
    end

    -- Load the font
    local _, data = fonts.definers.define {
        name = path,
        filename = path,
        cs = hashed_path,
        size = size,
    }

    -- Check if the font contains the target character
    if data and data.characters and data.characters[target_character] then
        -- Begin the page
        context.step()
        context.startTEXpage { offset = size .. "sp" }
        context.startTABLE()

        -- Print the font name
        context.NC { nc = tostring(math.min(10, #target_characters)) }
        context(file.basename(path))
        context.NC() context.NR()

        -- Print the target characters
        for i, character in ipairs(target_characters) do
            context.NC()
            context[hashed_path](character)

            if i % 10 == 0 then
                context.NC() context.NR()
            end
        end
        context.NC() context.NR()

        -- End the page
        context.stopTABLE()
        context.stopTEXpage()
    end
    ::continue::
end
context.stoptext()

-- Close the wrapper function
end, debug.traceback)) end)

第一次运行将需要真的由于 ConTeXt 需要创建字体缓存,因此需要很长时间(5 分钟以上),但后续运行应该更快(在我的计算机上为 30 秒)。

在我的计算机(Linux + TeX Live 2024)上,我得到以下输出:

输出页面 1 输出页面 2 输出页面 3

答案2

我终于成功创建了我所想的那种示例文档。它就在这里。

我现在真的不明白自己在做什么(例如:T1、B1、字体之间的差异......),但这些以后会一点一点地出现。欢迎任何改进建议 :-)

顺便说一句,我找到了一个包含我所期望内容(甚至更多)的 pdf,但没有提供 latex 源:https://www.overleaf.com/latex/templates/fontspec-all-the-fonts/hjrpnxhrrtxc

\documentclass{article}

\usepackage{fontspec}
\usepackage{calligra}
\usepackage{bbold}
\usepackage{pbsi}
\usepackage[T1]{fontenc}
\usepackage{cyklop}
\usepackage{DejaVuSans}
\usepackage{auncial}
\usepackage[B1]{fontenc}

\usepackage{tikz}

\begin{document}

\begin{tikzpicture}

\node[draw] at (5,15) {\Huge {\fontspec{cyklop} Sample text in cyklop}};
\node[draw] at (5,13) {\Huge {\fontspec{DejaVuSans} Sample text in DejaVuSans}};
\node[draw] at (5,11) {\Huge {\fontspec{QTArabian} Sample text in QTArabian}};
\node[draw] at (5,9) {\Huge \aunclfamily Sample text in aunclfamily};
\node[draw] at (5,7) {\Huge \calligra Sample text in calligra};
\node[draw] at (5,5) {\Huge {\fontspec{QTBoulevard} Sample text in QTBoulevard}};
\node[draw] at (5,3) {\Huge \bbfamily Sample text in bbold / bbfamily};
\node[draw] at (5,1) {\Huge \bsifamily Sample text in pbsi / bsifamily};

\end{tikzpicture}

\end{document}

在此处输入图片描述

编辑:还有很多字体我不知道如何一起使用。例如:

相关内容