TiKz 外部化忽略规模

TiKz 外部化忽略规模

我想在同一个文档中多次使用 TikZ 图片(埃菲尔铁塔,但没关系),但大小和颜色不同。

第一个选项可能是定义一个\newcommand。但这意味着 TikZ 将被调用多次来绘制同一张图片,以及更重的 pdf 文件。

我选择执行以下操作:

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[usenames,dvipsnames]{xcolor}
\usepackage{tikz}
\usepackage{xparse}

\usetikzlibrary{external}
\tikzexternalize[prefix=figs/]
\newcommand{\eiffeldessin}{(15.1496,157.9474) .. controls (15.1496,156.2479) and
  (19.1646,154.7631) .. (26.7002,153.6759) .. controls (29.7886,153.2304) and
  (31.2269,152.4980) .. (31.5669,151.1977) .. controls (31.8323,150.1826) and
  (32.4135,149.3520) .. (32.8584,149.3520) .. controls (33.3032,149.3520) and
  (36.6624,145.8645) .. (40.3233,141.6020) .. controls (47.4569,133.2960) and
  (56.7746,117.3833) .. (56.8005,113.4623) .. controls (56.8092,112.1479) and
  (57.4397,110.5729) .. (58.2017,109.9623) .. controls (60.5777,108.0583) and
  (67.0690,86.7792) .. (66.3176,83.3579) .. controls (65.9019,81.4654) and
  (66.0572,80.3520) .. (66.7368,80.3520) .. controls (67.3305,80.3520) and
  (67.8256,79.1145) .. (67.8370,77.6020) .. controls (67.8484,76.0895) and
  (68.7505,69.4520) .. (69.8415,62.8520) .. controls (73.2163,42.4378) and
  (74.4038,24.4695) .. (72.8156,17.8491) .. controls (71.6200,12.8653) and
  (71.6471,11.7949) .. (73.0391,9.0151) .. controls (73.9102,7.2754) and
  (74.8773,5.0645) .. (75.1882,4.1020) .. controls (75.9775,1.6585) and
  (78.8163,1.8858) .. (78.8163,4.3925) .. controls (78.8163,5.5148) and
  (79.7754,7.7302) .. (80.9475,9.3157) .. controls (82.5313,11.4578) and
  (82.8975,12.9246) .. (82.3731,15.0252) .. controls (80.8898,20.9668) and
  (80.6433,31.9936) .. (81.7563,42.6228) .. controls (82.9932,54.4362) and
  (86.5156,76.8731) .. (87.5225,79.3520) .. controls (87.8576,80.1770) and
  (88.0346,81.4424) .. (87.9160,82.1639) .. controls (87.6316,83.8929) and
  (89.4674,92.9651) .. (92.0517,102.6020) .. controls (93.6907,108.7137) and
  (94.5197,110.3520) .. (95.9732,110.3520) .. controls (96.9869,110.3520) and
  (97.8163,111.0270) .. (97.8163,111.8520) .. controls (97.8163,112.6770) and
  (97.3606,113.3520) .. (96.8037,113.3520) .. controls (94.4636,113.3520) and
  (107.4966,135.9884) .. (116.1534,146.9596) .. controls (120.0438,151.8901) and
  (120.5454,152.1999) .. (123.8163,151.6929) .. controls (128.8912,150.9064) and
  (141.6332,148.3413) .. (143.6175,147.7067) .. controls (144.9326,147.2861) and
  (145.0084,147.3832) .. (143.9531,148.1367) .. controls (142.8023,148.9584) and
  (142.8023,149.1881) .. (143.9531,149.6118) .. controls (147.7101,150.9950) and
  (127.9225,155.9799) .. (112.5933,157.5120) .. controls (103.4131,158.4295) and
  (96.4720,158.4032) .. (80.5933,157.3905) .. controls (69.4409,156.6793) and
  (54.4663,156.3470) .. (47.3163,156.6522) .. controls (34.3838,157.2041) and
  (31.3883,157.4485) .. (20.7329,158.8214) .. controls (15.9902,159.4325) and
  (15.1496,159.3009) .. (15.1496,157.9474) -- cycle(85.0663,154.6898) ..
  controls (84.3788,154.4123) and (83.2538,154.4123) .. (82.5663,154.6898) ..
  controls (81.8788,154.9672) and (82.4413,155.1941) .. (83.8163,155.1941) ..
  controls (85.1913,155.1941) and (85.7538,154.9672) .. (85.0663,154.6898) --
  cycle(116.5455,154.7478) .. controls (38.8485,158.2493) and (77.6970,156.4986)
  .. (116.5455,154.7478) -- cycle(74.0853,153.6961) .. controls
  (73.4083,153.4222) and (72.0583,153.4055) .. (71.0853,153.6590) .. controls
  (70.1123,153.9125) and (70.6663,154.1366) .. (72.3163,154.1570) .. controls
  (73.9663,154.1774) and (74.7623,153.9700) .. (74.0853,153.6960) --
  cycle(95.0229,150.6525) .. controls (94.7810,149.3873) and (94.1997,148.3520)
  .. (93.7311,148.3520) .. controls (93.2625,148.3520) and (93.1381,147.6770) ..
  (93.4547,146.8520) .. controls (93.7712,146.0270) and (93.5321,145.3520) ..
  (92.9233,145.3520) .. controls (90.7200,147.8788) and (92.0102,153.0524) ..
  (90.3824,147.0195) .. controls (87.3946,135.9031) and (77.2251,129.3512) ..
  (71.2663,134.7036) .. controls (67.2960,138.0570) and (63.5425,142.6797) ..
  (61.4978,146.5118) -- (59.9937,150.1717) -- (70.1550,150.8659) .. controls
  (75.7437,151.2478) and (83.0163,151.8860) .. (86.3163,152.2840) .. controls
  (95.1760,153.3528) and (95.5265,153.2871) .. (95.0229,150.6525) --
  cycle(117.5223,152.1493) .. controls (118.1856,152.0775) and
  (118.4920,151.6363) .. (118.2032,151.1690) .. controls (117.0519,150.1033) and
  (113.1833,151.2641) .. (112.7161,151.1519) .. controls (111.9579,150.8992) and
  (110.1802,148.4783) .. (108.7658,145.7722) .. controls (107.3514,143.0661) and
  (104.8595,139.0106) .. (103.2283,136.7599) .. controls (101.5971,134.5093) and
  (99.4187,130.7968) .. (98.3875,128.5099) .. controls (94.4707,117.6272) and
  (97.3465,131.2963) .. (93.6104,117.4392) -- (92.6143,113.5148) --
  (84.4653,113.0228) .. controls (77.0493,112.5751) and (73.9959,112.5965) ..
  (64.0663,113.1657) .. controls (62.2788,113.2682) and (60.8877,113.6896) ..
  (60.9750,114.1021) .. controls (61.0624,114.5146) and (60.7777,115.7521) ..
  (60.3425,116.8521) .. controls (59.9072,117.9521) and (58.5329,121.4525) ..
  (57.2883,124.6308) .. controls (54.4079,131.9870) and (49.3824,140.3584) ..
  (44.4813,145.9651) .. controls (42.3721,148.3779) and (41.0221,150.3896) ..
  (41.4813,150.4354) .. controls (41.9405,150.4812) and (43.4413,150.6858) ..
  (44.8163,150.8901) .. controls (46.1913,151.0943) and (49.3541,151.0283) ..
  (51.8447,150.7434) .. controls (56.3490,150.2281) and (56.3795,150.1985) ..
  (57.5715,145.1801) .. controls (61.2379,129.7456) and (73.9302,122.3547) ..
  (85.9090,128.6788) .. controls (91.8185,131.7987) and (95.4724,137.3004) ..
  (97.5643,146.2282) -- (99.2927,153.6042) -- (107.8045,152.9421) .. controls
  (112.4860,152.5779) and (116.8590,152.2212) .. (117.5223,152.1493) --
  cycle(37.1130,148.8206) .. controls (39.4235,145.6460) and (38.8143,145.6608)
  .. (35.8163,148.8520) .. controls (34.5245,150.2270) and (33.8836,151.3379) ..
  (34.3920,151.3206) .. controls (34.9003,151.3033) and (36.1248,150.1783) ..
  (37.1130,148.8206) -- cycle(39.9438,148.6020) .. controls (41.1877,147.0160)
  and (41.1523,146.9806) .. (39.5663,148.2245) .. controls (38.6038,148.9793)
  and (37.8163,149.7668) .. (37.8163,149.9745) .. controls (37.8163,150.7975)
  and (38.6375,150.2678) .. (39.9438,148.6020) -- cycle(91.4443,141.5997) ..
  controls (90.6615,140.0859) and (89.0184,137.9484) .. (87.7928,136.8497) ..
  controls (85.8160,135.0774) and (85.8609,135.2908) .. (88.1905,138.7416) ..
  controls (89.6347,140.8808) and (90.8163,143.0183) .. (90.8163,143.4916) ..
  controls (90.8163,143.9648) and (91.2778,144.3520) .. (91.8420,144.3520) ..
  controls (92.4466,144.3520) and (92.2833,143.2221) .. (91.4443,141.5997) --
  cycle(71.8460,130.9355) .. controls (73.7547,130.1076) and (74.7314,129.4127)
  .. (74.0166,129.3912) .. controls (72.0628,129.3324) and (67.3573,131.9797) ..
  (65.7607,134.0361) .. controls (64.4169,135.7668) and (64.4452,135.7720) ..
  (66.3633,134.1464) .. controls (67.4702,133.2083) and (69.9374,131.7634) ..
  (71.8460,130.9355) -- cycle(72.5779,110.6649) .. controls (71.6219,110.4147)
  and (69.8219,110.4056) .. (68.5779,110.6447) .. controls (67.3340,110.8839)
  and (68.1163,111.0887) .. (70.3163,111.0998) .. controls (72.5163,111.1109)
  and (73.5340,110.9152) .. (72.5779,110.6649) -- cycle(84.0663,110.6463) ..
  controls (82.8288,110.4080) and (80.8038,110.4080) .. (79.5663,110.6463) ..
  controls (78.3288,110.8847) and (79.3413,111.0797) .. (81.8163,111.0797) ..
  controls (84.2913,111.0797) and (85.3038,110.8847) .. (84.0663,110.6463) --
  cycle(67.3983,108.7657) .. controls (69.1272,108.3014) and (69.6795,106.9255)
  .. (70.6548,100.6519) .. controls (71.9429,92.3663) and (73.4213,88.5922) ..
  (76.0077,86.9863) .. controls (78.4099,85.4948) and (81.3145,88.4004) ..
  (82.9464,93.9272) .. controls (83.6650,96.3609) and (84.6312,98.3520) ..
  (85.0936,98.3520) .. controls (85.5560,98.3520) and (85.6554,98.8034) ..
  (85.3145,99.3550) .. controls (84.9735,99.9066) and (84.9981,102.3816) ..
  (85.3690,104.8550) .. controls (85.9345,108.6262) and (86.4005,109.3520) ..
  (88.2560,109.3520) -- (90.4686,109.3520) -- (88.1897,102.6020) .. controls
  (86.9364,98.8895) and (85.6169,93.5225) .. (85.2575,90.6753) .. controls
  (77.9101,80.5979) and (76.4922,78.4245) .. (71.9328,82.7820) .. controls
  (71.4764,83.3705) and (70.5451,86.7702) .. (69.8632,90.3369) .. controls
  (69.1812,93.9035) and (67.3449,99.6410) .. (65.7825,103.0869) .. controls
  (62.9260,109.3866) and (63.0793,109.9254) .. (67.3983,108.7657) --
  cycle(81.9932,105.6020) -- (81.4474,102.8520) -- (80.7315,105.3520) ..
  controls (80.2046,107.1922) and (79.9893,107.3548) .. (79.9160,105.9680) ..
  controls (79.7609,103.0368) and (77.5816,96.3520) .. (76.7811,96.3520) ..
  controls (76.3858,96.3520) and (75.3823,99.0520) .. (74.5510,102.3520) --
  (73.0396,108.3520) -- (77.7893,108.3520) .. controls (82.4364,108.3520) and
  (82.5272,108.2926) .. (81.9932,105.6020) -- cycle(78.8163,94.3520) .. controls
  (78.1182,92.6668) and (77.3335,91.5015) .. (77.0724,91.7625) .. controls
  (76.8114,92.0236) and (77.1961,93.5889) .. (77.9274,95.2409) .. controls
  (79.6617,99.1589) and (80.4718,98.3488) .. (78.8163,94.3520) --
  cycle(81.3879,74.6020) .. controls (80.2835,69.4308) and (77.8165,48.9864) ..
  (77.6849,43.9156) -- (77.5535,38.8520) -- (76.7375,43.8520) .. controls
  (76.2887,46.6020) and (75.1814,54.6607) .. (74.2769,61.7601) .. controls
  (73.3723,68.8595) and (72.4005,75.2720) .. (72.1173,76.0101) .. controls
  (71.7273,77.0264) and (72.8609,77.3520) .. (76.7887,77.3520) .. controls
  (81.9224,77.3520) and (81.9692,77.3240) .. (81.3879,74.6020) --
  cycle(78.1741,13.4187) .. controls (77.3098,12.4612) and (75.6451,15.2660) ..
  (76.3759,16.4485) .. controls (76.9561,17.3872) and (77.3447,17.2140) ..
  (77.8633,15.7857) .. controls (78.2493,14.7222) and (78.3892,13.6570) ..
  (78.1741,13.4187) -- cycle;}

