打开阅读困难字体

打开阅读困难字体

是否可以直接使用OpenDyslexic 字体在 latex 文档中?需要哪些步骤?

答案1

由于它是以 TrueType 字体的形式发布的,因此您可以轻松使用 或xetexluatex这是我在字体首次发布时使用 LuaLaTeX 编写的示例。lua 代码来自此站点的某个地方(可能是来自 Cthulu 问题,但我记不清了)。我将结果发送给了字体的作者,幸运的是,他对此很感兴趣。

\documentclass{article}
\thispagestyle{empty}
\pagestyle{empty}
\usepackage{fontspec}
\setmainfont{Open Dyslexic}
\usepackage{filecontents}

%create a lua script file
\begin{filecontents*}{luaFunctions.lua}

function createReplaceTable()    
    replaceTable = {}

    -- create a table with all ASCII chars
    -- the name and(!) the value of each table item is the ASCII char
    -- this is important if the char shouldn't be replaced
    -- the table have 128 items each filled with the corresponding char
    for i = 1, 128, 1 do    
       replaceTable[string.char(i-1)] = string.char(i-1)
    end
end

function parseString(input)
    outputString = ""

    -- for each char in the given string we replace
    -- the char with the content of the table item
    -- because the table items have the same name like the chars
    -- we have access to the table item via the given char
    for i = 1, string.len(input) do
        char = input:sub(i, i)
        outputString = outputString..rotateString(char)
    end

    tex.print(outputString)
end

function parseFile(fileName)
    -- open file
    local input = io.open('lorem.txt', 'r')

    -- parse each line
    for line in input:lines() do
        parseString(line)
    end
end

function rotateString(c)
    if c == " " then
      return c
    end
    local ang = math.random(-10,10)
    local dp = math.random(-.5,.5)
    return "\\raisebox{" .. dp .. "pt}{\\rotatebox[origin=c]{" .. ang .. "}{" .. c .. "}}"
end

function fillReplaceTable()
    -- here we fill/override the replacements for each ASCII char
    replaceTable["L"] = "\\textbf{\\large L}\\marginpar{\\tiny 'L'(\\stepcounter{counterForL}\\#\\thecounterForL)}"
    replaceTable["o"] = "\\underline{o}"
    replaceTable["e"] = ""
end

\end{filecontents*}    

% read the external lua file to declare the functions,
% but without execute the Lua commands and functions
\directlua{dofile("luaFunctions.lua")}

%create and fill the tables
\directlua{createReplaceTable()}
\directlua{fillReplaceTable()}

% latex commands to execute the lua functions
\def\parseString#1{\directlua{parseString("#1")}}
\def\parseFile#1{\directlua{parseFile("#1")}}

\begin{document}
\parseString{%
This is the Open Dyslexia font.
Allegedly, it was designed so that the letters have a `gravity' to them which helps to anchor them to the baseline and thus prevent them jumping about on the page (this being one of the ways that dyslexia can show itself).
I'm not so sure that it's working.
}
\end{document}

结果:

使用 lualatex 打开 Dyslexic 字体

(编辑时添加)Speravir(在评论中)完全正确:上面的大部分内容都是为了实现随机旋转效果。使用字体很简单:将它安装在 TeX 可以找到的地方,使用包fontspec,将字体设置为Open Dyslexic(阅读 fontspec 手册以了解有关字体名称以及xelatex和之间的区别的详细信息lualatex),然后使用xelatex或进行编译lualatex。以下是一个较小的示例(使用编译lualatex)。

\documentclass{article}
%\url{http://tex.stackexchange.com/q/153778/86}
\thispagestyle{empty}
\pagestyle{empty}
\usepackage{fontspec}
\setmainfont{Open Dyslexic}

\begin{document}
This is the Open Dyslexia font.
Allegedly, it was designed so that the letters have a `gravity' to
them which helps to anchor them to the baseline and thus prevent them
jumping about on the page (this being one of the ways that dyslexia
can show itself).
I'm not so sure that it's working.
\end{document}

使用 Open Dyslexia 字体的更普通的文档

相关内容