METAPOST:在标签中使用循环变量 [英] METAPOST: using loop variables in labels

查看:74
本文介绍了METAPOST:在标签中使用循环变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尊敬的stackoverflowers

Dear stackoverflowers,

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

recently, while playing around with the METAPOST enviroment, I encountered a problem. While drawing something using the loop 'for' macro I needed the value of the loop variable to be correctly displayed inside a label, however I could not figure out how to do that and Mr.Google was unable to help me. Below is an example of the code I used:

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

将为您提供任何帮助:]

Any kind of help will be appreaciated :]

推荐答案

首先,在, some_position之前缺少etex. btexetex之间的所有内容均视为字符串.它不被解释.为此,必须首先通过TEX()计算字符串的内容.示例:

at first there's a etex missing before , some_position. All between btex and etex is taken as a string. It is not interpreted. For this purpose the contents of the string has to be calculated first by TEX(). Example:

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结构,则必须以这种方式修改原始TEX():

If You want to use LaTeX-Struktures, you have to modify the original TEX() in this way:

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.

这篇关于METAPOST:在标签中使用循环变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