\NewDocumentCommand{\eiffel}{O{1}O{LimeGreen}}{%
\IfFileExists{figs/eiffel_#2.pdf}{\includegraphics[scale=#1]{figs/eiffel_#2.pdf}}{%
\tikzsetnextfilename{eiffel_#2}%
\begin{tikzpicture}[y=1pt, x=1pt, yscale=-0.1*#1, xscale=0.1*#1,inner sep=0pt, outer sep=0pt    ]
\path[fill=#2] \eiffeldessin
\end{tikzpicture}}}

\begin{document}
\eiffel \eiffel[2] \eiffel[3]

\eiffel[1][red] \eiffel[5][red] \eiffel[4][Cerulean]   
\end{document}

更准确地说,该命令\eiffel采用两个可选参数:大小和颜色。根据不同的颜色名称,将创建与不同颜色相对应的不同文件,如 eiffel_black.pdf、eiffel_red.pdf、eiffel_LimeGreen.pdf 等。第一次调用时会\eiffel使用颜色名称创建该文件,下次调用时,该文件将仅包含在内\includegraphics

这似乎工作得很好,因为下面提供的示例产生了以下输出:

在此处输入图片描述

但是,第一次调用颜色时,文件的大小取决于第一次调用的缩放因子。例如,如果我添加\eiffel[1][Cerulean]到前面的示例,我将得到一个新的蓝色埃菲尔铁塔,其大小与之前的相同。我理解为什么会发生这种情况,但我希望这个新的蓝色塔比之前的塔小四倍。

\eiffel所以我的问题是:在创建外部化图片时,是否有某种方法可以“忘记”比例因子,但当第一次使用新颜色调用时,使用的比例因子不同于 1,仍然将其应用于我的文档。

另一种方法是,能够将图片外部化而不将其包含在文档中(我的意思是在第一次调用时创建一个未缩放的外部化 PDF,然后以所需的比例包含它)。如果有一个简单的方法可以做到这一点,那对我来说就足够了。

相关内容