4

I want to use circuit_macros, a tool for creating circuit diagrams using M4 macros written by Dwight Aplevich. I am using Windows and face problems since most of the avalaible documentation are for UNIX and GNU/Linux users.

I am using Miktex 2.9 with Texmaker 5.0.2 on Windows 8.1. Following the installation instructions, here is what I have done so far:

  1. Downloaded the .exe files of dpic (pic interpreter) from
    https://ece.uwaterloo.ca/~aplevich/dpic/Windows/index.html
    I've put the two executables files dpic.exe and m4.exe inside a newly-created folder at: C:\dpic.
    Then I added do the Path variable the above-mentioned folder from the "View Advanced System Settings" menu, so that I can execute these programs regardless of the directory inside which I am.

  2. Downloaded and installed a m4 macro interpreter.
    Still according to Aplevich's instructions on the repository, one may download a program from the sourceforge website at:
    http://gnuwin32.sourceforge.net/packages/m4.htm

  3. Downloaded and unzipped the circuit_macros distribution from CTAN

  4. Decided where to install the .m4 library files
    I created the localtexmf folder at C:\localtexmf\tex\latex\circuit_macros and copied the downloaded unzipped files of the distribution to the target folder.

  5. Copied boxdims.sty from the top distribution directory to where LaTeX will find it
    In my case, I pasted it to newly-created folder called "boxdims" at:
    C:\Users\billyandriam\AppData\Local\Programs\MiKTeX2.9\miktex\tex\latex\boxdims\.

    After that, I opened the MikTex console and from the upper-left menus, I clicked on Tasks>Refresh file name database.

  6. Defined the environment variable M4PATH to point to the installation directory determined in Step number 4.
    In the Control Panel at "View Advanced System Settings", I created a new environment variable called M4PATH and attributed as its value the following directory: C:\localtexmf\tex\latex\circuit_macros\.

Now, my installation works with some limitations. When I have a .m4 file and run the appropriate command, the .m4 file converts to .tex with no errors. So, from Windows's command prompt, this is the command I used to create the "filename.tex" file (At the beginning, I put include(pgf.m4) at the first line of the .m4 because it has to generate a Tikz picture):

m4 filename.m4 | dpic -g > filename.tex

Yet, I cannot invoke m4 and dpic from a latex document directly.
As an illustration, let us consider the following latex code:

\documentclass{article}
\usepackage{tikz}
\newcommand\mtotex[2]{\immediate\write18{m4 #2.m4 | dpic -#1 > #2.tex}}

\begin{document}
\mtotex{g}{filename} %This line should create filename.tex from filename.m4
\input{filename.tex}
\end{document}

For some reasons, typesetting the above MWE returns an error. Did I miss something?

8
  • 1
    Crosspost
    – Johannes_B
    Commented Jan 17, 2019 at 6:01
  • @Johannes_B Please go ahead and delete my post on latex.org forum, it was a clumsy move from me. Commented Jan 17, 2019 at 12:20
  • 1
    @mandresybilly Maybe "tex.stackexchange.com/questions/156794/…" may be a start point?
    – jotagah
    Commented Jan 17, 2019 at 13:23
  • @jotagah Thank you for the advice.One link on the accepted answer seems to have an installation guide but unfortunately, that link is no more working now. Commented Jan 17, 2019 at 16:28
  • 1
    latex will not run external programs (for security reasons) unless you allow them by adding the option --shell-escape. See e.g. tex.stackexchange.com/a/236648/2388 for how to add it in texmaker. Commented Jan 19, 2019 at 16:18

2 Answers 2

6
+100

LaTeX will not run external applications (for security reasons) unless you allow this by using the option --shell-escape.

\immediate\write18{...} is such a call to an external application.

See e.g. https://tex.stackexchange.com/a/236648/2388 how to add the option to the texmaker call.

I would also suggest to move boxdims.sty and the m4 files to your localtexmf in C:\localtexmf\tex\latex\circuit_macros

If not done yet add C:\localtexmf to the TEXMF root directories in MikTeX Console under the buttons Settings>Directories>(add the localtexmf path) or refresh the FNDB with the entry in the tasks menu.

3
  • My last question is why is it better practice to move boxdims.sty to C:\localtexmf\tex\latex\circuit_macros and not inside the MikTex folders? And after updating the environment variable M4PATH to the new directory, should I also add C:\localtexmf to the TEXMF root directories in Miktex under the buttons Settings>Directories>add the localtexmf path for it to work? Commented Jan 19, 2019 at 17:06
  • 1
    Leave the main miktex directory alone. At first you can break things, and at second you can loose things if you have to reinstall miktex. And yes, you should add localtexmf as a new root. Commented Jan 19, 2019 at 17:15
  • @UlrikeFischer That makes sense. Ok got it. I will edit your answer for completeness :). Commented Jan 19, 2019 at 17:18
1

Although the question has already been answered, other users finding a simple way to use circuit-macros into LaTeX may find useful the PyCirkuit tool, which works on GNU/Linux, Mac and windows systems.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .