
다음과 같은 텍스트 구절로 시작합니다.
This is a sample passage.
3~4개의 가능한 크기 목록에서 각 단어가 무작위로 다른 크기로 표시되도록 설정하려면 어떻게 해야 합니까?
예를 들어, 출력에서 "This"는 클 수 있고 "is"는 작을 수 있으며 "a"는 중간 크기일 수 있습니다.
- 문서가 렌더링될 때마다 크기가 다를 수 있습니다.
답변1
Aditya와 Henri ConTeXt가 언급한 두 가지 명령 외에도 명령을 제공 \applytosplitstringwordspaced
하고 각각 또는 주어진 인수 \applytosplitstringcharspaced
에 명령을 적용합니다 .word
character
\startluacode
function userdata.randomwordsize(str)
local sizes = { "10pt", "12pt", "14pt", "16pt", "18pt", "20pt" }
local size = sizes[math.random(1,6)]
context.startfont{ string.formatters["Serif at %s"](size) }
context(str)
context.stopfont()
end
\stopluacode
\starttext
\defineexpandable[1]\RandomWordSize
{\ctxlua{userdata.randomwordsize("#1")}}
\applytosplitstringwordspaced\RandomWordSize
{The fraction of fossil olfactory receptor genes is significantly
higher in all species with full color vision. This suggests that
the evolution of trichromatic vision --- which allows these
primates to detect food, mates, and danger with visual cues ---
has reduced their reliance on the sense of smell.}
\blank
\applytosplitstringcharspaced\RandomWordSize
{The fraction of fossil olfactory receptor genes is significantly
higher in all species with full color vision. This suggests that
the evolution of trichromatic vision --- which allows these
primates to detect food, mates, and danger with visual cues ---
has reduced their reliance on the sense of smell.}
\stoptext
답변2
어려운 부분은 구절에서 단어를 분리하고 각 단어에 임의의 매크로를 적용하는 것입니다. ConTeXt는 \processwords
이를 수행하는 명령을 제공합니다 . 이 명령을 사용하려면 먼저 \processword
특정 단어에 작용할 매크로를 정의해야 합니다 .
예를 들어, 각 단어 주위에 프레임을 그리고 싶다고 가정해 보겠습니다. 그런 다음 다음을 정의합니다.
\def\processword{\inframed}
\starttext
Normal text \processwords{This is a simple passage.} Normal text
\stoptext
이는
이제 다음 단계는 임의의 글꼴 크기를 선택하여 적용하는 매크로를 만드는 것입니다.
답변3
Aditya의 답변은 원칙적으로 정확하지만 글꼴 크기를 무작위로 지정하는 순진한 매크로는 작동하지 않습니다. 이는 기본적으로 \processwords
다음을 사용하기 때문입니다.“오래된 전화”여기서 각 단어는 상자에 들어가고 \processword
매크로는 한 번만 평가됩니다. 이를 완화하려면 수동으로“메타펀콜”또한 Lua를 호출할 필요도 없습니다.
\def\processword#1{{\switchtobodyfont[\randomnumber{5}{15}pt]#1}}
\starttext
Normal text \processwords{This is a simple passage.} Normal text
\unprotect
\def\processwords#1%
{\syst_helpers_process_word#1 \_e_o_w_}% no \unskip
\protect
Normal text \processwords{This is a simple passage.}Normal text
\stoptext
\processseparatedlist
또는 임의의 구분 기호를 사용할 수 있는 방법을 사용할 수 있습니다 .
\processseparatedlist
[This is a simple passage.]
[ ]
{\groupedcommand{\bgroup\switchtobodyfont[\randomnumber{5}{15}pt]}{\space\egroup}}
모든 경우에 목록 뒤에 가짜 공백이 있는지 확인하세요.