WeBWorK Problems
https://webwork.maa.org/moodle/mod/forum/view.php?f=3
Questions and comments related to WeBWorK problems, problem authoring, etc.Moodleen(c) 2024 WeBWorK: Online homework for math and sciencehttps://webwork.maa.org/moodle/theme/image.php/classic/core/1584125254/i/rsssitelogomoodle
https://webwork.maa.org/moodle
14035Re: Boolean Circuits using Tikz
https://webwork.maa.org/moodle/mod/forum/discuss.php?d=8509&parent=21199
Wed, 15 May 2024 15:48:14 GMTby Cindy Loten. <p><div class="text_to_html">~~ is the fix! Thanks. This is ringing a bell. I just went looking through some notes from last year, and found something about using ~~ (but not \ ) to escape special characters. I was using Perl to process string answers. I'm all set. <br />
Good to know I don't have to load calc when I've already got the circuits.logic.US tikz library going.</div></p>https://webwork.maa.org/moodle/mod/forum/discuss.php?d=8509&parent=21199Re: Boolean Circuits using Tikz
https://webwork.maa.org/moodle/mod/forum/discuss.php?d=8509&parent=21198
Wed, 15 May 2024 10:47:45 GMTby Glenn Rice. <p><div class="text_to_html">Here is a working example that uses the double tilde escape approach.<br /><br />
DOCUMENT();<br /><br />
loadMacros("PGstandard.pl", "PGML.pl", "PGtikz.pl", "PGcourse.pl");<br /><br />
$my_graph = createTikZImage();<br />
$my_graph->tikzLibraries("circuits.logic.US");<br /><br />
$my_graph->BEGIN_TIKZ<br />
\node (P) at (0,1) {P};<br />
\node (Q) at (0,0) {Q};<br />
\node[and gate US, draw, logic gate inputs=nn] at (~~$(P)+(3,0)-(0,0.1)~~$) (and) {};<br />
\draw (P) -- (and.input 1);<br />
\draw (Q) -- (1.5,0) |- (and.input 2);<br />
END_TIKZ<br /><br />
# Text<br />
BEGIN_PGML<br />
[@ image($my_graph, width => 300, tex_size => 1000) @]*<br />
END_PGML<br /><br />
ENDDOCUMENT();<br /><br />
Note that the circuits.logic.US tikz library automatically loads the calc tikz library. So that doesn't need to be explicitly loaded. The other tikz libraries you had listed aren't needed for this (or are also automatically loaded). You can add any back that you use though.</div></p>https://webwork.maa.org/moodle/mod/forum/discuss.php?d=8509&parent=21198Re: Boolean Circuits using Tikz
https://webwork.maa.org/moodle/mod/forum/discuss.php?d=8509&parent=21197
Wed, 15 May 2024 03:33:10 GMTby Glenn Rice. <p><p>No, the dollar signs in this case are not for math mode. They are for the "calc" tikz library.</p><p>You need to escape the dollar signs. You can't use the usual backslash for this due to PG translation. However, you should be able to use ~~ instead. So it would be</p><p>\node[and gate US, draw, logic gate inputs=nn] at (~~$(P)+(3,0)-(0,0.1)~~$) (and) {};<br /></p></p>https://webwork.maa.org/moodle/mod/forum/discuss.php?d=8509&parent=21197Re: Boolean Circuits using Tikz
https://webwork.maa.org/moodle/mod/forum/discuss.php?d=8509&parent=21196
Wed, 15 May 2024 01:22:56 GMTby Andrew Parker. <p><p>I was not actually able to get this alternative to work when developing my posted example. It seems that literal dollar signs are required as delimiters for these tikz calculations (please, someone correct me if I'm wrong) as they are not denoting math-mode in this case.</p><p>However, I was successful in using a variable to hold the literal dollar sign as follows:</p><pre>$dol = '$';</pre><pre># ... then between BEGIN_TIKZ/END_TIKZ</pre><pre>\node[and gate US, draw, logic gate inputs=nn] at ($dol (P)+(3,0)-(0,0.1)$dol ) (and) {};<br /></pre><p><br /></p></p>https://webwork.maa.org/moodle/mod/forum/discuss.php?d=8509&parent=21196Re: Boolean Circuits using Tikz
https://webwork.maa.org/moodle/mod/forum/discuss.php?d=8509&parent=21195
Wed, 15 May 2024 00:08:37 GMTby Sean Fitzpatrick. <p><div class="text_to_html">Sorry for the weird formatting. Moodle also uses the first syntax for entering LaTeX, and I couldn't remember the HTML tag for inline preformatted text.</div></p>https://webwork.maa.org/moodle/mod/forum/discuss.php?d=8509&parent=21195Re: Boolean Circuits using Tikz
https://webwork.maa.org/moodle/mod/forum/discuss.php?d=8509&parent=21194
Wed, 15 May 2024 00:06:05 GMTby Sean Fitzpatrick. <p><span class="filter_mathjaxloader_equation"><p>For math in text nodes, you can do </p><pre><span class="nolink">\(\maththings\)</span></pre> instead of <pre>$\maththings$</pre>.<p></p></span></p>https://webwork.maa.org/moodle/mod/forum/discuss.php?d=8509&parent=21194Re: Boolean Circuits using Tikz
https://webwork.maa.org/moodle/mod/forum/discuss.php?d=8509&parent=21193
Tue, 14 May 2024 22:36:12 GMTby Cindy Loten. <p><div class="text_to_html">Thank-you for the working example! I'll play around with it to get the hang of your code.<br /><br />
Cindy</div></p>https://webwork.maa.org/moodle/mod/forum/discuss.php?d=8509&parent=21193Re: Boolean Circuits using Tikz
https://webwork.maa.org/moodle/mod/forum/discuss.php?d=8509&parent=21192
Tue, 14 May 2024 22:33:51 GMTby Cindy Loten. <p><div class="text_to_html">Thank-you for your quick response, and I apologize for my slow response. You're right. It's not a library problem. I was having a dollar sign problem. The code below works. However, if try to use <br />
\node[and gate US, draw, logic gate inputs=nn] at ($(P)+(3,0)-(0,0.1)$) (and) {};<br />
to place my add gate like I do in my slides, that results in an error. To do the arithmetic (P)+(3,0)-(0,0.1) to place the AND gate 3 right and 0.1 down of node (P), I need the dollar signs in my slides. Given that $ means string name in Perl, what symbol should I put around (P)+(3,0)-(0,0.1) to get tikz to do arithmetic to place the AND gate?<br /><br />
Looking at the example provided by Andrew Parker in this thread, I see another approach to placing nodes and gates, but I'm wondering if my current approach can be modified for WeBWorK.<br /><br />
DOCUMENT(); <br /><br />
loadMacros( <br />
"PGstandard.pl", # Standard macros for PG language <br />
"MathObjects.pl", <br />
"PGML.pl", <br />
"PGtikz.pl", <br />
#"source.pl", # allows code to be displayed on certain sites. <br />
"PGcourse.pl", # Customization file for the course <br />
); <br /><br />
# Print problem number and point value (weight) for the problem <br /><br />
TEXT(beginproblem()); <br /><br />
# Show which answers are correct and which ones are incorrect <br /><br />
$showPartialCorrectAnswers = 1; <br /><br />
############################################################## <br />
# <br />
# Setup <br />
# <br />
#<br /><br />
Context("Numeric"); <br /><br />
$my_graph = createTikZImage(); <br />
$my_graph -> tikzLibraries("shapes,decorations,arrows,calc,fit,positioning,arrows.meta,circuits.logic.US");#from slides<br />
#need to look at what libraries I really need<br />
$my_graph -> tikzOptions(" ");<br />
$my_graph -> addToPreamble(" "); <br />
$my_graph->BEGIN_TIKZ <br />
\node (P) at (0,1) {P};<br />
\node (Q) at (0,0) {Q}; <br /><br />
\node[and gate US, draw, logic gate inputs=nn] at (2,.9) (and) {};<br /><br />
%\node[and gate US, draw, logic gate inputs=nn] at ($(P)+(3,0)-(0,0.1)$) (and) {};<br /><br />
\draw (P) -- (and.input 1);<br />
\draw (Q) -- (1.5,0) |- (and.input 2);<br />
END_TIKZ <br />
#using testing suggestion <br />
$image = image($my_graph, width => 300, tex_size => 1000); <br /><br />
############################################################## <br />
# <br />
# Text <br />
# <br />
# <br /><br />
BEGIN_PGML <br />
**Having problems with \$ ** <br />
Trying to draw a circuit. <br /><br />
[@ $image @]* <br />
END_PGML <br /><br />
ENDDOCUMENT();</div></p>https://webwork.maa.org/moodle/mod/forum/discuss.php?d=8509&parent=21192Re: Boolean Circuits using Tikz
https://webwork.maa.org/moodle/mod/forum/discuss.php?d=8509&parent=21191
Mon, 13 May 2024 21:49:20 GMTby Andrew Parker. <p><span class="filter_mathjaxloader_equation"><p>I got the circuits library to work. Here is some sample code:</p><pre>DOCUMENT();
loadMacros(
"PGstandard.pl",
"PGML.pl",
"PGtikz.pl"
);
$image = createTikZImage();
$image->tikzLibraries('circuits.logic.US');
$image->tikzOptions('circuit logic US,line width=0.8pt,line cap=round,line join=round');
$image->BEGIN_TIKZ
\matrix[column sep=7mm]
{
\node (A) {<span class="nolink">\(A\)</span>}; & & & \\\\
& \node [and gate] (and1) {}; & & \\\\
\node (B) {<span class="nolink">\(B\)</span>}; & & \node [or gate,yshift=-1mm] (or1) {}; & \node[yshift=-1mm] (out) {};\\\\
\node (C) {<span class="nolink">\(C\)</span>}; & & & \\\\
};
\draw
(A) -- ++(right:5mm) |- (and1.input 1)
(B) -- ++(right:5mm) |- (and1.input 2)
(or1.input 1) -- ++(left:3mm) |- (and1.output)
(or1.input 2) -- ++(left:3mm) |- (C)
(or1.output) -- (out);
END_TIKZ
BEGIN_PGML
>> [@ image($image, width => 300, height => 300, tex_size => 450) @]* <<
END_PGML
ENDDOCUMENT();
</pre><p><br /></p></span></p>https://webwork.maa.org/moodle/mod/forum/discuss.php?d=8509&parent=21191Re: Boolean Circuits using Tikz
https://webwork.maa.org/moodle/mod/forum/discuss.php?d=8509&parent=21189
Fri, 10 May 2024 23:11:06 GMTby Glenn Rice. <p><p>There are no tikz libraries that are not allowed. Can you share an example of your code? Perhaps we can help to figure out what is not working.<br /></p></p>https://webwork.maa.org/moodle/mod/forum/discuss.php?d=8509&parent=21189