@@ -430,3 +430,29 @@ def test_document_font_size():
430
430
label = r'\normalsize the document font size is \the\fontdimen6\font'
431
431
)
432
432
plt .legend ()
433
+
434
+
435
+ # test using a preamble where packages have different options
436
+ @needs_pgf_xelatex
437
+ @pytest .mark .parametrize ('format' , ('pgf' , 'pdf' , 'pgf' ))
438
+ @pytest .mark .backend ('pgf' )
439
+ def test_preamble_packages (format , tmp_path ):
440
+ # A preamble containing all packages matplotlib uses, but with different
441
+ # options to trigger an option clash.
442
+ preamble = '\n ' .join ([
443
+ r'\usepackage[no-math]{fontspec}' ,
444
+ r'\usepackage[nohyphen]{underscore}' ,
445
+ r'\usepackage[demo]{graphicx}' ,
446
+ r'\usepackage[draft]{hyperref}' ,
447
+ r'\usepackage[margin=1in]{geometry}' ,
448
+ r'\usepackage[draft]{pgf}' ,
449
+ r'\usepackage[ascii]{inputenc}' ,
450
+ r'\usepackage[safe]{textcomp}' ,
451
+ ])
452
+ mpl .rcParams ['pgf.preamble' ] = preamble
453
+
454
+ plt .figure ().savefig (BytesIO (), format = format )
455
+
456
+ path = os .path .join (tmp_path , f'preamble_packages_{ format } .pdf' )
457
+ with PdfPages (path ) as pdf :
458
+ pdf .savefig (plt .figure ())
0 commit comments