סימן קנ סעיף ב
בִּשְעַת הַזִּוּוּג, יֶשׁ לוֹ לְהַרְהֵר בְּדִבְרֵי תוֹרָה וּבִשְׁאָר דָּבָר שֶׁבִּקְדֻשָּׁה. וְאַף עַל פִּי שֶׁאָסוּר לִקְרוֹת בְּפִיו, הִרְהוּר מֻתָּר וּמִצְוָה, כִּי הִרְהוּר אֵינוֹ כְּדִבּוּר לְעִנְיָן זֶה. אַף עַל פִּי דְּבַמְּבוֹאוֹת הַמְּטֻנָפִים אָסוּר אֲפִילּוּ לְהַרְהֵר בְּדָבָר שֶׁבִּקְּדֻשָּׁה, זֶהוּ מִשׁוּם דְּבָעֵינָן וְהָיָה מַחֲנֶיךָ קָדוֹשׁ. אֲבָל הֵיכָא דְהָאִסּוּר הוּא מִשּׁוּם עֶרְוָה, מִדִּכְתִיב עֶרְוַת דָּבָר דָּרְשׁוּ רַבּוֹתֵינוּ, זִכְרוֹנָם לִבְרָכָה, דִּבוּר אָסוּר, הִרְהוּר מֻתָּר.
While engaged in the marital act, you should think about Torah subjects or other sacred subjects. Even though [during the act itself] it is forbidden to speak words of Torah, thinking about them is permitted and meritorious, for thought is not likened to speech in this case. Even though in filthy alleys it is forbidden to even think about sacred subjects, this is because of the Divine command, "And your camp shall be holy;"4Deuteronomy 22:15. but where it is forbidden because of body nakedness, concerning which it is written, ervas davar (unseemingly thing), our Sages of blessed memory inferred from this that speaking davar (words of Torah) is forbidden, but thinking about them is permitted.5Maseches Shabbos 150a. the word דָבָר indicates actual speech.
תנא דבי אליהו כל השונה הלכות בכל יום מובטח לו שהוא בן העולם הבא שנאמר הליכות עולם לו אל תקרי הליכות אלא הלכות (נדה ע"ג.)