ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • 이미지 경로 정하기
    TeX과 친구들 2020. 12. 28. 13:35

    오래 전에 디지털 방송 수신기 제조사에서 일했었다. 매우 다양한 모델들이 있어서 나는 거의 매 주마다 한두 권의 사용 설명서를 만들어 인쇄소에 넘겨야 했다. 매뉴얼들이 내용에서 대동소이해서, 당시에 나는 레이텍으로, 그것을 거의 완성한 뒤에야 비로소 "싱글 소싱"이라는 개념이 있다는 것을 알게 되었는데, 싱글 소싱 시스템을 구축했다. 

    한 가지 다소 어려운 문제가 삽입할 이미지들의 경로들을 결정하는 것이었다.

    +---common
        +---remote1
        +---remote2
        +---remote3
        +---OSD1
            +---english
                +---satellite
                +---terrestrial
                +---cable
            +---german
                +---satellite
                +---terrestrial
                +---cable
            +---french
                +---satellite
                +---terrestrial
                +---cable
        +---OSD2 
        +---OSD3

    이를테면, 실은 이보다 훨씬 복잡했는데, 이런저런 옵션들을 지정한 뒤에 그것들이 조합되어 다음과 같은 효과를 일으키는 경로 설정이 이루어지게 하는 것이다.

    \graphicspath{ 
      {../common/remote2/}
      {../common/OSD2/}
      {../common/OSD2/german/}
      {../common/OSD2/german/cable/}
    }

    이를 구현하는 코드에 \csname이 거듭 사용되었다.

    \expandafter\def\csname  RemotePath\endcsname
    {\csname CommonPath\endcsname Remote/\csname remoteno\endcsname/}
    \expandafter\def\csname OSDPath\endcsname
    {\csname CommonPath\endcsname\csname osdno\endcsname
    /}
    \expandafter\def\csname Ginput@path\endcsname{ 
        {\csname LocalPath\endcsname}
        {\csname ParentPath\endcsname}
        {\csname RemotePath\endcsname}
        {\csname OSDLangPath\endcsname}
        {\csname OSDPath\endcsname}}

    이것이 필요한 프로젝트가 내게 다시는 주어지지 않을 것 같지만, 그런 기회가 생긴다면 이를 대체하는 코드를 expl3로 만들어야 할 것이다. 해 보니, 너무 쉽고 단순하다.

    \newcommand\CommonPath{../Common}
    \newcommand\Language{English}
    \newcommand\groupa{AAA}
    \newcommand\groupb{BBB}
    \newcommand\groupc{CCC}
    \ExplSyntaxOn
    \NewDocumentCommand \DetermineGraphicpath { }
    {
        \tl_set:Nx \groupapath { \CommonPath/\Language/\groupa/ }
        \tl_set:Nx \groupbpath { \CommonPath/\Language/\groupb/ }
        \tl_set:Nx \groupcpath { \CommonPath/\Language/\groupc/ }

        \exp_args:Nx \graphicspath { 
            {\groupapath}{\groupbpath}{\groupcpath}
        }
    }
    \ExplSyntaxOff

    그때 만들었던 스타일 파일을 열어보니, 용하다 해야 할지 무식하다 해야 할지, \newif가 무려 88번이나 사용되었다. 벌써 14년이나 되었다.

    'TeX과 친구들' 카테고리의 다른 글

    판정 함수  (0) 2021.03.31
    한글 단어에서 줄나눔이 일어나지 않게  (0) 2021.01.11
    편집 디자인  (0) 2020.12.23
    polyglossia와 일본어  (0) 2020.12.23
    tcolorbox가 페이지 하단에 걸릴 때  (0) 2020.11.11

    댓글

Designed by Tistory.