【问题标题】:METAPOST: using loop variables in labelsMETAPOST:在标签中使用循环变量
【发布时间】:2013-04-10 15:59:32
【问题描述】:

亲爱的stackoverflowers,

最近,在玩 METAPOST 环境时,我遇到了一个问题。在使用循环“for”宏绘制某些东西时,我需要循环变量的 value 正确显示在标签内,但是我不知道该怎么做,Mr.Google 也无法做到帮我。下面是我使用的代码示例:

for i=1 upto N: label(btex $here should be the value of i$, some_position); endfor;

任何形式的帮助都会得到赞赏:]

【问题讨论】:

    标签: variables loops text label metapost


    【解决方案1】:

    起初,, some_position 之前缺少一个 etexbtexetex 之间的所有内容都被视为字符串。它不被解释。为此,必须首先通过TEX() 计算字符串的内容。示例:

    prologues := 2;
    
    input tex;
    
    verbatimtex
    \documentclass[12pt,a4paper]{article}
    \usepackage[T1]{fontenc}
    \usepackage[ansinew]{inputenc}
    etex;
    
    beginfig(0);
    n := 10;
        for i := 1 upto n:
        label.lrt(TEX("$i = "&decimal(i)&"$"),(0,i*1cm));
    endfor; 
    endfig;
    

    如果你想使用LaTeX-Struktures,你必须这样修改原来的TEX():

    vardef TEX primary s =
    write "verbatimtex"                    to "mptextmp.mp";
    write "\documentclass[12pt]{article}"  to "mptextmp.mp"; 
    write "\usepackage[T1]{fontenc}"       to "mptextmp.mp";
    write "\usepackage[ansinew]{inputenc}" to "mptextmp.mp";
    write "\usepackage{amsmath,amssymb}"   to "mptextmp.mp";
    write "\begin{document}"               to "mptextmp.mp";
    write "etex"                           to "mptextmp.mp";
    write "btex "&s&" etex"                to "mptextmp.mp";
    write EOF                              to "mptextmp.mp";
    scantokens "input mptextmp"
    enddef;
    

    希望有帮助

    V。 W.

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-05-08
      • 2023-04-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多