ResearchMethods-ZHAW / Statistik

https://researchmethods-zhaw.github.io/Statistik/
5 stars 10 forks source link

highlight code #2

Open ratnanil opened 10 months ago

ratnanil commented 10 months ago

Wie machen wir das?

image

(p 28)

(p 52)

ratnanil commented 10 months ago

see https://github.com/quarto-ext/latex-environment/issues/13 and https://github.com/quarto-ext/latex-environment/issues/14

ratnanil commented 10 months ago

This is how it can be done manually:

---
title: test
format: 
    pdf: default
    html: default
---

<style>
.red{
    background-color: red;
}

.gray{
    background-color: gray;
}
</style>

<pre><code>
     Paired t-test

data: blume$a and blume$b
<span class="gray">t = 3.4821, df = 9</span>, <span class="red">p-value = 0.006916</span>
alternative hypothesis: true difference in means is not equal to 0
95 percent confidence interval:
  1.366339 6.433661
sample estimates:
mean of the differences
                    3.9
</pre></code>

\begin{lstlisting}
     Paired t-test

data: blume$a and blume$b
|\colorbox{gray}{t = 3.4821, df = 9}|, |\colorbox{red}{p-value = 0.006916}|
alternative hypothesis: true difference in means is not equal to 0
95 percent confidence interval:
  1.366339 6.433661
sample estimates:
mean of the differences
                    3.9
\end{lstlisting}
ratnanil commented 10 months ago

Aber wie in den beiden obigen Issue vermerkt, möchte ich lieber mit dem latex-environment lua filter arbeiten. Das ist aber noch nicht ganz gelöst

---
title: test
format: 
    pdf:
        keep-tex: true
        include-in-header:
            text: |
                \usepackage{listings}
                \lstset{basicstyle=\ttfamily,escapeinside={||}}
                \usepackage{xcolor}
filters:
   - latex-environment
environments: [lstlisting]
commands: colorbox
---
ratnanil commented 10 months ago

p 28 würde mit Code Annotation funktionieren, p 52. aber nicht. Grund ist, dass auf der gleichen Linie an zwei verschiedenen Stellen Annotationen gebraucht werden würden

So sieht Code Annotation aus:

image

```` ```{.bash} Paired t-test # <1> data: blume$a and blume$b t = 3.4821, df = 9, # <4> p-value = 0.006916 # <2> alternative hypothesis: true difference in means is not equal to 0 95 percent confidence interval: 1.366339 6.433661 sample estimates: mean of the differences # <3> 3.9 # <3> ``` 1. Name des Tests (Methode) 2. Signifikanz/p-Wert (Verlässlichkeit des Ergebnisses) 3. Effektgrösse und -richtung (unser eigentliches Ergebnis!) 4. ggf. Wert der Teststatistik und Freiheitsgrade („Zwischenergebnisse“) ````
ratnanil commented 10 months ago

https://tex.stackexchange.com/questions/15237/highlight-text-in-code-listing-while-also-keeping-syntax-highlighting

ratnanil commented 9 months ago
::: {.content-visible when-format="html"}
1. <span class="orange">Name des Tests (Methode)</span>
2. <span class="red">Signifikanz/p-Wert (Verlässlichkeit des Ergebnisses)</span>
3. <span class="magenta">Effektgrösse und -richtung (unser eigentliches Ergebnis!)</span>
4. <span class="teal">ggf. Wert der Teststatistik und Freiheitsgrade ("Zwischenergebnisse")</span>
:::

::: {.content-visible when-format="pdf"}
1. \colorbox{orange}{Name des Tests (Methode)}
2. \colorbox{red}{Signifikanz/p-Wert (Verlässlichkeit des Ergebnisses)}
3. \colorbox{magenta}{Effektgrösse und -richtung (unser eigentliches Ergebnis!)}
4. \colorbox{teal}{ggf. Wert der Teststatistik und Freiheitsgrade ("Zwischenergebnisse")}
:::

Werfen wir noch einmal einen Blick auf den Output von R:

<pre><code>
     <span class="orange">Paired t-test</span>

data: blume$a and blume$b
<span class="teal">t = 3.4821, df = 9</span>, <span class="red">p-value = 0.006916</span>
alternative hypothesis: true difference in means is not equal to 0
95 percent confidence interval:
  1.366339 6.433661
sample estimates:
<span class="magenta">mean of the differences
                    3.9</span>
</code></pre>

\begin{lstlisting}
     |\colorbox{orange}{Paired t-test}|

data: blume$a and blume$b
|\colorbox{teal}{t = 3.4821, df = 9}|, |\colorbox{red}{p-value = 0.006916}|
alternative hypothesis: true difference in means is not equal to 0
95 percent confidence interval:
  1.366339 6.433661
sample estimates:
|\colorbox{magenta}{mean of the differences}|
                    |\colorbox{magenta}{3.9}|
\end{lstlisting}